我正在在线阅读,我发现可以根据使用边缘检测器然后应用霍夫变换检测到的行数来判断图像是否像素化。
我尝试了该方法,但霍夫变换似乎无法正确检测到线条,我不知道为什么它不能正常工作。
以下是一些结果图像供参考:坎尼边缘检测结果
和霍夫变换结果
我该怎么做才能改善线路检测?
我根据一些在线教程使用的代码:
img = cv2.imread(image_path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
high_thresh, thresh_im = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
lowThresh = 0.5*high_thresh
edges = cv2.Canny(img, lowThresh, high_thresh)
minLineLength = 200
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
for x1,y1,x2,y2 in lines[0]:
cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
答案 0 :(得分:1)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
minLineLength = 200
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
# edited this line
for line in lines:
x1,y1,x2,y2 = line[0]
cv2.line(image,(x1,y1),(x2,y2),(0,255,0),2)