Ask Your Question
0

Hot to convert a Mat object to byte[] data object in "onPreviewFrame" and show it in camera preview

asked 2016-07-04 07:37:18 -0600

elish gravatar image

updated 2016-07-04 10:46:43 -0600

In my android app, I am trying to take frames in "onPreviewFrame" and convert them to Mat object so i can do on them some image processing, but i don't know how to convert them back to byte[] type and make them be shown on camera preview.

Does any one know how to do that?

Here is my onPreviewFrame function, i am trying to change frame color to grey:

public void onPreviewFrame(byte[] data, Camera arg1)
{
    Mat mRgba = new Mat(PreviewSizeWidth, PreviewSizeHeight, CvType.CV_8UC3);
    mRgba.put(0, 0, data);

    Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_BGR2GRAY);
    mRgba.put(0, 0, data);

    mCamera.addCallbackBuffer(data);

}

Thanks in advance!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-07-05 01:46:30 -0600

berak gravatar image

you should process your image in onCameraFrame() .

just get your Mat from inputFrame.rgba();, whatever you return , will get shown in the preview.

(no need to process byte[] buffers, also, in your example above, your 2nd put call overwrites the cvtColor() (and might even crash))

edit flag offensive delete link more

Comments

@berak I tried to do it in onCameraFrame() but the resolution of the camera preview of CvCameraViewListener2 was very bad. Can i use the camera of android and together with that use CvCameraViewListener2 only for onCameraFrame and it will work?

elish gravatar imageelish ( 2016-07-05 03:23:25 -0600 )edit

hi berak, I tried to do in mine onCameraFrame() somthing like this:

mRgba = inputFrame.gray();
 Core.transpose(mRgba, mRgbaT);
 Imgproc.resize(mRgbaT, mRgbaF, mRgbaF.size(), 0,0, 0);
 Core.flip(mRgbaF, mRgba, 1 );

return mRgba;

and the preview dosent on gray and show wide (not good resulation)

thenk.

lea gravatar imagelea ( 2016-07-05 05:04:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-04 07:37:18 -0600

Seen: 920 times

Last updated: Jul 05 '16