gpt4 book ai didi

image-processing - 查找轮廓错误 'support only 8uC1 images'

转载 作者:太空宇宙 更新时间:2023-11-03 20:38:40 25 4
gpt4 key购买 nike

尝试在二进制图像上运行 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);

引发错误:

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

有什么想法吗?谢谢

最佳答案

来自 the documentation :

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

rtype – desired output matrix type or, rather, the depth since the number ofchannels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.

您看到 convertTo 没有改变 channel 数,这意味着您很可能获得 3 个 channel (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);

关于image-processing - 查找轮廓错误 'support only 8uC1 images',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13203981/

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