1 | initial version |
in short - NO. only rectangular areas can be copied. (it's a silly demand, if you think of it)
but , what you can do is: make a mask from your contour, and mask out (blacken or such) anything inside the boundingRect but outside the contour:
Rect roi = boundingRect(contours[i])
Mat mask = Mat::zeros(roi.size(), img.type());
drawContours(mask,contours,i,Scalar::all(255), -1); // -1 == filled
Mat final;
img(roi).copyTo(final, mask);
2 | No.2 Revision |
in short - NO. only rectangular areas can be copied. (it's a silly demand, if you think of it)copied.
but , what you can do is: make a mask from your contour, and mask out (blacken or such) anything inside the boundingRect but outside the contour:
Rect roi = boundingRect(contours[i])
Mat mask = Mat::zeros(roi.size(), img.type());
drawContours(mask,contours,i,Scalar::all(255), -1); // -1 == filled
Mat final;
img(roi).copyTo(final, mask);
3 | No.3 Revision |
in short - NO. only rectangular areas can be copied.
but , what you can do is: make a mask from your contour, and mask out (blacken or such) anything inside the boundingRect but outside the contour:
Rect roi = boundingRect(contours[i])
Mat mask = Mat::zeros(roi.size(), img.type());
drawContours(mask,contours,i,Scalar::all(255), -1); // -1 == filled
Mat final;
img(roi).copyTo(final, mask);
binary_or(img(roi), mask, final); // EDIT !
4 | No.4 Revision |
in short - NO. only rectangular areas can be copied.
but , what you can do is: make a mask from your contour, and mask out (blacken or such) anything inside the boundingRect but outside the contour:
Rect roi = boundingRect(contours[i])
Mat mask = Mat::zeros(roi.size(), img.type());
drawContours(mask,contours,i,Scalar::all(255), -1); // -1 == filled
Mat final;
binary_or(img(roi), mask, final); // EDIT !
img(roi).copyTo(final, mask);