检测交叉矩形OpenCV

时间:2018-12-18 14:55:03

标签: python opencv detection rectangles

在我的项目中,我试图估算稻草的切碎细度。在尝试任何CNN技术之前,我也非常想知道OpenCV方法能给我带来多大的好处。 这是这样的图片: This picture shows similar footage which I found on the internet, because the images I'm using are property of the company

到目前为止,我一直在使用不同的图像操作员和不同的设置。多亏了stackoverflow上的一些帖子,我一直在尝试在轮廓检测之前对图像进行预处理,包括模糊,对比度和伽玛调整,重磨,阈值设置,精巧运算符,膨胀和侵蚀...到目前为止,我一直在玩围绕操作员进行切换,更改其顺序和参数并获得了导致以下结果前后的工作流程:

before processing after processing

在预处理工作流中进行编码提取:

    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    ContourDetection_Variant.show_image(image, "Grayscaled", image_label)

    image = cv2.medianBlur(image, 5)
    ContourDetection_Variant.show_image(image, "Median Filtered Image", image_label)

    # Adjust the brightness and contrast of the picture, alpha is contrast & beta is brightness.
    alpha = 3  # Simple contrast control, 1.0 is status quo (alpha value [1.0-3.0])
    beta = -100  # Simple brightness control, 0 i status quo (beta value [0-100])
    image = cv2.convertScaleAbs(image, alpha=alpha, beta=beta)
    ContourDetection_Variant.show_image(image, "Contrast & Brightness adjustment", image_label)

    # Sharping method 2: Applying scharpening kernel filter
    # https://medium.com/@almutawakel.ali/opencv-filters-arithmetic-operations-2f4ff236d6aa
    # Create our shapening kernel, it must equal to one eventually
    # kernel_sharpening = np.array([[-1.4142, -1, -1.4142],
    #                               [-1, 10.6569, -1],
    #                               [-1.4142, -1, -1.4142]])
    kernel_sharpening = np.array([[-2.8284, -2.2361, -2, -2.2361, -2.8284],
                                  [-2.2361, -1.4142, -1, -1.4142, -2.2361],
                                  [-2, -1, 47.8591, -1, -2],
                                  [-2.2361, -1.4142, -1, -1.4142, -2.2361],
                                  [-2.8284, -2.2361, -2, -2.2361, -2.8284]])
    # applying the sharpening kernel to the input image & displaying it.
    image = cv2.filter2D(image, -1, kernel_sharpening)
    ContourDetection_Variant.show_image(image, "Sharpening method by designing own kernel", image_label)

    # Added bordertype REFLECT_101, which extends the image at the borders with pixels within the image in inverse
    # order.
    image = cv2.GaussianBlur(image, (3, 3), cv2.BORDER_REFLECT_101)
    ContourDetection_Variant.show_image(image, "Gaussian Blur", image_label)

    retval, image = cv2.threshold(image, 45, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    ContourDetection_Variant.show_image(image, "Thresholded", image_label)

    image = cv2.erode(image, None, iterations=1)
    ContourDetection_Variant.show_image(image, "Erode applied", image_label)

    image = cv2.medianBlur(image, 3)
    ContourDetection_Variant.show_image(image, "Median Filtered Image", image_label)

    retval, image = cv2.threshold(image, 45, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    ContourDetection_Variant.show_image(image, "Thresholded", image_label)

(接下来将获得的图像馈送到OpenCV的findContours中)

挑战是一些吸管很大,我想注册它,但是它们被顶部的一些吸管相交,这使得算法认为这些是单独的吸管。

我的问题很笼统,OpenCV是否可以提供更多有前途的技术(除了寻找轮廓)来实现我的目标?

0 个答案:

没有答案