#!/bin/bash # STATUS A/O 2016 02 13: untested, indeterminate # based on https://barclaysapps.wordpress.com/2014/07/06/openalpr-install-for-rpi-and-udoo-and-tre-and-yun/ , # http://lukagabric.com/raspberry-pi-license-plate-recognition/, and updated for new packages. # there are other random notes and googled pages that also informed this tutorial whihc may not be specifically referenced. #This is not optimized for space or whatever, but does work. well, not as of 2016 01 03 but working to fix that) # discussion is at https://groups.google.com/forum/#!topic/openalpr/-vckIsPe618: please contribute if you can, and ask questions if you # # have them # thanks to Timis for tips and hints... # how to read: # this is a heading, as denoted by the: # on a line where you see some text -> some more text # this is the text in the original tutorial -> this is what you should type instead # note: this is a note: don't type this. # if you see a line like this ; or // anything after the ';' or the '//' including the ';' or '//' is a note and should not be typed # installed and tested on a raspberry pi 2 model B 1GB using raspbian installed via noobs on a 32 GB memory card. # note that an 8GB card will fill before this tutorial ends, so you will need a card bigger than that. # Not tested on a 16GB card so no idea if that will work or not. # download this tutorial: # wget https://gist.github.com/amstanley/9da7febc9a3e3c2228ee/archive/a670894f0c0162c3f2efdcd93e527c59628f6c90.zip # unzip 655ca8d3ca8eb17a3376123950de8445fb83a404.zip # make it executable (chmod +x filename) so it can run as a script and then run it. # when it is done resume manual entry at line 112. # Create a log file of the build as well as displaying the build on the tty as it runs exec > >(tee build_gstreamer.log) exec 2>&1 # Set Up the camera to stream mjpeg. to do this follow this tutorial exactly: # http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14 # the steps are: curl http://www.linux-projects.org/listing/uv4l_repo/lrkey.asc | sudo apt-key add - # Add the following line to the file /etc/apt/sources.list (type sudo nano /etc/apt/sources.list) : sudo -- sh -c "echo deb http://www.linux-projects.org/listing/uv4l_repo/raspbian/ wheezy main >> /etc/apt/sources.list" # Update and Upgrade the Pi, otherwise the build may fail due to inconsistencies sudo apt-get update && sudo apt-get upgrade -y --force-yes # Get the required libraries sudo apt-get install -y --force-yes autoconf build-essential automake libtool git cmake pkg-config \ libpng12-dev libjpeg-dev libtiff5-dev zlib1g-dev libjasper-dev \ libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \ libxvidcore-dev libx264-dev libgtk2.0-dev libatlas-base-dev \ gfortran python2.7-dev python3-dev \ libcurl4-openssl-dev liblog4cplus-1.0-4 liblog4cplus-dev uuid-dev \ uv4l uv4l-raspicam uv4l-raspicam-extras uv4l-server uv4l-mjpegstream \ gstreamer1.0 # Clone openalpr: cd /home/pi git clone https://github.com/openalpr/openalpr.git # Create a directory and download libraries: cd openalpr mkdir libraries cd libraries git clone https://github.com/tesseract-ocr/tesseract.git git clone https://github.com/tesseract-ocr/tessdata.git wget http://www.leptonica.org/source/leptonica-1.71.tar.gz # wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.11/opencv-2.4.11.zip # wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip # trying alternate versions as 2.4.11 fails to compile with ffmpeg. wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip # extract the packages: tar -zxvf leptonica-1.71.tar.gz # unzip opencv-2.4.9.zip unzip opencv.zip unzip opencv_contrib.zip # clean up the downloads rm leptonica-1.71.tar.gz # rm opencv-2.4.9.zip rm opencv.zip rm opencv_contrib.zip # compile leptonica: cd leptonica-1.71 ./configure make -j4 sudo make install # compile tesseract: cd ../tesseract sudo apt-get install -y --force-yes autoconf automake libtool ./autogen.sh # script crapped here, missing aclocal. ran sudo apt-get install -y --force-yes autoconf automake libtool, seemed to fix it. ./configure make -j4 sudo make install sudo ldconfig export TESSDATA_PREFIX=/home/pi/openalpr/libraries/tessdata # installing openCV 3 with Python 2.7 # see http://www.pyimagesearch.com/2015/10/26/how-to-install-opencv-3-on-raspbian-jessie/ # as referenced by timis at https://groups.google.com/d/topic/openalpr/-vckIsPe618 wget https://bootstrap.pypa.io/get-pip.py sudo python get-pip.py sudo pip install virtualenv virtualenvwrapper sudo rm -rf ~/.cache/pip echo 'export WORKON_HOME=$HOME/.virtualenvs' >> ~/.profile echo 'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.profile source ~/.profile mkvirtualenv cv source ~/.profile workon cv pip install numpy cd /home/pi/openalpr/libraries/opencv-3.1.0 mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=OFF \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_EXTRA_MODULES_PATH=/home/pi/openalpr/libraries/opencv_contrib-3.1.0/modules \ -D BUILD_EXAMPLES=ON .. make -j4 sudo make install sudo ldconfig cd ~/.virtualenvs/cv/lib/python2.7/site-packages/ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so # Compile openALPR: cd /home/pi/openalpr/src # nano CMakeLists.txt # add the following lines in the section near the top that has SET() statements # SET(OpenCV_DIR "/home/pi/openalpr/libraries/opencv-2.4.11/release") # SET(Tesseract_DIR "/home/pi/openalpr/libraries/tesseract") # do this using sed sed -i '11 i SET(Tesseract_DIR "/home/pi/openalpr/libraries/tesseract")' /home/pi/openalpr/src/CMakeLists.txt sed -i '11 i SET(OpenCV_DIR "~/openalpr/libraries/opencv-3.1.0/build")' /home/pi/openalpr/src/CMakeLists.txt cmake ./ make -j4 sudo make install sudo cp -r /usr/local/lib/* /lib # sudo cp /home/pi/openalpr/libraries/opencv-2.4.11/release/lib/* /lib # note: seems like this last step is just a path issue... surely better way to do this) # test the library (from https://github.com/openalpr/openalpr/wiki/Compilation-instructions-(Ubuntu-Linux)): wget http://plates.openalpr.com/ea7the.jpg alpr -c us ea7the.jpg # result: # plate0: 10 results # - EA7THE confidence: 92.4795 # - EA7TBE confidence: 84.0421 # - EA7TRE confidence: 83.1932 # - EA7TE confidence: 82.0527 # - EA7T8E confidence: 81.7845 # - EA7TME confidence: 80.8062 # - EA7THB confidence: 76.6468 # - EA7TH6 confidence: 76.6153 # - EA7TH confidence: 75.2232 # - EA7TBB confidence: 68.2095 # wget http://plates.openalpr.com/h786poj.jpg # alpr -c eu h786poj.jpg