Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Mat from byte-array (or stream) - which type/format?

In my Android app I'm streaming images (all of same size) over the network to the Android device. Usually the stream is then decoded into a Bitmap like this:

            Bitmap bmp = BitmapFactory.decodeByteArray(buffer, 0,
                    buffer.length);

But this allocated and de-allocates memory all the time. Therefore I would prefer creating an OpenCV Mat and put the received buffer (byte[]) into that. But I just get a white-noise image because my image format seems wrong. Maybe you can help me? On the senders side (.NET C#) it's a PNG with 24bppRgb. On the receivers side (Android) I'm currently initializing the Mat like this:

            Mat mat = new Mat(new Size(width, height), CvType.CV_8U); mat.put(0, 0, buffer);

Mat from byte-array (or stream) - which type/format?

In my Android app I'm streaming images (all of same size) over the network to the Android device. Usually the stream is then decoded into a Bitmap like this:

            Bitmap bmp = BitmapFactory.decodeByteArray(buffer, 0,
                    buffer.length);

But this allocated and de-allocates memory all the time. Therefore I would prefer creating an OpenCV Mat and put the received buffer (byte[]) into that. But I just get a white-noise image because my image format seems wrong. Maybe you can help me? On the senders side (.NET C#) it's a PNG with 24bppRgb. On the receivers side (Android) I'm currently initializing the Mat like this:

            Mat mat = new Mat(new Size(width, height), CvType.CV_8U);  mat.put(0, 0, buffer);
click to hide/show revision 3
retagged

updated 2014-02-25 02:01:41 -0600

berak gravatar image

Mat from byte-array (or stream) - which type/format?

In my Android app I'm streaming images (all of same size) over the network to the Android device. Usually the stream is then decoded into a Bitmap like this:

            Bitmap bmp = BitmapFactory.decodeByteArray(buffer, 0,
                    buffer.length);

But this allocated and de-allocates memory all the time. Therefore I would prefer creating an OpenCV Mat and put the received buffer (byte[]) into that. But I just get a white-noise image because my image format seems wrong. Maybe you can help me? On the senders side (.NET C#) it's a PNG with 24bppRgb. On the receivers side (Android) I'm currently initializing the Mat like this:

            Mat mat = new Mat(new Size(width, height), CvType.CV_8U);                               
            mat.put(0, 0, buffer);