Skip to content
Open

. #23

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'
gem 'osx-plist', '~> 1.0'
gem 'logger', '~> 1.2'
#gem 'pry-byebug', '~> 3.3'
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
GEM
remote: https://rubygems.org/
specs:
logger (1.2.8)
osx-plist (1.0.3)

PLATFORMS
ruby

DEPENDENCIES
logger (~> 1.2)
osx-plist (~> 1.0)

BUNDLED WITH
1.10.6
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ A Ruby script that builds an Xcode project and a universal iOS static library fr

Running the script will:

- Download the OpenCV 3.0.0 framework binary release and symlink the headers diretory so that the OpenALPR code will see them.
- Download the OpenCV 3.0.0 framework binary release and symlink the headers directory so that the OpenALPR code will see them.
- Download and build universal Tesseract 3.03, Leptonica 1.71, and OpenALPR static library framework bundles from source.
- Generate a OpenALPR Xcode project

## Requirements

- Mac OS X
- Ruby 2.1.x
- [osx-plist](https://github.com/kballard/osx-plist) Ruby gem
- Ruby *2.1*.x, bundler
- Xcode and command line tools. Tested with Xcode 7.1.
- curl (seems to be installed by default on OS X)
- git
- curl, tar, unzip, git (seems to be installed by default on OS X)
- cmake (<a href="http://brewformulas.org/Cmake" target="_blank">homebrew</a> | <a href="https://cmake.org/install/" target="_blank">source</a>)
- autoconf (<a href="http://brewformulas.org/autoconf" target="_blank">homebrew</a> | <a href="http://www.gnu.org/software/autoconf/autoconf.html" target="_blank">source</a>)

As of this writing, the latest openalpr commit on the master branch was `eecd41e097534f84e2669da24d4aed4bf75a1132`

Expand All @@ -28,13 +28,15 @@ As of this writing, the latest openalpr commit on the master branch was `eecd41e
# git clone git@github.com:twelve17/openalpr-ios.git
```

- Run the `./bin/build_frameworks.rb` script. 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.
- 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.

## Usage

### Bitcode

Because the opencv2 binary 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](http://stackoverflow.com/a/32728516/868173), it sounds like we want this feature disabled for OpenCV anyway.
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](http://stackoverflow.com/a/32728516/868173), it sounds like we want this feature disabled for OpenCV anyway.

To disable bitcode in your project:

Expand All @@ -51,13 +53,14 @@ To disable bitcode in your project:

## AlprSample App

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 place image, and a table view below it showing scanned plate values for that image.
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:

1. Find a plate image file you wish to test with and add it to the project.
2. Edit `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";`
3. Link the project to the dependency frameworks and add the required resources per the "Linking To Frameworks" section above.
4. Run the app! The library should work in a simulator.

## Misc Notes

Expand All @@ -81,7 +84,7 @@ Steps for creating the app are kept here for posterity.
- [Viewing iOS device logs](http://stackoverflow.com/a/31379741/868173)
- Viewing symbols in library:
`nm -gUj openalpr.framework/Libraries/libopenalpr-static.a | c++filt`
- [Seeing errors in Simulator](http://stackoverflow.com/a/26129829/868173):
- [Inspecting the Simulator logs](http://stackoverflow.com/a/26129829/868173):
`tail -f ~/Library/Logs/CoreSimulator/*.log`
- clean up temporary Xcode items

Expand Down
24 changes: 23 additions & 1 deletion bin/build_frameworks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,29 @@

# Tested on Ruby 2.1.2

require 'pry-byebug'
#-----------------------------------------------------------------------------
# Check ruby version before requiring alpr libs, which use 2.1.x named params.
#-----------------------------------------------------------------------------
def ruby_version_new_enough?
ruby_v = RUBY_VERSION.split('.').map(&:to_i)
ruby_v[0] >= 2 && ruby_v[1] >= 1
end

def check_deps
if !ruby_version_new_enough?
raise "Ruby 2.1.x or later is required. You have: #{RUBY_VERSION}."
end
%w{cmake autoconf}.each do |prog|
`which -s #{prog}`
unless $?.success?
raise "Dependency '#{prog}' is missing. Please install it and try again. See the README.md for details."
end
end
end

check_deps
#-----------------------------------------------------------------------------

require 'optparse'
require 'logger'
require_relative '../lib/alpr/package'
Expand Down
123 changes: 0 additions & 123 deletions etc/cmake/OpenALPR_CMakeLists.txt.patch

This file was deleted.

20 changes: 2 additions & 18 deletions etc/cmake/Toolchains/iOS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -193,39 +193,23 @@ set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

################### Start OpenALPR customizations ######################

# TODO: move to IOS specific block instead of opencv specific
# http://stackoverflow.com/questions/822404/how-to-set-up-cmake-to-build-an-app-for-the-iphone
# "so that the product type generated would be com.apple.product-type.application instead of com.apple.product-type.tool"
set(CMAKE_MACOSX_BUNDLE YES)

#SET(CMAKE_EXE_LINKER_FLAGS "-framework CoreGraphics -framework QuartzCore -framework AssetsLibrary -framework CoreVideo -framework AVFoundation -framework CoreMedia -framework Foundation -framework UIKit -framework ImageIO")
#SET(CMAKE_EXE_LINKER_FLAGS "-framework UIKit -framework ImageIO")

#FIND_LIBRARY(IMAGE_IO_LIB ImageIO)
#FIND_LIBRARY(UI_KIT_LIB UIKit)
#FIND_LIBRARY(FOUNDATION_LIB Foundation)
#FIND_LIBRARY(AV_FOUNDATION_LIB AVFoundation)
#FIND_LIBRARY(CORE_MEDIA_LIB CoreMedia)
#FIND_LIBRARY(CORE_VIDEO_LIB CoreVideo)
#FIND_LIBRARY(ASSETS_LIB AssetsLibrary)
#FIND_LIBRARY(QUARTZ_CORE_LIB QuartzCore)
#FIND_LIBRARY(CORE_GRAPHICS_LIB CoreGraphics)
#MARK_AS_ADVANCED(CORE_GRAPHICS_LIB)
#SET(Extra_LIBS ${CORE_GRAPHICS_LIB})

# https://public.kitware.com/Bug/view.php?id=15329
message(STATUS "Disabling code signing for ALPR iOS framework")
SET(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
SET(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Don't Code Sign")

SET(CMAKE_INSTALL_PREFIX install)
SET(WITH_DAEMON OFF)
SET(WITH_UTILITIES OFF)
SET(WITH_BINDING_JAVA OFF)
SET(WITH_BINDING_PYTHON OFF)
#SET(WITH_GPU_DETECTOR OFF)
SET(WITH_TESTS OFF)

SET(CMAKE_INSTALL_PREFIX install)

# These will be unused
SET(CMAKE_INSTALL_SYSCONFDIR "etc")
SET(CMAKE_INSTALL_VARDIR "var")
Expand Down
16 changes: 0 additions & 16 deletions lib/alpr/package/alpr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ def build_arch(target, arch)
self.merge_libfiles(self.target_libs, self.thin_lib_dir(target, arch), self.target_merged_lib)
end

def pre_build_setup
patch_cmakelists
end

def post_build_setup
install_resources
end
Expand Down Expand Up @@ -173,17 +169,5 @@ def cmake_build_dir
File.join(cmake_src_dir, 'build')
end

def patch_cmakelists
logger.info("patching CMakeLists")
common_args = "-d #{self.package_dir} -p1 -i #{CONFIG_DIR}/cmake/OpenALPR_CMakeLists.txt.patch"
output = `patch --silent --dry-run #{common_args}`
# file is not patched yet
if $?.success?
log_execute("patch #{common_args}")
else
logger.info("CMakeLists is already patched") # TODO: could be error too
end
end

end
end
9 changes: 6 additions & 3 deletions lib/alpr/package/tesseract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ def extra_libs_dir(target, arch)
File.join(self.leptonica_thin_lib_dir, "#{target}-#{arch}")
end

# Attempting to use the tesseract "LIBLEPT_HEADERSDIR"
def env_for_arch(target, arch, headers_dir, lib_dir)
super.merge('LIBLEPT_HEADERSDIR' => self.leptonica_headers_dir)
end

# Attempting to only use the tesseract "LIBLEPT_HEADERSDIR"
# was causing the tesseract build fail, as it was setting the
# -I flag to $LIBLEPT_HEADERSDIR/leptonica, which is incorrect
# (the sources reference lept headers relative to $LIBLEPT_HEADERSDIR)
# It seems that just explicitly including the leptonica headers
# via the -I flag does the trick.
# Looks like also including the headers via the -I flag does the trick.
def extra_headers_dir
self.leptonica_headers_dir
end
Expand Down