Ubuntu下使用qtcreator,opencv3.0调用函数 connectedComponents报错。

weixin_39381465 2018-06-10 09:41:02

void MainWindow::on_AOI_clicked()
{
cv::namedWindow("noise");
cv::namedWindow("output");
cv::Mat pattern;//(653,994,CV_8UC3,cv::Scalar(100,100,100));
cv::Mat aux,thr30,thr140;
cv::Mat clean = cv::imread("/home/kylin/图片/2.jpg");
cv::blur(clean,pattern,cv::Size(clean.cols/3,clean.cols/3));
//cv::imshow("pattern",pattern);//背景近似值
aux = pattern - clean;
cv::medianBlur(aux,noise,3);//除噪
cv::threshold(aux,thr30,30,255,cv::THRESH_BINARY);
cv::threshold(aux,thr140,140,255,cv::THRESH_BINARY_INV);//二值化
//cv::imshow("clean",thr30);
cv::imshow("noise",thr140);
thr140.convertTo(thr140,CV_8UC1);//转换为8位格式
cv::imshow("aux",thr140);
cv::Mat labels;
int num_objects = cv::connectedComponents(thr140,labels,8,CV_32S);//此处过不去。
//int num_objects = 6;
if(num_objects < 2)
{
qDebug()<< "No objects detected" << endl;
}
else
qDebug()<< "Number of objects detected: "<< num_objects - 1 << endl;
//创建彩色目标的输出图像
cv::Mat output = cv::Mat::zeros(thr140.rows,thr140.cols,CV_8UC3);
cv::RNG rng(0xFFFFFFFF);
for(int i=1;i < num_objects;i++)
{
cv::Mat mask = labels==i;
output.setTo(randomColor(rng),mask);
}
cv::imshow("output",output);


终端提示报错信息如下。不知道是环境搭建有问题还是函数调用问题。麻烦大家,有没有碰到过类似问题的帮我想想办法。
OpenCV Error: Assertion failed (L.channels() == 1 && I.channels() == 1) in connectedComponents_sub1, file /build/opencv-zcaJjh/opencv-3.2.0+dfsg/modules/imgproc/src/connectedcomponents.cpp, line 1657
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-zcaJjh/opencv-3.2.0+dfsg/modules/imgproc/src/connectedcomponents.cpp:1657: error: (-215) L.channels() == 1 && I.channels() == 1 in function connectedComponents_sub1
...全文
1349 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧