Skip to content Skip to sidebar Skip to footer

How To Transfer Pictures From Android Device To Matlab And Vice-versa

I am in trouble and need your help. I am currently working on a project which requires me to first capture a natural scene(picture) using an android device, extract text and then r

Solution 1:

You might be able to use client/server sockets. I haven't tried this on Android, but I assume it would work as long as you have internet access. Matlab client-server and Java client-server should be compatible, in that you should be able to run a server in Matlab and connect to it from a Java client on android. The Matlab server could look like:

tcpipServer = tcpip('0.0.0.0',port,'NetworkRole','Server');
fopen(tcpipServer);
imageSize = fread(tcpipServer, 2, 'int32');
image = zeros(imageSize(1), imageSize(2), 3);
for x=1:imageSize(1)
  for y=1:imageSize(2)
    image(x, y, :) = fread(tcpipServer, 3, 'double');
  endend
%Process image
fwrite(tcpipServer, results, 'double'); %or'char'

And the Java client could be something like:

Socket s = new Socket(<Server IP>, port);
out = new PrintWriter(s.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));

out.println(image.getWidth());
out.println(image.getHeight());
for (int x = 1; x < image.getWidth(); x++) {
  for (int y = 1; y < image.getHeight(); y++) {
    //Write the RGB values. I can't remember how to pull these out of the image.
  }
}

String results = in.readLine();

I'm not exactly sure how things will work with datatypes. Maybe something other than PrintWriter would be better, or you might have to send everything as char[] and then parse it at the other end.

Post a Comment for "How To Transfer Pictures From Android Device To Matlab And Vice-versa"