我有一个带有度量的图像,我需要用python来读取,现在它读取的文本最多,但不是全部,因为有些行挡住了它的去路。我不能使用原始图像,所以我做了一个像我正在使用的图像。你知道吗
def erode(img):
kernel = np.ones((3,3), np.uint8)
eroded = cv2.erode(img, kernel, iterations=1)
gray = cv2.cvtColor(eroded,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
minLineLength = 10
maxLineGap = 1
lines = cv2.HoughLinesP(edges,1,np.pi/180,120,minLineLength,maxLineGap)
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line(eroded,(x1,y1),(x2,y2),(255,255,255),7)
我尝试过使用OpenCV
函数houghLinesP
并在这些函数上画一条线,但这并没有删除所有的线,仍然会留下一些点,就像这样:
我需要删除所有行但不更改 文本是因为我需要保存文本坐标。你知道吗
其思想是将文本展开并连接在一起,形成一个单一的轮廓。从这里我们可以找到轮廓和过滤器使用最小阈值面积。如果它通过了这个过滤器,那么我们就有一个想要的文本ROI要保留,我们把这个ROI画到一个遮罩上
相关问题 更多 >
编程相关推荐