简体   繁体   English

如何在OpenCv C ++中向图像添加图像

[英]How add image to image in OpenCv c++

I load small image. 我加载小图像。

 Mat extra;
 extra = imread("Korona.jpg");

I load image from camera and I try add my image. 我从相机加载图像,然后尝试添加图像。

VideoCapture cap;
Mat frame;
cap >> frame;
cv::Rect roi(cv::Point(0, 0), cv::Size(110, 110));
cv::Mat destinationROI = img(roi);
extra.copyTo(destinationROI(cv::Rect(0, 0, extra.cols, extra.rows)));

But not successful and have this 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, file C:\\build\\master_winpack-build-win64-vc14\\opencv\\modules\\core\\src\\matrix.cpp, line 522 OpenCV错误:断言失败(0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows)在cv :: Mat :: Mat中,文件C:\\ build \\ master_winpack-build-win64-vc14 \\ opencv \\ modules \\ core \\ src \\ matrix.cpp,第522行

Any ideas? 有任何想法吗? Thx. 谢谢。

if(roi.x >= 0 && roi.y >= 0 && roi.width + roi.x < input_frame.cols && roi.height + roi.y < input_frame.rows)
{
    // your code

}
else
    return -1;

Found similar issues and pulled code from here and here 发现类似的问题并从这里这里拉出代码

Looking at your code, looks like you don't open your capture 查看您的代码,好像您没有打开捕获

VideoCapture cap(0); //for a webcam
Mat frame;
if(cap.isOpened())
   cap >> frame;
else
   throw;
cv::Rect roi(cv::Point(0, 0), cv::Size(110, 110));
cv::Mat destinationROI = frame(roi);
extra.copyTo(destinationROI(cv::Rect(0, 0, extra.cols, extra.rows)));

Check out OpenCV's documentation on VideoCapture to make sure you're getting that done correctly. 在VideoCapture上查看OpenCV的文档 ,以确保正确完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM