Getting desired angles from HoughLineP Transformations with OpenCV

100 views Asked by At

I am trying to use probabilistic HoughLine Tranforms . After using HoughLinesP I get the following lines:

enter image description here

Note that the blue thing denoted in the image is not part of it. I have made it using paint for demonstration purposes. I want the angles shown in blue.

So what I tried was using the points from the lines and calculated slope of it and took the arctan. But I did not get any result. Note that the following function is a part of a class.

def HoughLines(self):

        self.copy_image = self.img.copy()

        minLineLength = 10
        maxLineGap = 30
        self.lines = cv2.HoughLinesP(self.edges,1,np.pi/180,15,minLineLength=minLineLength,maxLineGap=maxLineGap)

        for line in range(0, len(self.lines)):
            for x1,y1,x2,y2 in self.lines[line]:
                cv2.line(self.copy_image,(x1,y1),(x2,y2),(0,255,0),2)

#        cv2.imshow('hough',self.copy_image)
#        cv2.imwrite('test.jpg', self.copy_image)
#        cv2.waitKey(0)

        angle = 0.0
        self.nlines = self.lines.size
        for x1, y1, x2, y2 in self.lines[0]:
            angle += np.arctan2(y2 - y1, x2 - x1)
            print(angle)

Therefore, I am stuck and I do not how to proceed. What can be a possible solution?

Any help is appreciated. Thank You.

0

There are 0 answers