【问题标题】:findContours error 'support only 8uC1 images'findContours 错误“仅支持 8uC1 图像”
【发布时间】:2012-11-03 06:51:59
【问题描述】:

尝试在二进制图像上运行 findContours"

Mat conv(image.size(), CV_8U);
image.convertTo(conv, CV_8U);
vector<vector<cv::Point> > contours;

findContours(conv, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);

throws 错误:

OpenCV Error: Unsupported format or combination of formats ([Start]FindContours support only 8uC1 images) in cvStartFindContours, 

有什么想法吗? 谢谢

【问题讨论】:

    标签: image-processing opencv


    【解决方案1】:

    来自the documentation

    C++: void Mat::convertTo(OutputArray m, int rtype, double alpha=1, double beta=0) const
    参数:

    rtype – 所需的输出矩阵类型,或者更确切地说,自 通道与输入相同;如果 rtype 为负,则输出矩阵将与输入具有相同的类型。

    您看到convertTo 没有改变通道数,这意味着您很可能获得了 3 个通道(r、g 和 b)。但是findContours 需要单色图像。

    您需要将图像转换为黑白:

    cv::Mat bwImage;
    cv::cvtColor(image, bwImage, CV_RGB2GRAY);
    vector< vector<cv::Point> > contours;
    cv::findContours(bwImage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
    

    【讨论】:

    • 有没有办法可以将其还原为单色?我已经有一张黑白图像,它是用另一个程序的 canny 过滤的
    • @0xSina:是的,刚刚添加了它:)
    猜你喜欢
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多