negative values of rectange in bounding box in opencv c++
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?