加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – cv :: findcontours导致程序崩溃

发布时间:2020-12-16 09:41:36 所属栏目:百科 来源:网络整理
导读:我正试图从我的框架中获取轮廓,这就是我所做的: cv::Mat frame,helpframe,yframe,frame32f; Videocapture cap(1); .......while(waitkey()){cv::Mat result = cv::Mat::zeros(height,width,CV_32FC3);cap frame; // get a new frame from cameraframe.conve
我正试图从我的框架中获取轮廓,这就是我所做的:

cv::Mat frame,helpframe,yframe,frame32f;
 Videocapture cap(1); 
.......
while(waitkey()){
cv::Mat result = cv::Mat::zeros(height,width,CV_32FC3);
cap >> frame; // get a new frame from camera
frame.convertTo(frame32f,CV_32FC3);
for ( int w = 0; w< 10;w ++){
            result += frame32f;
        }   
         //Average the frame values.
        result *= (1.0/10);
        result /= 255.0f;
cvtColor(result,CV_RGB2YCrCb); // converting to Ycbcr///// the code work fine when I use frame instead of result 
extractChannel(yframe,0); //extracting the Y channel
cv::minMaxLoc(helpframe,&minValue,&maxValue,&min,&max);
std::vector<std::vector<cv::Point>> contours;
cv::findContours(helpframe,contours,CV_RETR_LIST /*CV_RETR_EXTERNAL*/,CV_CHAIN_APPROX_SIMPLE);

………………………………………….. ..

程序崩溃在findcontours,我debbug我收到此错误消息:

OpenCV Error: Unsupported format or combination of formats ([Start]FindContours
support only 8uC1 and 32sC1 images) in unknown function,file ……srcopenc
vmodulesimgprocsrccontours.cpp,line 196

@Niko感谢您的帮助我认为我必须将帮助框架转换为其他类型.
当我使用结果时,我得到了
?????helpframe.type()=>五
?和框架我得到0
我不知道这是什么意思?但我会尝试找到转换帮助框架的方法.

转换帮助框架后:
?????helpframe.convertTo(helpframe2,CV_8U)

我什么都得不到helpframe2 = 0?当我尝试使用框架而不是结果框架时,转换工作?

知道我应该如何更改帮助框架类型,因为我使用结果而不是框架?

解决方法

在识别轮廓之前,需要将图像缩小为二进制图像.这可以通过例如应用某种边缘检测算法或通过简单的阈值处理来完成:

// Binarize the image
cv::threshold(helpframe,50,255,CV_THRESH_BINARY);

// Convert from 32F to 8U
cv::Mat helpframe2;
helpframe.convertTo(helpframe2,CV_8U);

cv::findContours(helpframe2,...);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读