【问题标题】:openCV no matching function fillPolyopenCV没有匹配函数fillPoly
【发布时间】:2018-01-08 13:15:02
【问题描述】:

我正在尝试实现this 答案,但我总是出错。请帮忙。

我的代码:

cv::Point corners[1][6];

for (unsigned long j = startIndex; j < startIndex+6; j++) {
  int x = shape.part(j).x(); 
  int y = shape.part(j).y();

  corners[0][j-startIndex] = Point(x, y);
}
const Point* corner_list[1] = {corners[0]};

cv::Mat mask(image.rows, image.cols, CV_8UC2);
cv::fillPoly(mask, corner_list, 6, 1, cv::Scalar(255), 8);
cv::Mat result(image.size(), image.type(), cv::Scalar(0,0,0));
image.copyTo(result, mask);

这是我的错误:

jni/jni_detections/jni_face_det.cpp:121:5: error: no matching function for call to 'fillPoly'
    cv::fillPoly( mask, corner_list, num_points, num_polygons, cv::Scalar( 255, 255, 255 ),  line_type);
    ^~~~~~~~~~~~ 
/home/feli/Development/android/test/dlib/dlib-android/third_party/opencv/jni/include/opencv2/imgproc.hpp:3987:17: note: 
      candidate function not viable: no known conversion from 'int' to 'const int *' for 3rd argument; take the address of
      the argument with & CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
                                          ^ 
/home/feli/Development/android/test/dlib/dlib-android/third_party/opencv/jni/include/opencv2/imgproc.hpp:4005:19: note: 
      candidate function not viable: no known conversion from 'const Point *[1]' to 'const cv::_InputArray' for 2nd argument 
CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,
                  ^

我的 OpenCV 版本是 3.1.0

【问题讨论】:

  • 看来你需要把cv::Scalar(255)改成cv::Scalar(255,255,255)
  • 或标量::all(255)。
  • “第三个参数没有从 'int' 到 'const int *' 的已知转换”——第三个参数需要是一个指向整数的指针,而不是你所拥有的整数常量。 | CV_8UC2 看起来也有点奇怪。为什么是 2 个频道?
  • @bandaf 我已经更新了另一个问题的答案:其中有一个错误。 “numPoints”参数(在您的示例中为 6)应该是一个指针。例如,请在您的第一个链接中查看我的答案。
  • 这就是问题所在,谢谢!

标签: c++ opencv syntax no-match


【解决方案1】:

看来你需要改变

cv::Scalar(255)

cv::Scalar(255,255,255)

【讨论】:

  • 您的答案中的错字。它应该是 cv::Scalar(255,255,255) 而不是 cv:Scalar(255,255,255)
  • 这种事情不会导致 OP 出现编译错误。除此之外,mask 目前(由于某种未知原因)是一个 2 通道图像,所以这并不是更正确。
  • 我也必须这样做,但不是那个导致构建错误
【解决方案2】:

我需要像这样传递 numPoints 参数的指针:

int num_points = 6;
cv::fillPoly(mask, corner_list, &num_points, 1, cv::Scalar(255), 8);

感谢@Tim Sweet

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多