tracking boundary using opencv
I am trying to track/ trace boundary points in sequence from the following binary image:
I am using OpenCV (python). I am using three ways:
- Apply Canny edge detection to detect edge. Problem is how to get the sequence of points? It's work fine but it's very hard to get the sequence of boundary points
- Ideal option is to detect contours on the binary image. Because contours return the boundary points in sequence. But openCV contour method is not detecting the boundary as shown in the results. Why is this happening?
- Detect contours on the Canny edge. Still some boundary is missed ??
Can anyone help me what's going on with OpenCV contours? Why it is not tracking the complete boundary. I am detecting contours as follows:
contours, hierarchy = cv2.findContours(thresh1,cv2.RETR_TREE ,cv2.CHAIN_APPROX_SIMPLE)
where thresh1 is the binary image
how did you print the points of contours in the above, second in the row image? I think you have done something wrong. If you could provide some more code, that might help :-).
See related question here.
My code is :
seg= cv2.imread(eachImg) # reading binary image blurred= cv2.medianBlur(seg,3) contours, hierarchy = cv2.findContours(blurred,cv2.RETR_TREE ,cv2.CHAIN_APPROX_SIMPLE)