Opencv python HoughLinesP strange results

前端 未结 3 1584
梦毁少年i
梦毁少年i 2020-12-06 08:16

I\'m trying to get the same result they got in this tutorial for HoughLinesP filter. I took same images and same threshold values like this :

import cv2
fro         


        
3条回答
  •  一整个雨季
    2020-12-06 08:40

    The problem in your code was how the returned lines are arranged. This piece of code works for me:

    import cv2
    import numpy as np
    
    img = cv2.imread('building.jpg',1)
    cannied = cv2.Canny(img, 50, 200, 3)
    lines = cv2.HoughLinesP(cannied, 1, np.pi / 180, 80, 30, 10)
    
    for line in lines:
        leftx, boty, rightx, topy = line[0]
        cv2.line(img, (leftx, boty), (rightx,topy), (255, 255, 0), 2)
    
    cv2.imwrite('lines.png',img)
    cv2.imwrite('canniedHouse.png',cannied)
    cv2.imshow('', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

    I also did some other small changes in order to get the code running on my machine.

    I think you need to change some parameters in order to get exactly same results as in the documentation.

提交回复
热议问题