Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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);
    Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);

}

Thanks in advance!

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

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);
    Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);
mRgba.put(0, 0, data);

    mCamera.addCallbackBuffer(data);

}

Thanks in advance!