我在OpenCV中使用了拉普拉斯变换进行边缘检测,然后使用霍夫线变换来检测其中的直线。这些被识别出来的直线最终需要从图像中去除。
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('Feb_16-0.jpg',0)
kernel = np.ones((1,1),np.uint8)
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
blur = cv2.GaussianBlur(opening,(1,1),0)
ret3,th4 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
laplacian = cv2.Laplacian(th4,cv2.CV_8UC1)
cst = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
minLineLength = 100
maxLineGap = 10
lines = cv2.HoughLinesP(laplacian,1,np.pi/180,100,minLineLength,maxLineGap)
for x1,y1,x2,y2 in lines[0]:
cv2.line(cst,(x1,y1),(x2,y2),(0,255,0),2)
cv2.imwrite('houghlines5.jpg',cst)
我希望你能识别账单上的所有线条:
![Internet Bill](https://istack.dev59.com/5zcft.webp)
![The edge detection results](https://istack.dev59.com/vcRtB.webp)
![Transformed Internet Bill](https://istack.dev59.com/aycM7.webp)