2017-04-26 12 views
1

私はPythonからC++にコードを移植しようとしています。私は黒色のイメージ(ポリゴン)の一部をペイントする必要があります。OpenCv例外fillconvexppoly

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

答えて

1

例外は、あなたのポイントが浮動小数点型であるCV_32S型(符号付き整数)をチェックしていたことを示しています。

ありがとう

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

であなたの

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

を交換してください!それはそれを働かせました。整数の代わりに浮動小数点を使用する方法はありますか? – user1298272

+0

本当にありません。ピクセルは本質的に整数であることを忘れないでください。私は最新のopenCVでもフロートタイプを扱うことは期待していません。理論的には、浮動小数点を取るdrawPoly関数のオーバーロードを行い、近似/アンチエイリアスを行い、キーポイントごとに複数のピクセルを定義するポリゴンを描画しますが、ポリゴンの単純な描画よりも多くのリソースを消費します。 – user3002166

関連する問題