c++ - 使用来自 OpenCV 2.4.3 C++ 接口(interface)的 fillPoly 未处理的异常绘图不是凸多边形

标签 c++ opencv drawing

我正在尝试使用 OpenCV 2.4.3 c++ 接口(interface)在二进制图像中绘制一些通过 findContours 找到的连接组件。代码是这样的。

std::vector<std::vector<cv::Point> > contours;
std::vector<cv::Vec4i> hierarchy;
cv::findContours( tempOR, contours, hierarchy, CV_RETR_EXTERNAL , CV_CHAIN_APPROX_TC89_L1, cv::Point(0, 0) );

bgs_detection_or=cv::Mat::zeros(cv::Size(m_frame_width, m_frame_height), CV_8UC1);
for( int i = 0; i < contours.size(); i++ )
{
    if (pointPolygonTest(contours[i], cv::Point2f(m_car_coords.x, m_car_coords.y-1), false)>-1)
    {
        std::vector<cv::Point> contours_poly;
        approxPolyDP( cv::Mat(contours[i]), contours_poly, 3, true );           

        //cv::fillConvexPoly(bgs_detection_or, contours_poly, cv::Scalar(255));
        cv::fillPoly(bgs_detection_or, contours_poly, cv::Scalar(255));
        break;
    }
}

如您所见,我也尝试使用 fillConvexPoly。 fillConvexPoly 不会抛出任何错误,但它不会正确绘制多边形。之后我尝试使用 fillPoly,仅此而已,我无法管理未处理的异常。

我也试过这样调用fillPoly:

cv::fillPoly(bgs_detection_or, contours_poly, contours_poly.size(), 1, cv::Scalar(255));

但随后出现编译错误:错误 35 error C2665: 'cv::fillPoly' : 2 个重载中没有一个可以转换所有参数类型

我做错了什么?

最佳答案

我找到了实现最终目标的解决方法:

drawContours( bgs_detection_or, contours, i, cv::Scalar(255), CV_FILLED);

但我不明白为什么 fillPoly 会抛出未处理的错误,而 fillConvexPoly 不会。

关于c++ - 使用来自 OpenCV 2.4.3 C++ 接口(interface)的 fillPoly 未处理的异常绘图不是凸多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14603709/

相关文章:

python - Python-OpenCv相机校准-将 map 矩阵保存到文件并读回

ios - Xamarin iOS : Why there is a line from the center to arc of the circle

iphone - 在 iPhone 上使用 Quartz 绘制虚线

c++ - 在这里类型转换最好的解决方案吗?

image - 从点获取畸变变换

C++ 变量零校正

image-processing - 模拟 "unfocused"图像

ios - 在 UIBezierPath 的两侧应用阴影

c++ - 使用 sfml 绘制瓦片 map

c++ - 嵌套的重载运算符?