How to Prevent drawContours() to draw strange wrong line?
I have found some rule about this problem, this wrong line connects two point and do not cross any others contour points.
It seams that drawContours prefer convex shape, but I am not very sure about it.
std::vector<std::vector<Point>> collision_for_mask2_contours;
test for this variable, I have put it in bmp image in accessory file , you can get points from it for drawContours.
Thank you very much!
G:\test.bmp
int main(int argc, char* argv[])
{
argv[]){
// test code for drawContours
std::vector<std::vector<Point>> collision_for_mask2_contours;
std::vector<Point> constours;
Mat_<uchar> testbmp = imread("G:/test.bmp", WINDOW_AUTOSIZE);
namedWindow("testbmp");
imshow("testbmp", testbmp);
waitKey(0); // need to press any key to continue
for (int y = 0; y < testbmp.rows; ++y) {
for (int x = 0; x < testbmp.cols; ++x) {
if (testbmp(y, x)) {
constours.push_back(Point(x, y));
}
}
}
collision_for_mask2_contours.push_back(constours);
Mat_<uchar> testForDrawContours = Mat_<uchar>::zeros(testbmp.size());
// one case, can not get concave shape
drawContours(testForDrawContours, collision_for_mask2_contours, -1, Scalar(255));
namedWindow("testForDrawContours", WINDOW_AUTOSIZE);
imshow("testForDrawContours", testForDrawContours);
waitKey(0);
// one another case, also can not get concave shape
drawContours(testForDrawContours, collision_for_mask2_contours, -1, Scalar(255), -1, 8);
namedWindow("testForDrawContours2", WINDOW_AUTOSIZE);
imshow("testForDrawContours2", testForDrawContours);
waitKey(0);
waitKey(0);}
}