OpenCV draw an image over another image

前端 未结 4 467
礼貌的吻别
礼貌的吻别 2020-12-07 21:06

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<

4条回答
  •  旧巷少年郎
    2020-12-07 21:35

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

    Results in the following:

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

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

提交回复
热议问题