我正在尝试为较大的图片添加徽标,但我收到以下错误。
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 Mat, file C:\opencv246\modules\core\src\matrix.cpp, line 323
terminate called after throwing an instance of ’cv::Exception’
what(): C:\opencv246\modules\core\src\matrix.cpp:323: error: (-215) 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 function Mat
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application’s support team for more information.
有人可以请更正我的代码吗?我一直试图修复它三个小时,但仍然无法做到。
这是我的代码。
using namespace std;
using namespace cv;
int main()
{
Mat image = imread("C:\\castle.jpg",0);
Mat logo = imread("C:\\logo.jpg",0);
Mat imageROI = image(cv::Rect(385,270,logo.cols,logo.rows));
addWeighted(imageROI,1.0,logo,0.3,0.,imageROI);
namedWindow("output",CV_WINDOW_AUTOSIZE);
imshow("output",imageROI);
waitKey(0);
destroyAllWindows();
}
答案 0 :(得分:1)
您的图片可能没有合适的尺寸。 image
和logo
的像素尺寸是多少?如果image.cols < 385 + logo.cols
或image.rows < 270 + logo.rows
,您将无法在此图片上重叠此徽标。