Image processing 使用scikit图像将图像缩减为文本内容
这是我想从中取出文本的图像 如何去除黑色边框并将图像缩小到50 我采取的办法:Image processing 使用scikit图像将图像缩减为文本内容,image-processing,scikit-image,Image Processing,Scikit Image,这是我想从中取出文本的图像 如何去除黑色边框并将图像缩小到50 我采取的办法: 我尝试使用角点检测器(corner peak和corner harris),从左侧拾取前2个坐标,从右侧拾取最后2个坐标 使用这4个坐标,我裁剪了图像,并在所有边上进一步减少了5 这肯定不是一个有效的方法。我也看了几段也。没能把它弄对。我正在使用scikit图像来解决此问题。使用角点可能不起作用,因为角点也可能以字符形式出现 下面是我使用hough线尝试的内容,如下所述: 1) 首先腐蚀图像,以最小化线条和字符之间
这肯定不是一个有效的方法。我也看了几段也。没能把它弄对。我正在使用scikit图像来解决此问题。使用角点可能不起作用,因为角点也可能以字符形式出现 下面是我使用hough线尝试的内容,如下所述: 1) 首先腐蚀图像,以最小化线条和字符之间的间隙 2) 使用Hough直线检测算法检测和删除直线 3) 放大图像以获得清晰的字符 4) 现在我们将字符和行分隔开,因此我们可以通过查找连接的组件来删除行 以下是Python中的代码实现:
img = cv2.imread('D:\Image\st1.png',0)
ret, thresh = cv2.threshold(img, 150, 255, cv2.THRESH_BINARY_INV)
#dilate the image to reduce gap between characters and lines and get hough lines correctly
kernel = np.ones((3,3),np.uint8)
erosion = cv2.erode(thresh,kernel,iterations = 1)
#find canny edge image
canny = cv2.Canny(erosion,100,200)
minLineLength=img.shape[1]/4
lines = cv2.HoughLinesP(image=canny,rho=0.02,theta=np.pi/500, threshold=10,lines=np.array([]), minLineLength=minLineLength,maxLineGap=10)
a,b,c = lines.shape
# delete the lines
for i in range(a):
cv2.line(erosion, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), 0, 3, cv2.LINE_AA)
#erode the image
kernel = np.ones((3,3),np.uint8)
erosion = cv2.dilate(erosion, kernel, iterations=1)
# find connected components
connectivity = 4
nb_components, output, stats, centroids = cv2.connectedComponentsWithStats(erosion, connectivity, cv2.CV_32S)
sizes = stats[1:, -1]; nb_components = nb_components - 1
min_size = 250 #threshhold value for lines length
img2 = np.zeros((output.shape), np.uint8)
for i in range(0, nb_components):
if sizes[i] >= min_size:
img2[output == i + 1] = 255 #delete the line components
img = cv2.bitwise_not(img2)
输出图像: