A Ruby script that builds an Xcode project and a universal iOS static library framework for the openalpr library. As of this writing, this project is compatible with the 2.2.x release of OpenALPR and later.
Running the script will:
As of this writing, the latest openalpr commit on the master branch was eecd41e097534f84e2669da24d4aed4bf75a1132
Clone this module:
# git clone git@github.com:twelve17/openalpr-ios.git
Install dependencies: bundle install
If running Homebrew, unlink existing installs of leptonica and tesseract, as the OpenALPR library will use those instead, which we don't want: brew unlink leptonica tesseract
. You can run brew link
to re-link them after the install is done.
Run bundle exec ./bin/build_frameworks.rb
. By default, it will put all the frameworks under a subdirectory called output
. You can pass an alternate path with the -d
option. Intermediate files are kept under the work
subdirectory, including a log called build.log
which you can inspect for errors.
Because the OpenCV binary framework release is compiled without bitcode, the other frameworks built by this script are also built without it, which ultimately means your Xcode project also cannot be built with bitcode enabled. Per this message, it sounds like we want this feature disabled for OpenCV anyway.
To disable bitcode in your project:
Build Settings
→ Build Options
, search for Enable Bitcode
and set it to No
. Add Files
and add all four frameworks (leptonica, opencv, tesseract, openalpr) from the output
directory. Use the Copy items if needed
option. This should cause the project to add a framework search path to the project's build settings (e.g. $(PROJECT_DIR)
). Link Binary With Libraries
build phase.openalpr.conf
) and a data folder (runtime_data
), both of which are included in the framework, but must be copied to the application resources:
Targets
→ <Your Project>
→ Build Phases
→ Copy Bundle Resources
, and click on the +
. Add Other...
openalpr.framework
bundle, and command-select both runtime_data
and openalpr.conf
. Unselect Copy items if needed
and select Create folder references
.You can use the AlprSample
app included in this project to test your installation. It has one view that simply presents a fixed (pre-selected) license plate image, and a table view below it showing scanned plate values for that image.
To run the app, you will need to build the frameworks with build_frameworks.rb
. Then, in Xcode, open the project and follow these steps:
ViewController.mm
and change the value of plateFilename
to the name of the file you added in step 1, e.g. NSString *plateFilename = @"license_plate.jpg";
I initially attempted to build dynamic libraries, since they are supported as of iOS 9. It required me to update the rpath
of the dynamic libraries. Then the frameworks must be embedded into the application. However, even after doing that, I ran into odd run-time errors where the libopenalpr.dylib library could not load the statedetection library. PRs welcome!
Steps for creating the app are kept here for posterity.
iOS
→ Application
→ Single View Application
AlprSample
ViewController.h
and ViewController.m
class. Rename the .m
class to ViewController.mm
(two m's). This causes Xcode to compile the class as "Objective-C++", which we need, as the openalpr code is in C++.nm -gUj openalpr.framework/Libraries/libopenalpr-static.a | c++filt
tail -f ~/Library/Logs/CoreSimulator/*.log
clean up temporary Xcode items
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Caches/com.apple.dt.Xcode