1 | initial version |
this is probably an 'expectation mismatch'.
the outcome of findContours is not your img_threshold, but the contours vector.
if you care to lok at the docs again you will see: "The function modifies the image while extracting the contours." again, this is just a by-product, not the desired result.
if you need your img_threshold for further operations, supply a clone() for findContours:
vector<vector<Point>>contours;
cv::findContours(img_threshold.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
// let's draw some things, assuming, Mat ocv is the original rgb image:
drawContours(ocv, contours, -1, Scalar(200), 2);
rectangle(ocv, boundingRect(contours[0]), Scalar(0,0,200), 2);
2 | No.2 Revision |
this is probably an 'expectation mismatch'.
the outcome of findContours is not your img_threshold, but the contours vector.
if you care to lok at the docs again you will see: "The function modifies the image while extracting the contours." again, this is just a by-product, not the desired result.
if you need your img_threshold for further operations, supply a clone() for findContours:
vector<vector<Point>>contours;
cv::findContours(img_threshold.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
// let's draw some things, assuming, Mat ocv is the original rgb image:
drawContours(ocv, contours, -1, Scalar(200), 0, Scalar(200,0,0), 2);
rectangle(ocv, boundingRect(contours[0]), Scalar(0,0,200), 2);
3 | No.3 Revision |
this is probably an 'expectation mismatch'.
the outcome of findContours is not your img_threshold, but the contours vector.
if you care to lok look at the docs again you will see: "The function modifies the image while extracting the contours." again, this is just a by-product, not the desired result.
if you need your img_threshold for further operations, supply a clone() for findContours:
vector<vector<Point>>contours;
cv::findContours(img_threshold.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
// let's draw some things, assuming, Mat ocv is the original rgb image:
drawContours(ocv, contours, 0, Scalar(200,0,0), 2);
rectangle(ocv, boundingRect(contours[0]), Scalar(0,0,200), 2);