From 1763353e00a4e374d35f2c7cfd6646714abe209b Mon Sep 17 00:00:00 2001 From: Moe Date: Tue, 8 Jan 2019 15:27:28 -0800 Subject: [PATCH] Update OpenALPR README and add Plugin Installer + Update OpenALPR installer to check for OpenCV --- INSTALL/openalpr-cpu-easy.sh | 41 ++++++++++++++++++ INSTALL/openalpr-gpu-easy.sh | 12 +++++- plugins/openalpr/INSTALL.sh | 53 +++++++++++++++++++++++ plugins/openalpr/README.md | 63 ++++++++++------------------ plugins/openalpr/package.json | 1 - plugins/openalpr/shinobi-openalpr.js | 4 +- 6 files changed, 131 insertions(+), 43 deletions(-) create mode 100644 INSTALL/openalpr-cpu-easy.sh create mode 100644 plugins/openalpr/INSTALL.sh diff --git a/INSTALL/openalpr-cpu-easy.sh b/INSTALL/openalpr-cpu-easy.sh new file mode 100644 index 00000000..56e54b72 --- /dev/null +++ b/INSTALL/openalpr-cpu-easy.sh @@ -0,0 +1,41 @@ +# Install prerequisites +DIR=`dirname $0` +INSTALLERS_DIR="$DIR" +echo "-----------------------------------" +if ! [ -x "$(command -v opencv_version)" ]; then + echo "Installing OpenCV" + dos2unix $INSTALLERS_DIR/opencv-cuda.sh + sh $INSTALLERS_DIR/opencv-cuda.sh +else + echo "OpenCV found... : $(opencv_version)" +fi +# this includes all the ones missing from OpenALPR's guide. +sudo apt install libtesseract-dev git cmake build-essential libleptonica-dev -y +sudo apt install liblog4cplus-dev libcurl3-dev -y +sudo apt install libleptonica-dev -y +sudo apt install libcurl4-openssl-dev -y +sudo apt install liblog4cplus-dev -y +sudo apt install beanstalkd -y +sudo apt install openjdk-8-jdk -y + +# Clone the latest code from GitHub +git clone https://github.com/openalpr/openalpr.git + +# Setup the build directory +cd openalpr/src +mkdir build +cd build + +# setup the compile environment +cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc .. + +# compile the library +make + +# Install the binaries/libraries to your local system (prefix is /usr) +sudo make install + +# Test the library +wget http://plates.openalpr.com/h786poj.jpg -O lp.jpg +alpr lp.jpg +rm lp.jpg diff --git a/INSTALL/openalpr-gpu-easy.sh b/INSTALL/openalpr-gpu-easy.sh index 09496295..f78e3615 100644 --- a/INSTALL/openalpr-gpu-easy.sh +++ b/INSTALL/openalpr-gpu-easy.sh @@ -1,4 +1,14 @@ # Install prerequisites +DIR=`dirname $0` +INSTALLERS_DIR="$DIR" +echo "-----------------------------------" +if ! [ -x "$(command -v opencv_version)" ]; then + echo "Installing OpenCV" + dos2unix $INSTALLERS_DIR/opencv-cuda.sh + sh $INSTALLERS_DIR/opencv-cuda.sh +else + echo "OpenCV found... : $(opencv_version)" +fi # this includes all the ones missing from OpenALPR's guide. sudo apt install libtesseract-dev git cmake build-essential libleptonica-dev -y sudo apt install liblog4cplus-dev libcurl3-dev -y @@ -28,4 +38,4 @@ sudo make install # Test the library wget http://plates.openalpr.com/h786poj.jpg -O lp.jpg alpr lp.jpg -rm lp.jpg \ No newline at end of file +rm lp.jpg diff --git a/plugins/openalpr/INSTALL.sh b/plugins/openalpr/INSTALL.sh new file mode 100644 index 00000000..6fe455d5 --- /dev/null +++ b/plugins/openalpr/INSTALL.sh @@ -0,0 +1,53 @@ +DIR=`dirname $0` +INSTALLERS_DIR="$DIR/../../INSTALL" +if ! [ -x "$(command -v dos2unix)" ]; then + echo "-----------------------------------" + echo "Installing dos2unix" + apt install dos2unix -y +fi +echo "-----------------------------------" +if ! [ -x "$(command -v alpr)" ]; then + echo "Installing OpenALPR" + echo "Do you want to Install OpenALPR with CUDA enabled?" + echo "(Y)es or (n)o?" + echo "Press [ENTER] for default (Yes)" + read openalprcudaenabled + if [ "$openalprcudaenabled" = "n" ] || [ "$openalprcudaenabled" = "N" ]; then + sed -i -e 's/detector = lbpgpu/detector = lbpcpu/g' "$DIR/openalpr.conf" + dos2unix $INSTALLERS_DIR/openalpr-cpu-easy.sh + sh $INSTALLERS_DIR/openalpr-cpu-easy.sh + else + sed -i -e 's/detector = lbpcpu/detector = lbpgpu/g' "$DIR/openalpr.conf" + dos2unix $INSTALLERS_DIR/openalpr-gpu-easy.sh + sh $INSTALLERS_DIR/openalpr-gpu-easy.sh + fi +else + echo "OpenALPR found... : $(alpr --version)" +fi +echo "-----------------------------------" +if [ ! -e "$DIR/conf.json" ]; then + echo "Creating conf.json" + cp $DIR/conf.sample.json $DIR/conf.json +else + echo "conf.json already exists..." +fi +echo "-----------------------------------" +echo "Installing Modules.." +npm install --unsafe-perm +echo "Finding and Fixing Module Vulnerabilities.." +npm audit fix --force +echo "Shinobi - Do you want to start the plugin?" +echo "(Y)es or (n)o?" +echo "Press [ENTER] for default (Yes)" +read startplugin +if [ "$startplugin" = "n" ] || [ "$startplugin" = "N" ]; then + echo "-----------------------------------" + echo "Start the plugin with pm2 like so :" + echo "pm2 start $DIR/shinobi-openalpr.js" + echo "-----------------------------------" + echo "Start the plugin without pm2 :" + echo "node $DIR/shinobi-openalpr.js" +else + pm2 start shinobi-openalpr.js + pm2 save +fi diff --git a/plugins/openalpr/README.md b/plugins/openalpr/README.md index 44beac78..4e353f25 100644 --- a/plugins/openalpr/README.md +++ b/plugins/openalpr/README.md @@ -1,49 +1,32 @@ -# OpenALPR and Motion Detector +# OpenALPR Install required libraries. -**Ubuntu and Debian only** +**Ubuntu 17.10 and 18.04 only** -``` -sudo apt update && sudo apt install libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev build-essential g++ openalpr openalpr-daemon openalpr-utils libopenalpr-dev -y -``` +> By default plugins run as a client. `camera.js` is running as the host awaiting a plugin to connect to it. To learn about how to connect a plugin as a Host please review the "Run the plugin as a Host" section at the end of this README. -**Install the Node.js Canvas engine** +1. Go to the plugin's directory and run the installer for OpenALPR. **/home/Shinobi** is the default directory for where Shinobi is installed. + ``` + cd /home/Shinobi/plugins/openalpr + sh INSTALL.sh + ``` -``` -sudo npm install canvas@1.6 -``` -Go to the Shinobi directory. **Below is an example.** +2. Then add the plugin key to the **Main Configuration** file, the `conf.json` located in **/home/Shinobi**. You will find the `pluginKeys` object empty on a new install as seen below. + ``` + "pluginKeys":{} + ``` + > Add the key so it looks something like this. -``` -cd /home/Shinobi -``` + ``` + "pluginKeys":{ + "OpenALPR": "SomeOpenALPRkeySoPeopleDontMessWithYourShinobi" + } + ``` -Copy the config file. +3. Restart Shinobi to apply the Plugin Key. Shinobi does not need to be restarted when a plugin is initiated or stopped after applying changes to the Main Configuration file. -``` -cp plugins/openalpr/conf.sample.json plugins/openalpr/conf.json -``` - -Edit it the new file. Host should be `localhost` and port should match the `listening port for camera.js`. - -``` -nano plugins/openalpr/conf.json -``` - -Start the plugin. - -``` -node plugins/openalpr/shinobi-openalpr.js -``` - -Or to daemonize with PM2. - -``` -pm2 start plugins/openalpr/shinobi-openalpr.js -``` - -Doing this will reveal options in the monitor configuration. Shinobi does not need to be restarted when a plugin is initiated or stopped. +> You should change `SomeOpenALPRkeySoPeopleDontMessWithYourShinobi` to something else in both the main configuration and plugin configuration. Both files changed need to be matching keys of course. ## Run the plugin as a Host > The main app (Shinobi) will be the client and the plugin will be the host. The purpose of allowing this method is so that you can use one plugin for multiple Shinobi instances. Allowing you to easily manage connections without starting multiple processes. @@ -51,7 +34,7 @@ Doing this will reveal options in the monitor configuration. Shinobi does not ne Edit your plugins configuration file. Set the `hostPort` **to be different** than the `listening port for camera.js`. ``` -nano plugins/openalpr/conf.json +nano conf.json ``` Here is a sample of a Host configuration for the plugin. @@ -70,7 +53,7 @@ Here is a sample of a Host configuration for the plugin. } ``` -Now modify the **main configuration file** located in the main directory of Shinobi. *Where you currently should be.* +Now modify the **Main Configuration** file located in the main directory of Shinobi. *Where you currently should be.* ``` nano conf.json @@ -90,4 +73,4 @@ Add the `plugins` array if you don't already have it. Add the following *object "type" : "detector" } ], -``` \ No newline at end of file +``` diff --git a/plugins/openalpr/package.json b/plugins/openalpr/package.json index 7f6d5aa0..ed0b314e 100644 --- a/plugins/openalpr/package.json +++ b/plugins/openalpr/package.json @@ -4,7 +4,6 @@ "description": "OpenALPR plugin for Shinobi", "main": "shinobi-openalpr.js", "dependencies": { - "canvas": "^1.6.7", "express": "^4.16.2", "moment": "^2.19.2", "socket.io": "^2.0.4" diff --git a/plugins/openalpr/shinobi-openalpr.js b/plugins/openalpr/shinobi-openalpr.js index d74bd87d..76a9f40e 100644 --- a/plugins/openalpr/shinobi-openalpr.js +++ b/plugins/openalpr/shinobi-openalpr.js @@ -26,7 +26,9 @@ try{ } // Base Init />> // OpenALPR Init >> -if(config.alprConfig===undefined){config.alprConfig=__dirname+'/openalpr.conf'} +if(config.alprConfig === undefined){ + config.alprConfig = __dirname + '/openalpr.conf' +} // OpenALPR Init />> s.detectObject = function(buffer,d,tx,frameLocation){ var detectStuff = function(frame){