2

I have a Bitmap image that I want to send using the Socket class. The Bitmap needs to be sent from the Android client to a server. The server is a C++ program. How do I this?

I was looking at Android's Bitmap class here. But it doesn't really talk about it.

Also how do I decode this Bitmap on the server side? The server is running a OpenCV program and I need to interpret the Bitmap as an IplImage (IplImage is an OpenCV struct that represents an image). If I have a image buffer, I can set IplImage to point to this buffer.

user1210233
  • 2,730
  • 5
  • 24
  • 31
  • 1
    Related: http://stackoverflow.com/questions/649154/save-bitmap-to-location. If you can save bitmap to a file, you can send bitmap to socket. Just change `FileOutputStream` to `Socket.getOutputStream()` or the stream you have. – johnchen902 Jul 21 '13 at 03:16
  • 2
    And then on Server side, use `imdecode` or `imread` to turn `png` to `Mat`. The turn `Mat` to `IplImage` by: http://stackoverflow.com/questions/4664187/converting-cvmat-to-iplimage. – johnchen902 Jul 21 '13 at 03:33

1 Answers1

1

It would be more efficient to send JPEG(or PNG) version of this bitmap as a byte[] to the server.

On the server side you can easily decode this byte array to OpenCV IplImage or Mat.

RomanI
  • 403
  • 4
  • 7
  • Is there a OpenCV function to read bytes and convert from JPEG to IplImage or Mat? – Cricketer Jul 21 '13 at 03:26
  • @johnchen902 gave the correct answer above: you need to use either `imread` or `imdecode`. It returns `Mat`, but you can easily convert it to `IplImage`. `IplImage lpl = mat;`. – RomanI Jul 21 '13 at 03:40