擅长:python、mysql、java
<p>您可以使用<code>createLineSegmentDetector()</code>,这是一个来自opencv的函数</p>
<pre><code>import cv2
#Read gray image
img = cv2.imread("lines.png",0)
#Create default parametrization LSD
lsd = cv2.createLineSegmentDetector(0)
#Detect lines in the image
lines = lsd.detect(img)[0] #Position 0 of the returned tuple are the detected lines
#Draw the detected lines
drawn_img = lsd.drawSegments(img,lines)
#Save the image with the detected lines
cv2.imwrite('lsdsaved.png', drawn_img)
</code></pre>
<p><a href="https://i.stack.imgur.com/Acsbh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Acsbh.jpg" alt="enter image description here"/></a><br/>
代码的下一部分将只删除长度超过50像素的行:</p>
^{pr2}$
<p><a href="https://i.stack.imgur.com/0nMEy.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0nMEy.jpg" alt="enter image description here"/></a></p>
<p>嗯,它不能很好地处理当前的图像,但它可能会在不同的图像上产生更好的效果。您可以调整要删除的线条的长度和白色线条的粗细以绘制已删除线条的背面。<br/>
我希望有帮助。在</p>