Ask Your Question

convert Mat CV_8UC4 to byte[] Android

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

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.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

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

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<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


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 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 -0500 )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 -0500 )edit
Login/Signup to Answer

Question Tools


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

Seen: 1,868 times

Last updated: Apr 07 '13