Ask Your Question

Tal's profile - activity

2015-01-10 09:21:10 -0600 received badge  Editor (source)
2015-01-09 09:57:04 -0600 asked a question Convert Mat OpenCV to BGR8 Byte Array or ROS message at Android Java


I want to able convert efficiently from opencv Mat to ROS Image Sensor.
There is efficient way to do it with CvBridge:
Using CvBridge To Convert Between ROS Images And OpenCV Images
Unfortunately, there is no CvBridge impliment on OpenCV Android Java.

Also, if you don't know what is ROS Image, it ok,
you can help me by converting Mat openv image to BGR8 byte Array. (or RGBA8 byte array) efficiently.
This way it was say it wrong format, and out of memory exception:
Mat to rgba8
can you do it better?

Thanks for the help. Tal.


I am using this code: But it throw me java.lang.OutOfMemoryError.
refence from this:
Mat to rgba8

Bitmap bmp = Bitmap.createBitmap(cols, rows, Bitmap.Config.ARGB_8888);
Utils.matToBitmap(frame, bmp);

Image rawImage = rawImagePublisher.newMessage();
rawImage.getHeader().setStamp(currentTime);
rawImage.getHeader().setFrameId("camera");
rawImage.setEncoding("rgba8");
rawImage.setWidth(bmp.getWidth());
rawImage.setHeight(bmp.getHeight());
rawImage.setStep(bmp.getRowBytes());

ByteBuffer bb = ByteBuffer.allocate(bmp.getRowBytes() * bmp.getHeight());

bmp.copyPixelsToBuffer(bb);
stream.write(bb.array());
rawImage.setData(stream.buffer().copy());
rawImagePublisher.publish(rawImage);

can you help me? Thanks.