findContours not working properply [closed]
I am using findContours on a simple white circle i created on a paint application with a black back ground. The problem is that while the tutorials tell me that there should be only one contour surrounding that circle, when i output the contours, there are 2 different points.
Due to this reason, i am not able to use contour approx method.
Can anyone help me with this?
Thanks in Advance!
import cv2
import numpy as np
img = cv2.imread("url.png")
canny = cv2.Canny(img,0,0)
imgs,cnts,hie = cv2.findContours(canny,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.namedWindow("img",cv2.WINDOW_NORMAL)
cnt = cnts[1]
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 original image(/upfiles/14483724218429244.png) This is the editied image for approximation(/upfiles/14483724673701482.png)
The black and white image/(/upfiles/14483740423517343.jpeg)
Please, post code and images
Please, don't post links. Instead, write down here your code (it should contain just a few lines) and also directly post your images.
@LorenaGdL There you go!
Your original image is not a white circle over a black background. You have a blue circle, surrounded by a red circle, over a white background. So yes, probably 2 contours. Anyway, I still don't know what's your real problem
Well, even if i create an image via paint. This problem still persists.
I've linked the black and white image also
The black&white image is a .jpeg image, and thus it has compression artifacts that make it non-binary. On the other hand, RETR_TREE might not be your best mode (maybe for your application RETR_EXTERNAL suits better). Also, you can always filter the found contours to get the biggest one, and approximate that one (use contourArea())
closed because duplicated here http://answers.opencv.org/question/77... may because user wasn't able to upload images in this post ?!?