c – cv :: findcontours导致程序崩溃
我正试图从我的框架中获取轮廓,这就是我所做的:
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我收到此错误消息:
解决方法
在识别轮廓之前,需要将图像缩小为二进制图像.这可以通过例如应用某种边缘检测算法或通过简单的阈值处理来完成:
// 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,...); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |