JuangaCovas.info

La página personal de Juan Gabriel Covas

Herramientas de usuario

Herramientas del sitio


linux:howtos:centos:openalpr-compile-from-sources

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anteriorRevisión previa
Próxima revisión
Revisión previa
linux:howtos:centos:openalpr-compile-from-sources [21/08/2021 14:36] – [Step 5. Dependencies resolved, let's try to make] Juanga Covaslinux:howtos:centos:openalpr-compile-from-sources [13/01/2023 19:53] (actual) – [Too Long, Won't read] Juanga Covas
Línea 15: Línea 15:
  
 \\ \\
 +
 +===== Too Long, Won't read =====
 +
 +<wrap tip>If you're feeling lucky</wrap>, you could put all of this on a bash shell script and execute it, to see if you end up having the ''alpr'' command available to use.
 +
 +<code bash [enable_line_numbers="true"]>
 +# Installing OpenALPR from sources under CentOS 7
 +
 +# some "easy" pre-requisites to be able to compile OpenALPR
 +sudo yum -y install epel-release
 +sudo yum -y install git wget
 +sudo yum -y groupinstall "Development tools"
 +sudo yum -y install cmake cmake3 curl curl-devel log4cplus-devel
 +
 +# get OpenALPR sources
 +mkdir ~/src; cd ~/src 
 +git clone https://github.com/openalpr/openalpr.git
 +cd ~/src/openalpr/src && mkdir build; cd build
 +
 +# compile Tesseract (and Leptonica), required by OpenALPR
 +sudo yum -y install autoconf-archive libjpeg-turbo-devel libpng-devel libtiff-devel zlib-devel
 +cd ~/src
 +wget http://www.leptonica.org/source/leptonica-1.81.1.tar.gz
 +tar -zxvf leptonica-1.81.1.tar.gz
 +cd leptonica-1.81.1
 +./configure
 +make
 +sudo make install
 +
 +cd ~/src
 +wget https://github.com/tesseract-ocr/tesseract/archive/refs/tags/4.1.1.tar.gz -O tesseract-4.1.1.tar.gz
 +tar -zxvf tesseract-4.1.1.tar.gz
 +cd tesseract-4.1.1
 +./autogen.sh
 +export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig && export LIBLEPT_HEADERSDIR=/usr/local/include
 +./configure --with-extra-includes=/usr/local/include --with-extra-libraries=/usr/local/lib LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include"
 +make -j$(nproc)
 +sudo make install
 +sudo ldconfig
 +cd ~/src/openalpr/runtime_data/ocr/tessdata
 +wget https://github.com/tesseract-ocr/tessdata/raw/master/spa.traineddata
 +
 +# compile OpenCV,  required by OpenALPR 
 +sudo yum -y install epel-release git gcc gcc-c++ cmake3 qt5-qtbase-devel python python-devel python-pip cmake python-devel python34-numpy gtk2-devel libpng-devel jasper-devel openexr-devel libwebp-devel libjpeg-turbo-devel libtiff-devel libdc1394-devel tbb-devel numpy eigen3-devel gstreamer-plugins-base-devel freeglut-devel mesa-libGL mesa-libGL-devel boost boost-thread boost-devel libv4l-devel
 +
 +mkdir ~/src/opencv_build; cd ~/src/opencv_build
 +git clone https://github.com/opencv/opencv.git
 +git clone https://github.com/opencv/opencv_contrib.git
 +cd ~/src/opencv_build/opencv && mkdir build; cd build
 +cmake3 -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_EXTRA_MODULES_PATH=~/src/opencv_build/opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
 +# this is going to take some minutes...
 +make -j$(nproc)
 +sudo make install
 +sudo ln -s /usr/local/lib64/pkgconfig/opencv4.pc /usr/share/pkgconfig/  
 +sudo ldconfig
 +pkg-config --modversion opencv4
 +
 +# finally, compile OpenALPR
 +cd ~/src/openalpr/src/build
 +cmake3 -DCMAKE_CXX_FLAGS="-std=c++11" -DCMAKE_INSTALL_PREFIX:PATH=/usr/local -DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc ..
 +make
 +sudo make install
 +</code>
 +
 +Finally as **root** user:
 +  # if [ ! -f /etc/ld.so.conf.d/usrlocal.conf ] ;then echo "/usr/local/lib" > /etc/ld.so.conf.d/usrlocal.conf; echo "/usr/local/lib64" >>/etc/ld.so.conf.d/usrlocal.conf; fi
 +  # sudo ldconfig -v
 +
 +This is needed so alpr doesn't complain about finding libraries...
 +
 +Test it:
 +  # alpr --version
 +  
 +  alpr  version: 2.3.0
 +
 +  # alpr --help
 +  [...]
 +
 +\\
 +
 +**LONG VERSION AHEAD:**
  
 ===== Step 1. Prepare after a fresh MINIMAL CentOS 7 installation ===== ===== Step 1. Prepare after a fresh MINIMAL CentOS 7 installation =====
Línea 24: Línea 105:
 We'll need EPEL repo, wget, git and basic development tools like a C/C++ compiler etc. We'll need EPEL repo, wget, git and basic development tools like a C/C++ compiler etc.
   $ sudo yum -y install epel-release   $ sudo yum -y install epel-release
-  $ sudo yum install git wget+  $ sudo yum -y install git wget
   $ sudo yum groupinstall "Development tools"   $ sudo yum groupinstall "Development tools"
      
 Now we can install cmake (2) and cmake3 (3.17) which is found on EPEL repo Now we can install cmake (2) and cmake3 (3.17) which is found on EPEL repo
-  # sudo yum install cmake3 cmake+  # sudo yum install cmake cmake3
  
 Now the problem is ''cmake'' command is 2.8 and ''cmake3'' the version we need. Thanks to this guide about [[https://gist.github.com/zrsmithson/8a1b7923a8f37dcb2e6b12b7e408fd50|Installing the latest git/cmake versions on RHEL/Centos]]. Now the problem is ''cmake'' command is 2.8 and ''cmake3'' the version we need. Thanks to this guide about [[https://gist.github.com/zrsmithson/8a1b7923a8f37dcb2e6b12b7e408fd50|Installing the latest git/cmake versions on RHEL/Centos]].
Línea 34: Línea 115:
 The relevant part is to execute the following two commands, assuming you have installed ''cmake'' AND ''cmake3'': The relevant part is to execute the following two commands, assuming you have installed ''cmake'' AND ''cmake3'':
 <code [enable_line_numbers="false"]> <code [enable_line_numbers="false"]>
-sudo alternatives --install /usr/local/bin/git git /usr/bin/git 10 \ +sudo alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake 10 \ 
---slave /usr/local/git-receive-pack git-receive-pack /usr/bin/git-receive-pack +--slave /usr/local/bin/ctest ctest /usr/bin/ctest 
---slave /usr/local/git-shell git-shell /usr/bin/git-shell +--slave /usr/local/bin/cpack cpack /usr/bin/cpack 
---slave /usr/local/git-upload-archive git-upload-archive /usr/bin/git-upload-archive \ +--slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake 
---slave /usr/local/git-upload-pack git-upload-pack /usr/bin/git-upload-pack +--family cmake
---family git+
  
-sudo alternatives --install /usr/local/bin/git git /usr/local/git/bin/git 20 \ +sudo alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake3 20 \ 
---slave /usr/local/git-cvsserver git-cvsserver /usr/local/git/bin/git-cvsserver \ +--slave /usr/local/bin/ctest ctest /usr/bin/ctest3 
---slave /usr/local/git-receive-pack git-receive-pack /usr/local/git/bin/git-receive-pack +--slave /usr/local/bin/cpack cpack /usr/bin/cpack3 
---slave /usr/local/git-shell git-shell /usr/local/git/bin/git-shell \ +--slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake3 
---slave /usr/local/git-upload-archive git-upload-archive /usr/local/git/bin/git-upload-archive +--family cmake
---slave /usr/local/git-upload-pack git-upload-pack /usr/local/git/bin/git-upload-pack \ +
---slave /usr/local/gitk gitk /usr/local/git/bin/gitk +
---family git+
 </code> </code>
 Test ''cmake'' version: Test ''cmake'' version:
Línea 86: Línea 163:
 First we need to compile **Leptonica** (a software for image processing and analysis), which is a dependency of Tesseract. First we need to compile **Leptonica** (a software for image processing and analysis), which is a dependency of Tesseract.
  
-  $ sudo yum install autoconf-archive libjpeg-turbo-devel libpng-devel libtiff-devel zlib-devel+  $ sudo yum -y install autoconf-archive libjpeg-turbo-devel libpng-devel libtiff-devel zlib-devel
   $ cd ~/src   $ cd ~/src
   $ wget http://www.leptonica.org/source/leptonica-1.81.1.tar.gz   $ wget http://www.leptonica.org/source/leptonica-1.81.1.tar.gz
Línea 96: Línea 173:
  
 Check if libpng is installed: type ''whereis libpng'' and expect to see a directory; a blank line is not good Check if libpng is installed: type ''whereis libpng'' and expect to see a directory; a blank line is not good
 +
 Check if leptonica is installed: type ''ls /usr/local/include'' and expect to see "leptonica" Check if leptonica is installed: type ''ls /usr/local/include'' and expect to see "leptonica"
  
 Now let's compile the latest Tesseract released, 4.1.1 at the time of this writing. The process was smooth too: Now let's compile the latest Tesseract released, 4.1.1 at the time of this writing. The process was smooth too:
   $ cd ~/src   $ cd ~/src
-  $ wget https://github.com/tesseract-ocr/tesseract/archive/refs/tags/4.1.1.tar.gz+  $ wget https://github.com/tesseract-ocr/tesseract/archive/refs/tags/4.1.1.tar.gz -O tesseract-4.1.1.tar.gz
   $ tar -zxvf tesseract-4.1.1.tar.gz   $ tar -zxvf tesseract-4.1.1.tar.gz
   $ cd tesseract-4.1.1   $ cd tesseract-4.1.1
Línea 133: Línea 211:
 So we need **OpenCV**, a real-time optimized Computer Vision library, another dependency of //OpenALPR//. So we need **OpenCV**, a real-time optimized Computer Vision library, another dependency of //OpenALPR//.
  
-We have a "opencv-devel" package from official CentOS 7 repos, but... +We have a "opencv-devel" package from official CentOS 7 repos, but...
   $ sudo yum list opencv-devel   $ sudo yum list opencv-devel
  
Línea 146: Línea 224:
 **Why not, we're going to build OpenCV from sources** to get OpenCV **4.x**, which is a bit of extra pain, but this guide helped: https://linuxize.com/post/how-to-install-opencv-on-centos-7/ **Why not, we're going to build OpenCV from sources** to get OpenCV **4.x**, which is a bit of extra pain, but this guide helped: https://linuxize.com/post/how-to-install-opencv-on-centos-7/
  
-  $ sudo yum install epel-release git gcc gcc-c++ cmake3 qt5-qtbase-devel python python-devel python-pip cmake python-devel python34-numpy gtk2-devel libpng-devel jasper-devel openexr-devel libwebp-devel libjpeg-turbo-devel libtiff-devel libdc1394-devel tbb-devel numpy eigen3-devel gstreamer-plugins-base-devel freeglut-devel mesa-libGL mesa-libGL-devel boost boost-thread boost-devel libv4l-devel+  $ sudo yum -y install epel-release git gcc gcc-c++ cmake3 qt5-qtbase-devel python python-devel python-pip cmake python-devel python34-numpy gtk2-devel libpng-devel jasper-devel openexr-devel libwebp-devel libjpeg-turbo-devel libtiff-devel libdc1394-devel tbb-devel numpy eigen3-devel gstreamer-plugins-base-devel freeglut-devel mesa-libGL mesa-libGL-devel boost boost-thread boost-devel libv4l-devel
  
   $ mkdir ~/src/opencv_build; cd ~/src/opencv_build   $ mkdir ~/src/opencv_build; cd ~/src/opencv_build
Línea 258: Línea 336:
 \\ \\
  
-===== Woohoo! alpr command is available =====+===== Woohoo! alpr command actually works =====
  
 Get an image of a vehicle plate, say ''plate.jpg''. Get an image of a vehicle plate, say ''plate.jpg''.
linux/howtos/centos/openalpr-compile-from-sources.1629549364.txt.bz2 · Última modificación: 21/08/2021 14:36 por Juanga Covas