gpt4 book ai didi

c++ - Opencv 异常 fillconvexppoly

转载 作者:太空宇宙 更新时间:2023-11-03 22:48:30 24 4
gpt4 key购买 nike

我正在尝试将代码从 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() <<"\r\n";

//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 <<"H5\r\n";
imshow( "Good Matches & Object detection", img_matches);
waitKey(0);

在文档中我发现了一个接收 vector 大小的 fillconvexpoly 函数。我的似乎不接受这一点。我使用的是 opencv 2.4.6

最佳答案

异常表明它正在检查 CV_32S 类型(有符号整数),其中您的点是 float 类型。

替换你的

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

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

关于c++ - Opencv 异常 fillconvexppoly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43629978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com