项目开发中使用到opencv,设置roi区域。运行时出现了tombstone。
Abort message: 'terminating with uncaught exception of type cv::Exception: external/opencv3/modules/core/src/matrix.cpp:495: error: (-215) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols &0 <= roi.height && roi.y + roi.height <= m.rows in function Mat
分析发现,原因是图像的ROI区域超过了图像的尺寸,即roi.x + roi.width > m.cols && roi.y + roi.height > m.rows;
之前一直以为从camera得到的图片是1920 * 1080的,而添加打印后发现,实际大小只有1080 * 720;所以出现了这个问题;
重新调整ROI区域的设置,运行时就正常了。
Mat src = imread("path_to_image");
cout << src.width;
cout << "Width : " << src.cols << endl;
cout << "Height: " << src.rows << endl;