OpenCV将徽标添加到感兴趣的区域
我试图添加一个标志到一个更大的图像,但我得到以下错误OpenCV将徽标添加到感兴趣的区域,opencv,Opencv,我试图添加一个标志到一个更大的图像,但我得到以下错误 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,
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.
您的图像可能大小不正确。
图像
和徽标
的像素尺寸是多少?如果image.cols<385+logo.cols
或image.rows<270+logo.rows
您将无法在此位置将此徽标重叠到此图像上 将您的错误粘贴到此处,而不是屏幕截图的链接。看起来您的图像太小,无法在给定位置保留徽标如果(385+logo.cols>=image.cols)您的徽标太大,必须调整其大小,或者必须增加图像大小
,对于徽标。行
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();
}