How to detect vertical edges in an image using opencv in python


I want to detect joints in a sugarcane stick and do not want the border lines to be detected
this is my original Original Image, and after applying Morphological Gradient I got this output image. The desired output that I need is to detect only vertical edges that is the joints, the desired output are only the red lines in this image.

So, it would be great if anyone could help me out!


You can try to enhance the following code to find vertical edges as you need

img = cv2.imread("edges.png")
mask = img[:,:,0]

height, width = mask.shape

mask = cv2.threshold(mask, 100, 255, cv2.THRESH_BINARY)[1]
#cv2.imshow("mask", mask)

vertical_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1, height//30))
vertical_lines = cv2.erode(mask, vertical_kernel, iterations=1)
vertical_lines = cv2.dilate(vertical_lines, vertical_kernel, iterations=1)

#cv2.imshow("vertical_lines", vertical_lines)

img[vertical_lines > 0, 2] = 255
cv2.imshow("img", img)

enter image description here

Answered By – Ibrahim

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.