Ask Your Question
0

Why does the image break when converted to byte[]? (takePicture with Opencv on Android)

asked 2013-06-20 01:49:50 -0500

atasoyh gravatar image

updated 2013-09-16 13:10:17 -0500

berak gravatar image

I have an project that used Camera and Opencv. I take picture and crop image with OpenCv. After I have a Mat file to convert Jpeg for send byte[] data to Activity.

Mat to Bitmap

bmp2 = Bitmap.createBitmap(checkFrame.cols(),checkFrame.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(checkFrame, bmp2, true);
checkFrame.release();

Bitmap to byte[]

ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
bmp2.compress(Bitmap.CompressFormat.JPEG, 0,stream2);
bmp2.recycle();
bmp2 = null;
byte[] byteArray2 = stream2.toByteArray();

On Activity ,

((ImageView) findViewById(R.id.photoView))
                                .setImageBitmap(BitmapFactory
                                        .decodeByteArray(photo2, 0,
                                                photo2.length));

But this image is not same with I cropped. This is like 16bit color... If I direct send Bitmap to activity and set ImageBitmap, this is good. Why does the image break when it's converted to byte[]?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-09-16 07:48:09 -0500

updated 2013-09-16 08:00:15 -0500

This is not Opencv way to do it ?!

Mat onCameraFrame(CvCameraViewFrame inputFrame) {
Rgba = inputFrame.rgba();
.
. Do your work
.
return Rgba;
}

And

<org.opencv.android.JavaCameraView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:adjustViewBounds="true"
        android:gravity="center_vertical"
        android:id="@+id/java_surface_view" />

in your layout

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2013-06-20 01:49:50 -0500

Seen: 426 times

Last updated: Sep 16 '13