简体   繁体   中英

How to detect only vertical edges from the image?

I have the following image:

Original Image:

原始图像

I want to detect the 3 vertical edges shown in red in the below image:

Desired output:

期望的输出

I've tried the following:

#green is the original image
gray = cv2.cvtColor(green, cv2.COLOR_BGR2GRAY)
cv2.imshow("Gray green" ,gray)

ret, thresh1 = cv2.threshold(gray, 140, 255, cv2.THRESH_BINARY_INV)
cv2.imshow("140 Thresh", thresh1)

edges = cv2.Canny(thresh1,100,250,apertureSize = 7)
cv2.imshow("Edges", edges)

The canny edge detector shows this output:

Canny result:

精明的结果

I've tried using sobel vertical detection as follows:

 sobel_vertical = cv2.Sobel(thresh1, cv2.CV_64F, 1, 0, ksize=7)
 cv2.imshow("Vertical", sobel_vertical)

Here's the sobel vertical output:

Sobel Vertical output

索贝尔垂直输出

Following this

这个

as an answer, I tried the same code, as follows:

minLineLength=100

lines = cv2.HoughLinesP(image=edges,rho=1.4,theta=np.pi/180, threshold=100,lines=np.array([]), minLineLength=minLineLength,maxLineGap=10)

a,b,c = lines.shape

for i in range(a):
    cv2.line(green, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 1, cv2.LINE_AA)

cv2.imshow("Lines", green)

Which gives me this output:

Houghlines output:

Houghlines 输出

Can anyone suggest to me what I am doing wrong, or what I can do to get the desired output, or close to that? I don't want horizontal edges to be detected at all. Thank you!

For the lines you are getting from the Houghlines output, you can calculate the slope or inclination of each line and you can apply a condition where you display only those lines which have their slopes in a given bound say 0 to 90 degrees

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM