【问题标题】:How add image to image in OpenCv c++如何在 OpenCv c++ 中将图像添加到图像
【发布时间】:2017-06-14 15:33:09
【问题描述】:

我加载小图像。

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

我从相机加载图像并尝试添加我的图像。

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

但是不成功并且出现这个错误:

OpenCV 错误:断言失败 (0

有什么想法吗?谢谢。

【问题讨论】:

  • 错误表示你的roi尺寸大于源Mat在jpg中读取的尺寸是多少?
  • extra.copyTo(img(cv::Rect(5, 5, 11, 11)));我试试这个但有这个错误 penCV 错误:断言失败 (scn == 3 || scn == 4) in cv::cvtColor, 文件 C:\build\master_winpack-build-win64-vc14\opencv\modules\imgproc\ src\color.cpp,第 9716 行
  • 什么是img?声明不在您的代码中...

标签: c++ image opencv add


【解决方案1】:
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;

发现类似问题并从herehere提取代码

查看您的代码,您似乎没有打开捕获

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

在 VideoCapture 上查看 OpenCV 的 documentation,以确保您正确地完成了这项工作。

【讨论】:

    猜你喜欢
    • 2012-09-25
    • 2021-07-08
    • 1970-01-01
    • 2012-01-20
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    • 2020-02-03
    • 1970-01-01
    相关资源
    最近更新 更多