error: OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat

问题原因:

You are probably working outside of the image dimensions. Does any of the values you pass to the cvSetImageROI function lay outside the image boudaries?

图像的ROI区域超过了图像的尺寸,即roi.x + roi.width > m.cols && roi.y + roi.height > m.rows

解决办法:

判断截取的ROI尺寸是否在图像内

原文地址:https://www.cnblogs.com/long5683/p/9898409.html