0

I am currently involved in a project where we performed some computer vision object recognition and classification using python. It is necessary to use photos taken from an Android phone (photos should be automatically sent from android to python). I actually don't know how should I connect both applications (android and python) together. I thought of using TCP Server, but I am new to socket programming and don't know how and where to start.

Any one can help?

jnovacho
  • 2,825
  • 6
  • 27
  • 44
user2229953
  • 1,569
  • 3
  • 16
  • 24

2 Answers2

0

Android gives you options to connect via HTTP.

http://developer.android.com/guide/topics/connectivity/index.html

So I would probably go with a REST type implementation

https://en.wikipedia.org/wiki/Representational_state_transfer

http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Here is a tutorial for Android and REST

http://www.majidkhosravi.com/android-rest/

But you are dealing with pictures. Here is a SO talking about that.

POSTing image from Android to WCF Rest Service

On the Python side you have multiple choices, but the main ones I would consider:

Twisted (or maybe Tornado) if you want Asynch.

http://twistedmatrix.com/trac/wiki/WebDevelopmentWithTwisted

http://zenmachine.wordpress.com/web-services-and-twisted/

Flask for Synch.

http://flask-restful.readthedocs.org/en/latest/quickstart.html

Maybe Nginx/Apache + Django

http://django-rest-framework.org/

SO post about Python and REST

Recommendations of Python REST (web services) framework?

If you want to implement this at the socket level, this book would be a great resource:

http://www.amazon.com/Foundations-Python-Network-Programming-Goerzen/dp/1590593715

Hope this helps provide you some directions to explore.

Community
  • 1
  • 1
poof
  • 69
  • 5
0

poof's answer is a good overview, but here are some notes on the various options:

Option 1: Have your Android get the picture and do a HTTP POST to a Python application running a framework such as Django. It should be 1 line of code on Android, and only a few lines of code on Python (around your existing code).

The upside is that the low-level "Glue" is written for you, and it scales easily. The downside is that HTTP has some overhead.

Option 2: Have your Android talk a custom TCP protocol to a custom TCP application.

This is more work, so you should avoid it unless you need it. It will be more efficient and have lower latency, especially if you're sending multiple pictures. The response can also be much smaller without HTTP headers.

In either option, you don't have to send a JPEG, you could send any custom format you want (there is a trade-off between compression on Android and size of file).

I thought of using TCP Server, but I am new to socket programming and don't know how and where to start.

Start where everyone else started - by reading a lot and playing a lot. You can find plenty of introductions to Socket programming in Python on the web. Go thru the tutorials, and start modifying them to see how they work. Read up on TCP/IP itself -- there are a lot of dark corners (Nagel, fragmentation, slow start) that can affect how you write the app when you get to a low level.

BraveNewCurrency
  • 12,654
  • 2
  • 42
  • 50