negative values of rectange in bounding box in opencv c++

asked 2014-08-14 03:01:23 -0500

testingkills gravatar image

updated 2015-08-22 10:37:14 -0500

 findContours(diffimage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
cout << "Contour Size : " << contours.size()<<endl;
vector<Rect> boundRect(contours.size());
for (int j = 0; j < contours.size(); j++)
{
    cout << "Contour[i] Size : " << contours[j].size() << endl;
    boundRect[j] = boundingRect(contours[j]);
    cout << "Rectangle :" << boundRect[j].x << '\t' << boundRect[j].y << '\t' <<          boundRect[j].width << '\t' << boundRect[j].height << endl;
}

I have detected two contours in the image. When i run the {bounding Rectangle} on it.

One of the contour is correctly detected with positive set of values of the rectangle dimensions.

The other one is giving negative set of large values of the rectangle dimensions.

Can anyone tell me the reason and the possible solution?

edit retag flag offensive close merge delete