我正在尝试使用 fillConvexPoly
函数在掩码中填充三角形。
但我收到以下错误。
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
我像这样调用函数,
cv::Mat mask = cv::Mat::zeros(r2.size(), CV_32FC3);
cv::fillConvexPoly(mask, trOutCroppedInt, cv::Scalar(1.0, 1.0, 1.0), 16, 0);
其中 trOutCroppedInt 是这样定义的,
std::vector<cv::Point> trOutCroppedInt
我在 vector 中推了 3 个点,
[83, 46; 0, 48; 39, 0]
我应该如何纠正这个错误?
最佳答案
当遇到 points.checkVector(2, CV_32S) >= 0)
当数据类型比 CV_32S 更复杂且维度大于 2 时,可能会出现此错误,例如所有数据类型,如 vector<Point2f>
都可能产生问题。因此,我们可以按照以下步骤使用 fillConvexpoly
:
1. 使用 读取图像
cv::Mat src=cv::imread("what/ever/directory");
2. 确定点 你必须像下图一样确定你的分数
因此,我们针对这一点的代码是:
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.使用cv::fillConvexPoly
函数考虑图像
src
并在该图像上绘制一个多边形((带有点)),然后代码如下: 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
(所以输出图像如下:之前:左侧 - 之后:右侧)关于c++ - C++中的OpenCV fillConvexPoly函数抛出异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40284369/