我正在尝试使用Hough lines transform检测报纸文章的预处理二进制图像的背景线。
我使用的代码如下所示,它只检测一条垂直背景线,但我想检测所有垂直背景线。
如何改进我的代码以仅在预期输出图像中标记时检测所有垂直背景线?
import cv2 as cv
import numpy as np
import os
#binary image
image = cv.imread('../outputs/contour.jpg')
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY) # convert2grayscale
(thresh, binary) = cv.threshold(gray, 150, 255, cv.THRESH_BINARY | cv.THRESH_OTSU)
#cv.imshow('binary',binary)
#cv.waitKey(0)
minLineLength = 10
maxLineGap = 40
lines=np.array([])
lines = cv.HoughLinesP(binary,rho=np.pi/180,theta=np.pi/180,threshold=10,lines=lines,minLineLength=minLineLength,maxLineGap=maxLineGap)
for x1,y1,x2,y2 in lines[0]:
cv.line(image,(x1,y1),(x2,y2),(0,255,0),2)
cv.imshow('lines',image)
path='../outputs'
cv.imwrite(os.path.join(path , 'line.jpg'), image)
cv.waitKey(0)