Ask Your Question
0

how to use submat for a non square image

asked 2016-09-04 05:51:26 -0600

elish gravatar image

Hi,

I am working on an augmented reality app in android,
I am trying to overlay an image that is a shape of a star, its not a full squar onto the camera frame,

       dst.copyTo(submat);

but i get a black square in roi area and in the middle is the star.

How can i limit the size of submat to be the shape i want,
Is there a way to copy pixels instead of rows and cols?

Thank you!!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-09-04 06:39:09 -0600

berak gravatar image

you can use a mask with copyTo().

so, first make a black image:

Mat mask = new Mat(submat.size(), CvType.CV_8U, new Scalar(0));
// then draw a filled white star into that,
// e.g. with drawContours(), and linesize=-1
//
// now use that mask, to copy only where the mask is white:
dst.copyTo(submat, mask);
edit flag offensive delete link more

Comments

@berak Thank you so much berak, it is a perfect answer for me!

elish gravatar imageelish ( 2016-09-04 07:37:09 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-04 05:51:26 -0600

Seen: 519 times

Last updated: Sep 04 '16