Ask Your Question
0

convert Mat CV_8UC4 to byte[] Android

asked 2013-04-07 10:47:57 -0600

Marwen Z gravatar image

Hi i try to convert a Mat to Byte then the inverse so here is the code

 frame = new Mat(height, width, CvType.CV_8UC4);
        // traitement ...
         byte[] data = = new byte[(int) (frame.total() *  frame.channels())];
            frame.get(0, 0, data); 
        // but data.length=0
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-04-07 12:25:32 -0600

What you have to do is store your frame in a Mat element and loop over it using the at functor. This will need the following code

Mat frame;
// To get data
frame.at<uchar>(i,j)

Also, please try to put more clear questions ... your question should not be found inside sample code.

edit flag offensive delete link more

Comments

from a mRgba i want to convert it to a byte array because i want to store it in DB (ormlite) i follow this but don't work http://answers.opencv.org/question/2847/convert-mat-to-matofbyte-in-android/ yes but why ? i didn't inderstand what you mean , i want just to convert a Mat (CV_8UC4) to byte array

Marwen Z gravatar imageMarwen Z ( 2013-04-07 12:36:02 -0600 )edit

Actually it is quite normal that your algorithm doesnt work. You are creating the Mat storage object, reserving memory, but there is no assignment, no placing of data in the Mat. Create a Mat of zero's for testing purposes using :

  frame = new Mat::zeros(height, width, CvType.CV_8UC4)
StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-07 13:16:37 -0600 )edit

Question Tools

Stats

Asked: 2013-04-07 10:47:57 -0600

Seen: 2,408 times

Last updated: Apr 07 '13