Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.

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
}

img_1 img_1

img_2 img_2

img_3 img_3

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.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
}

img_1 img_1

img_2 img_2

img_3 img_3

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.

Highgui.imwrite(path2, destImg);
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
}

update:

    Mat destImg = Highgui.imread(path0, Highgui.IMREAD_COLOR);
    Mat srcImg = Highgui.imread(path1);

    srcImg.copyTo(destImg.submat(0, 30, 0, 30));

    /*          //Also i tried the following 
     * srcImg.submat(new Rect(0, 0, 30, 30)).copyTo(destImg.submat(0,30,0,30));
        Highgui.imwrite(path2, destImg);

        srcImg.submat(new Rect(0, 0, 30, 30)).copyTo(destImg.submat(new Rect(0, 0, 30, 30)));
        Highgui.imwrite(path2, destImg);*/

img_1 img_1

img_2 img_2

img_3 img_3

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.

Highgui.imwrite(path2, destImg);
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
}

update:

    Mat destImg = Highgui.imread(path0, Highgui.IMREAD_COLOR);
    Mat srcImg = Highgui.imread(path1);

    srcImg.copyTo(destImg.submat(0, 30, 0, 30));
     Highgui.imwrite(path2, destImg);

    /*          //Also i tried the following 
     * srcImg.submat(new Rect(0, 0, 30, 30)).copyTo(destImg.submat(0,30,0,30));
        Highgui.imwrite(path2, destImg);

        srcImg.submat(new Rect(0, 0, 30, 30)).copyTo(destImg.submat(new Rect(0, 0, 30, 30)));
        Highgui.imwrite(path2, destImg);*/

img_1 img_1

img_2 img_2

img_3 img_3