首页 文章

使用canny和hough变换检测图像是否像素化

提问于
浏览
0

我正在网上阅读,我发现根据使用边缘检测器检测到的线数然后应用Hough变换,可以判断图像是否像素化 .
我尝试了那种方法,霍夫变换没有弄清楚为什么它不能正常工作 .
以下是一些参考结果图片:canny边缘检测结果

和Hough变换结果

我该怎么做才能改善线路检测?
我正在使用的代码基于一些在线教程:

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()

1 回答

  • 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)
    

相关问题