3

I created a license plate detection program with Python using OpenCv, the program takes in a picture of a license plate and it returns its numbers/letters. I wanted to incorporate my Python program into an iOS app using Swift. Is there a way I can provide an image from Swift and call the python script and get the returned value of the license plate?

Basically is there a way I can call python scripts from Swift?

Thanks

(I know I can translate the code over to C++ and create a bridge to Swift but I am not very familiar with C++)

3
  • 1
    Do you want all of the code for your app on their phone? Or are you open to setting up a python RESTFUL api on a server to do the computation? Commented Oct 25, 2017 at 23:20
  • 1
    I was thinking REST api at first but the app has to be offline @PeterH Commented Oct 25, 2017 at 23:41
  • 1
    Ah. Yeah. I am not sure how computationally heavy your IR is, but if it takes a little while on a computer your best bet would probably get to rewrite your python code in c++ and port that into the swift app. Running the IR in c++ could save you a lot of overhead (Having the python interpreter running on the IOS device) and should be a lot faster and more efficient than the code written in Python. On the flip side writing good, stable, fast code in c++ is a lot harder than in a lot of other languages. But if you do have time to learn c++ it will change the way you program (in a good way). Commented Oct 26, 2017 at 0:07

1 Answer 1

1

You have not only to "call Python from swift", but to make it on the client, you have to embedd all the Python runtime and the OpenCV library with your application, run the Python app in a different application, and then work on making this call - which will be an interprocess call. Unless you can, from swift, instantiate an internal Python interpreter in native code (which is possible from C/C++ code, but I am not sure if it can done from Swift) - then you are spared from the separate process, but still will need to bundle everything.

However, if you can afford for the Python app to be run server side, then it should be trivial: you can use a microframework (like Flask), for example, to wrap your app functionality into a simple view. Your app would them just make an HTTP post request, send the image, and get the resulting text as a response.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.