1

我想在较大的图像上添加一个较小的图像(最终用于视频源上的 PiP)。我可以通过迭代大图像中的相关数据属性并添加小图像中的像素来做到这一点。但是有没有更简单、更整洁的方法呢?我正在使用 EMGU。

我的想法是在与小图像相同大小的大图像中定义一个 ROI。将大图像设置为小图像,然后简单地删除 ROI。即在伪代码中:

Large.ROI = rectangle defined by small image;

Large = Small;

Large.ROI = Rectangle.Empty;

但是,这不起作用,大图像不会改变。任何建议将不胜感激。

大图:
大图

小图:
小图像

期望的结果:
期望的结果

4

4 回答 4

5

如果您使用 C++ API,那么下面的代码片段应该可以工作:

cv::Mat big;
cv::Mat small;

// Define roi area (it has small image dimensions). 
cv::Rect roi = cv::Rect(50,50, small.cols, small.rows);

// Take a sub-view of the large image
cv::Mat subView = big(roi); 

// Copy contents of the small image to large
small.copyTo(subView); 

注意不要超出大图像的尺寸。

于 2012-07-02T11:30:35.577 回答
1

我不知道这是否会有所帮助,我没有使用过emgu。然而,这就是我能够用opencv做图像中的图像的方式。

drawIntoArea(Mat &src, Mat &dst, int x, int y, int width, int height)
{
    Mat scaledSrc;
    // Destination image for the converted src image.
    Mat convertedSrc(src.rows,src.cols,CV_8UC3, Scalar(0,0,255));

    // Convert the src image into the correct destination image type
    // Could also use MixChannels here.
    // Expand to support range of image source types.
    if (src.type() != dst.type())
    {
        cvtColor(src, convertedSrc, CV_GRAY2RGB);
    }else{
        src.copyTo(convertedSrc);
    }

    // Resize the converted source image to the desired target width.
    resize(convertedSrc, scaledSrc,Size(width,height),1,1,INTER_AREA);

    // create a region of interest in the destination image to copy the newly sized and converted source image into.
    Mat ROI = dst(Rect(x, y, scaledSrc.cols, scaledSrc.rows));
    scaledSrc.copyTo(ROI);
}
于 2013-07-18T13:26:33.920 回答
0

我对 EMGU 有很多经验。据我所知,您采用的方法是在大图像中显示子图像数据的唯一直接方式。您可能必须刷新较大的图像,这具有擦除传输数据并将较小的图像复制回来的内在效果。

虽然解决方案是可能的,但我认为该方法存在缺陷。所需的处理时间将影响任何图像在较大视图中的显示速率。

一种改进的方法是添加另一个控件。实际上,您的视频提要窗口在背景中显示较大的图像,而在此顶部的较小控件则显示较小的图像。实际上,您可以根据需要拥有尽可能多的这些较小的控件。实际上,您将在两个不同的控件(例如图像框)中显示两个图像或视频源。由于您拥有执行此操作的代码,您所要做的就是确保控件的显示顺序。

我假设您没有将输出编程到控制台窗口。如果您需要更多帮助,请随时询问。

至于评论 EMGU 是用 C# 编写的,虽然很欣赏您对不调用 EMGU OpenCV 的看法,但为什么不应将其标记为面向 OpenCV 的问题。毕竟 EMGU 只是带有 ac# 包装器的 OpenCV 库。我在 OpenCV 上发现了许多对 EMGU 有用的资源,反之亦然。

干杯克里斯

于 2011-07-14T14:52:08.967 回答
0

根据@BloodAxe 的回答,使用 EMGU 3.4 进行以下工作:

// Define roi area (it has small image dimensions). 
var ROI = new System.Drawing.Rectangle(100, 500, 200, 200)

// Take a sub-view of the large image
Mat subView = new Mat(bigImage, ROI);

// Copy contents of the small image to large
small.CopyTo(subView);
于 2018-12-13T16:25:08.200 回答