I just wrote a little program which searches for contours in a color thresholded binary image which is processed with canny after thresholding, but somehow it always finds two contours for every object in the image.
In the bottom right image where the found contours are drawn, you can see that the biggest contour is drawn two times with a little offset between the two contours. The next image shows a detailed view of this image.
http://img831.imageshack.us/img831/3641/doubleframe2.png
Here just the biggest contour is drawn two times, but it happens randomly for every other one of the contours.
I just want one contours for every object, how can i achieve that? :/
Update:
The size of the contours vector which is filled by the findContours method has a size of 8 where it should have a size of just 4.
update 2:
Here is the rgb input image from the kinect
http://img405.imageshack.us/img405/9761/inputimage.jpg
for the color Threshold i used the following approach
cv::cvtColor(in, out, CV_BGR2HSV);
cv::inRange(out,
cv::Scalar(25, 131, 97),
cv::Scalar(35, 220, 217),
out);
followed by an erosion + dilation with an rect element with a size of 1.
I think the problem is most likely because when you find the edges and then find the contours of those edges, there is an outer boundary and inner boundary for it. So openCV take both as contours and draw it.
When I calculated its areas, they have a very minor changes of a value of around ‘3’ ( for example, biggest square has detected two contours with areas 9105.5 and 9108.5 ), which is most likely to happen due to the reason I mentioned. (So they are very difficult to distinguish)
The problem can be solved if you find contours with out finding canny edges. ie directly find the contours from thresholded image. It will give you more accurate answer.
In first case(after canny), I got 36 contours while in second case, i got only 22 contours.
Try it and hope it solves the problem !!!