How to transfer pictures from android device to Ma

2019-02-20 15:39发布

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 recognize the text.

I have already achieved the process of extraction and recognizing through Matlab. Now my problem is, how can i transfer a picture which is captured from my android cell phone to MATLAB? How to send the results back to the phone after processing the image?

Please help. A code will be appreciated.

1条回答
ら.Afraid
2楼-- · 2019-02-20 16:40

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');
  end
end
%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.

查看更多
登录 后发表回答