如何删除(嘈杂和短)线路?
How to delete (noisy and short) lines?
将 OpenCV 与 Python 结合使用,我试图在我的图像中找到水平线和垂直线。
这是我的输出:
vertical_lines
horizontal_lines
好吧,我正在尝试仅检测长线并删除短(嘈杂)线。
我希望我的输出看起来像这个修改后的图像:
Final_Horizontal_lines
如果需要,我可以为您提供我的代码。
您可以使用等高线解决该问题。
im2, contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
for contour in contours:
(x, y, w, h) = cv2.boundingRect(contour)
# if h<500: # check the length of verical lines
if w<500: # check the length of horizontal lines
cv2.fillConvexPoly(gray,contour,0) #fill the contour with black color
将 OpenCV 与 Python 结合使用,我试图在我的图像中找到水平线和垂直线。
这是我的输出:
vertical_lines
horizontal_lines
好吧,我正在尝试仅检测长线并删除短(嘈杂)线。
我希望我的输出看起来像这个修改后的图像:
Final_Horizontal_lines
如果需要,我可以为您提供我的代码。
您可以使用等高线解决该问题。
im2, contours, hierarchy = cv2.findContours(gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
for contour in contours:
(x, y, w, h) = cv2.boundingRect(contour)
# if h<500: # check the length of verical lines
if w<500: # check the length of horizontal lines
cv2.fillConvexPoly(gray,contour,0) #fill the contour with black color