简体   繁体   中英

How to replace part of the image with another image ROI

using opencv2.4.11 java API i am trying to truncate part of an image and then place it on another image.

the code posted below shows, the truncate Mat object is a truncated part of the img_1 posted below. and img_2 is the image that should host the truncated part of the "truncated" Mat object.

When i run the code, the result is the img_3, and i exepected to see img_2 overlapped with the "truncated" Mat object img_3.

please let me know how to achieve this properly.

static final String PATH5 = "c:.../images/CannyDest.jpg";
static final String PATH6 = "c:.../images/BlurredDest.jpg";

public static void main(String[] args) {
    ....
    ....
    ....

    Mat temp = Highgui.imread(PATH5);//img_1
    Mat trunctaed = temp.submat(new Rect(0, 0, 30, 30));
    Mat target = Highgui.imread(PATH6);//img_2
    trunctaed.copyTo(target);
    Highgui.imwrite(PATH6, trunctaed);//img_3
    //Highgui.imwrite(PATH6, target);// results in img_3
}

img_1 img_1

img_2 img_2

img_3 img_3

According to the opencv dos, The parameter of copyTop() is the target. and you're saving the trunctaed picture and should actually save target

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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