Ask Your Question
0

Copy smaller mat to part of bigger mat

asked 2019-04-24 00:40:52 -0600

anton gravatar image

Hello everyone,

I have a mat1 (320x100), that I want to copy to a part of a bigger mat2 (320x480), so mat1 starts at (0, 75) from mat2 and ends at (320, 175). How do I do this? I would also like to now how to create a mat of a given color (e.g. mat3 (320x480) that is totally blue). How do I do this? I am using OpenCV 3.4.6 for android.

Thank you in advance

edit retag flag offensive close merge delete

Comments

and you did not find anything in the docs ?

berak gravatar imageberak ( 2019-04-24 01:47:15 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-04-24 04:21:40 -0600

berak gravatar image

1:)

 mat1.copyTo(mat2.submat(new Rect(0,75,320,100)));

2:)

Mat m = new Mat(480, 320, CvType.CV_8UC3, new Scalar(255,0,0));

3:) https://docs.opencv.org/master/javado...

edit flag offensive delete link more

Comments

So far I have this:

@Override
    public void onCameraViewStarted(int height, int width) {
        mat1 = new Mat(width, height, CvType.CV_8UC3);
        mat2 = new Mat(width, 175, CvType.CV_8UC3);
        mat3 = new Mat(width, height, CvType.CV_8UC3, new Scalar(255,0,0));
    }

and this:

@Override
    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        mat1 = inputFrame.rgba();
        Rect roi = new Rect(75, 0, 175, 320);
        mat2 = mat1.submat(roi).clone();
        mat2.copyTo(mat3.submat(new Rect(75,0,175,320)));
        return mat3;
}

But all I get is a red image ...

anton gravatar imageanton ( 2019-04-24 08:05:18 -0600 )edit

Mat(height, width, -- please.

you also overwrite most of your preallocated Mat's, so that's kinda useless (and misleading)

also, Rect(x,y,w,h)

also: mat1 will likely be CV_8UC4, not CV_8UC3

berak gravatar imageberak ( 2019-04-24 08:10:55 -0600 )edit

All my Mat's are rotated because the preview in opencv4android does not have the right rotation.

anton gravatar imageanton ( 2019-04-24 08:12:28 -0600 )edit

How do I get mat2 displayed on mat3?

anton gravatar imageanton ( 2019-04-24 08:16:23 -0600 )edit

Ok now I have this but it is still not working..

@Override
    public void onCameraViewStarted(int width, int height) {
        mat1 = new Mat(height, width, CvType.CV_8UC4);
        mat2 = new Mat(175, width, CvType.CV_8UC3);
        mat3 = new Mat(height, width, CvType.CV_8UC3, new Scalar(255,0,0));
    }

@Override
    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        mat1 = inputFrame.rgba();

        Rect roi = new Rect(75, 0, 175, 320);
        mat2 = mat1.submat(roi).clone();
        mat2.copyTo(mat3.submat(roi));

        return mat3;
    }
anton gravatar imageanton ( 2019-04-24 08:19:50 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-04-24 00:40:52 -0600

Seen: 2,699 times

Last updated: Apr 24 '19