我感兴趣的是检测线条(我使用hough变换设法找到了线条)和上面的文字
我写的代码如下。(我已进行编辑,以便可以在每条线的坐标之间循环)
import cv2
import numpy as np
img=cv2.imread('test3.jpg')
#img=cv2.resize(img,(500,500))
imgGray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
imgEdges=cv2.Canny(imgGray,100,250)
imgLines= cv2.HoughLinesP(imgEdges,1,np.pi/180,230, minLineLength = 700, maxLineGap = 100)
imgLinesList= list(imgLines)
a,b,c=imgLines.shape
line_coords_list = []
for i in range(a):
line_coords_list.append([(int(imgLines[i][0][0]), int(imgLines[i][0][1])), (int(imgLines[i][0][2]), int(imgLines[i][0][3]))])
print(line_coords_list)#[[(85, 523), (964, 523)], [(85, 115), (964, 115)], [(85, 360), (964, 360)], [(85, 441), (964, 441)], [(85, 278), (964, 278)], [(85, 197), (964, 197)]]
roi= img[int(line_coords_list[0][0][1]): int(line_coords_list[0][1][1]), int(line_coords_list[0][0][0]) : int(line_coords_list[0][1][0])]
print(roi) # why does this print an empty list?
cv2.imshow('Roi NEW',roi)
现在我只是不知道如何检测这些线上方的感兴趣区域。是否可以说裁剪出每一行,让图像显示roi_1、roi_2、roi_n,其中每个roi是第一行上方的文本,第二行上方的文本等
我希望输出是这样的
您已检测到这些线。现在,您必须使用
y
坐标将图像分割为线之间的区域,然后在白色背景(纸张)上搜索黑色像素(单词)沿着
x
和y
轴构建直方图可能会为您提供所需的感兴趣区域例如,为了回答您在评论中提出的问题,如果您有一个图像
img
和一个感兴趣的区域,并且y
坐标(100200)横跨图像的整个宽度,您可以裁剪该区域并在那里搜索类似的内容:现在搜索:
或者类似的东西
在Python/OpenCV中有一种方法可以做到这一点
输入:
阈值图像:
形态图像:
结果:
相关问题 更多 >
编程相关推荐