OPENCV异常填充Conconvexppoly

Opencv exception fillconvexppoly

本文关键字:Conconvexppoly 填充 异常 OPENCV      更新时间:2023-10-16

我正在尝试将代码从Python移植到C 。我需要用黑色绘制图像的一部分(多边形(。

在Python中,我有积分列表,然后我打电话给FillConvexPolygon来做到这一点。我在C 中尝试过同样的尝试,但是我得到了这个例外:

OpenCV Error: Assertion failed (points.checkVector(2, CV_32S) >= 0) in fillConvexPoly, file /home/user/template_matching/repositories/opencv/modules/core/src/drawing.cpp, line 2017
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/user/template_matching/repositories/opencv/modules/core/src/drawing.cpp:2017: error: (-215) points.checkVector(2, CV_32S) >= 0 in function fillConvexPoly

我能够在图像上绘画线,并且在用作多边形轮廓的点列表中有点:

drawMatches(img_object, TSMART_BANKNOTE[i].kp, img_orig, BankNote_t.kp,
            good, img_matches, Scalar::all(-1), Scalar::all(-1),
            vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
 line(img_matches, scene_corners[0] + Point2f(img_object.cols, 0), 
                       scene_corners[1] + Point2f(img_object.cols, 0), 
                                                  Scalar(0, 255, 0), 4);  //Left side
 line(img_matches, scene_corners[2] + Point2f(img_object.cols, 0),
                       scene_corners[3] + Point2f(img_object.cols, 0), 
                                                  Scalar(0, 255, 0), 4);  //right side
 line(img_matches, scene_corners[1] + Point2f(img_object.cols, 0), 
                       scene_corners[2] + Point2f(img_object.cols, 0),
                                                  Scalar(0, 255, 0), 4);    //Down line
 line(img_matches, scene_corners[3] + Point2f(img_object.cols, 0),
                       scene_corners[0] + Point2f(img_object.cols, 0),
                                                  Scalar(0, 255, 0), 4);       //Up line
    vector<Point2f> pt;
pt.push_back(Point2f(scene_corners[0].x + img_object.cols, 
                       scene_corners[1].y));
pt.push_back(Point2f(scene_corners[2].x + img_object.cols, 
                       scene_corners[3].y));
pt.push_back(Point2f(scene_corners[1].x + img_object.cols, 
                       scene_corners[2].y));
pt.push_back(Point2f(scene_corners[3].x + img_object.cols, 
                       scene_corners[0].y));
std::cout << "PT POINTS: " << pt.size() <<"rn";
    //fillConvexPoly(img_matches, pt, pt.size(), Scalar(1,1,1), 16, 0);
     fillConvexPoly(img_matches, pt, cv::Scalar(255), 16, 0);
    //-- Show detected matches
std::cout <<"H5rn"; 
imshow( "Good Matches & Object detection", img_matches);
    waitKey(0);

在文档中,我找到了接收向量大小的fillconvexpoly函数。我的似乎不接受。我正在使用OpenCV 2.4.6

例外表明它正在检查CV_32S类型(签名整数(,其中您的点为float类型。

更换您的

std::vector<cv::Point2f> pt;

std::vector<cv::Point2i> pt;