First time here? Check out the FAQ!

Ask Your Question
0

How could I transfer Mat data from Windows Application to Android application?

asked Apr 10 '13

adrian gravatar image

1 down vote favorite 1

I want to transfer a Mat image through tcp ip sockets from an Android device to a PC running Windows. Android application is made in Java and Windows application is made in C++; both are using OpenCV.

More exactly, I would like to transfer the data from Mat image, but I couldn't find the equivalent of 'data' class member from Windows OpenCV for Android OpenCV.

Any ideas?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
0

answered Apr 10 '13

berak gravatar image

i'd suggest, you imencode your image to png/jpg, something compressed, and send that buffer via tcp to your pc-client.

there, you can easily retrieve it via VideoCapture::open(url) (url should end in .jpg or .png, so they can retrieve the filetype from it) maybe it even needs a proper http header in front, haven't tested that

Preview: (hide)

Comments

it's much simpler to use imdecode on the client side

Andrey Pavlenko gravatar imageAndrey Pavlenko (Apr 11 '13)edit

I have implemented with 'imencode' and 'imdecode' functions, but the result is an image which I can't open it...

This is my code for the client application (Android - OpenCV): MatOfByte buf = new MatOfByte(); Highgui.imencode(".jpg", matCameraBitmap, buf);

byte[] bufferByte; bufferByte = buf.toArray(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); out.write(bufferByte.toString()); out.flush();

And this is my code for the server application (Windows - OpenCV): if((bytecount = recv(new_sock, buffer, dim_imagine, 0)) == SOCKET_ERROR) { fprintf(stderr, "Error receiving data %d\n", WSAGetLastError()); return 0; }

std::vector<char> data(buffer, buffer + bytecount); Mat matrixJprg = imdecode(Mat(data), 1); cv::imwrite("aaa.jpg", matrixJprg);

adrian gravatar imageadrian (Apr 12 '13)edit
  1. your packets will get fragmentated, so you can't read it all in one go, but have to read like 8k blocks until you reach the total number of bytes

  2. i got no idea about andoid api, but out.write(bufferByte.toString()); looks suspect. strings are null terminated, this might truncate it on the sender size

  3. Wireshark is my weapon of choice to debug it

berak gravatar imageberak (Apr 12 '13)edit

Thanks for your help, problem solved!

adrian gravatar imageadrian (Apr 17 '13)edit

Question Tools

Stats

Asked: Apr 10 '13

Seen: 1,675 times

Last updated: Apr 10 '13