OpenCV在另一个图像上绘制图像 [英] OpenCV draw an image over another image

查看:95
本文介绍了OpenCV在另一个图像上绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有OpenCV功能在另一张图像上绘制图像?
我有一个 Mat 类型的大图像。
我有一张 Mat 类型的小图片( 5x7 )。
我想在指定坐标

Is there an OpenCV function to draw an image over another image? I have one big image of Mat type. And I have a small image of Mat type (5x7). I want to draw this small image over the big image at specified coordinates.

推荐答案

使用 Mat :: rowRange() Mat :: colRange()来指定要在目标 Mat 中绘制的区域。代码:

Use Mat::rowRange() and Mat::colRange() to specify the area to which you want to draw in the destination Mat. Code:

Mat src( 5,  7, CV_8UC1, Scalar(1)); // 5x7
Mat dst(10, 10, CV_8UC1, Scalar(0)); // 10x10

src.copyTo(dst.rowRange(1, 6).colRange(3, 10));

结果如下:

之前 copyTo()

dst:
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )

copyTo()之后:

dst:
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 1 1 1 1 1 1 1 )
    ( 0 0 0 1 1 1 1 1 1 1 )
    ( 0 0 0 1 1 1 1 1 1 1 )
    ( 0 0 0 1 1 1 1 1 1 1 )
    ( 0 0 0 1 1 1 1 1 1 1 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )
    ( 0 0 0 0 0 0 0 0 0 0 )

这篇关于OpenCV在另一个图像上绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆