OpenCV fillConvexPoly function in C++ throws exception

c++, opencv

Solution

When points.checkVector(2, CV_32S) >= 0) is encountered

This error may occur when the data type is more complex than CV_32S and the dimension is greater than two, for example all data type like `vector<Point2f>` can create the problem. As the result we can use `fillConvexpoly` according to the following steps:

1. Reading an Image with

cv::Mat src=cv::imread("what/ever/directory");

2. determine points You must determine your points like in the following graphic

Thus, our code for this point is:

vector<cv::Point> point;
point.push_back(Point(163,146));  //point1
point.push_back(Point(100,148));  //point2
point.push_back(Point(100,110));  //point3
point.push_back(Point(139,110));  //point4

3.Use `cv::fillConvexPoly` function

Consider the image `src` and draw a polygon ((with the points)) on this image then code would be as follows:

   cv::fillConvexPoly(src,               //Image to be drawn on
                      point,             //C-Style array of points
                      Scalar(255, 0, 0), //Color , BGR form
                      CV_AA,             // connectedness, 4 or 8
                      0);                // Bits of radius to treat as fraction

(so output image is as follows: before:left side - after:right side)

Problem

I'm trying to fill a triangle in a mask using the `fillConvexPoly` function. But I get the following error. ``` OpenCV Error: Assertion failed (points.checkVector(2, CV_32S) >= 0) in fillConvexPoly, file /home/iris/Downloads/opencv-3.1.0/modules/imgproc/src/drawing.cpp, line 2256 terminate called after throwing an instance of 'cv::Exception' what(): /home/iris/Downloads/opencv-3.1.0/modules/imgproc/src/drawing.cpp:2256: error: (-215) points.checkVector(2, CV_32S) >= 0 in function fillConvexPoly ``` I call the function as like so, ``` cv::Mat mask = cv::Mat::zeros(r2.size(), CV_32FC3); cv::fillConvexPoly(mask, trOutCroppedInt, cv::Scalar(1.0, 1.0, 1.0), 16, 0); ``` where the trOutCroppedInt defined like so, ``` std::vector<cv::Point> trOutCroppedInt ``` And I push 3 points in the vector, ``` [83, 46; 0, 48; 39, 0] ``` How should I correct this error?

Original source