Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenCV将徽标添加到感兴趣的区域_Opencv - Fatal编程技术网

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();
}