Ask Your Question
2

convert a Mat type to be a type of frame Mat

asked 2016-09-04 04:43:27 -0600

elish gravatar image

Hi,

I am working on an augmented reality app in android,
In "onCameraFrame" i am trying to overlay a small Mat which is an image that was converted from bitmap, onto frame Mat that will be returned to camera preview, i am using submat to do it.
The problem is that the 2 Mat objects need to be the same type and i can not get the way to do it.

when i print the type of the small mat -

ImageMat.type()

i get 24.
when i print the frame Mat -

rgba.type()

i get 16.
How can i make the first one also 16 ?

edit retag flag offensive close merge delete

Comments

can it be, you got the numbers switched ? (if rgba is, what it says, it should have type()==24)

berak gravatar imageberak ( 2016-09-04 05:23:12 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-09-04 05:04:28 -0600

berak gravatar image

24 == CV_8UC4, 16 == CV_8UC3.

so, to convert ImageMat to the format of rgba (misnomer?) you would use:

Mat dst = new Mat();
Imgproc.cvtColor( ImageMat, dst, Imgproc.COLOR_BGRA2BGR );

or, into the other direction:

Imgproc.cvtColor( rgba, dst, Imgproc.COLOR_BGR2BGRA );

also see docs, and remember, that opencv's Mat''s are in BGR order, while native android has it RGB(A)

edit flag offensive delete link more

Comments

@berak Thank you very much!! it worked!!

elish gravatar imageelish ( 2016-09-04 05:33:43 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-04 04:43:27 -0600

Seen: 2,034 times

Last updated: Sep 04 '16