Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Contour approximation not working correctly

I have a white circle with black lines going from either side(as shown in the picture). The problem is that when I use the contour approx method, it just outputs points around the image. rather than a whole complete circle

GNU nano 2.2.6 File: test.py Modified

                   import cv2

                   img = cv2.imread("circ.jpeg")
                   canny = cv2.Canny(img,150,300)
                   ima,cnts,hie= cv2.findContours(canny,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)


                   cnt = cnts[0]
                   epsilon = 0.1*cv2.arcLength(cnt,True)
                   approx = cv2.approxPolyDP(cnt,epsilon,True)
                   cv2.drawContours(img,approx,-1,(0,255,0),3)
                   cv2.imshow("img",img)


                   cv2.waitKey(0)
                   cv2.destroyAllWindows()

This is the image of the circle. This is how it comes.