您的位置:首页 > 大数据 > 人工智能

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow

2013-09-09 20:58 916 查看
刚开始学习OpenCV编程,写了一个程序:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

void colorReduce( cv::Mat &image, int div=64 )
{
int nl = image.rows;
int nc = image.cols * image.channels();

for(int j=0; j<nl; j++)
{
uchar *data = image.ptr<uchar>(j);

for( int i=0; i<nc; i++)
{
data[i] = data[i]/div*div + div/2;
}
}
}

int main(void)
{
cv::Mat image = cv::imread("/home/fighting324/Pictures/lena.jpg");
colorReduce( image );

cv::namedWindow("colorReduced", CV_WINDOW_AUTOSIZE);
cv::imshow("colorReduced", image);

cv::waitKey();
}


后来运行时出现了这样的一个错误:OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/fighting324/app/opencv/modules/highgui/src/window.cpp, line 261

terminate called after throwing an instance of 'cv::Exception'

what(): /home/fighting324/app/opencv/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow

怎么搞都没有解决,搜索了将近一个小时之后发现了这个帖子:http://answers.opencv.org/question/18135/opencv-error-assertion-failed-sizewidth0/

我也照猫画虎,将我代码中读取图像的这一句:

cv::Mat image = cv::imread("~/Pictures/lena.jpg");
中的~改成了/home/fighting324,竟然就好了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐