简体   繁体   English

如何使用 python 中的 opencv 检测图像中的垂直边缘

[英]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 .我想检测甘蔗棒中的关节并且不希望检测到边界线这是我的原始原始图像,在应用形态梯度后我得到了这张output 图像 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 .我需要的所需 output 是仅检测作为关节的垂直边缘,所需的 output 只是此图像中的红线。

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)
cv2.waitKey(0)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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