백곡시스템

우분투 opencv + openalpr cross compile

출처: http://gampol.tistory.com/entry/%EC%9A%B0%EB%B6%84%ED%88%AC-opencvopenalpr-closs-compile

Ubuntu-12.04.4-desktop-amd64로 작업함

** 관련 패키지 설치

$ sudo apt-get install build-essential

$ sudo apt-get install cmake

$ sudo apt-get install git

$ sudo apt-get install g++-arm-linux-gnueabi

$ sudo apt-get install gcc-arm-linux-gnueabi

$ sudo apt-get install g++-arm-linux-gnueabihf

$ sudo apt-get install gcc-arm-linux-gnueabihf

$ sudo apt-get install cmake-curses-gui

sudo apt-get install libpng12-dev

$ sudo apt-get install libjpeg62-dev

$ sudo apt-get install libtiff4-dev

$ sudo apt-get install zlib1g-dev

$ sudo apt-get install autoconf automake libtool autotools-dev

** 혹씨모를 컴파일시 오류발생 방지를 위해 계정의 .bashrc 에 추가함
export LD_LIBRARY_PATH=”/usr/local/lib:/usr/local/arm/opencv/lib:/usr/local/arm/leptonica/lib:/usr/local/arm/tesseract-ocr/lib:$LD_LIBRARY_PATH”

** 패키지 다운로드 디렉토리 생성(계정의 홈디렉토리에서 생성함)

$ pwd

/home/계정명

$ mkdir down

$ cd down

** opencv 소스 다운로드

wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip

$ unzip opencv-2.4.9.zip

** ARM gcc 컴파일 버전 확인(주버전.부버전만 확인한다 4.8)

$ arm-linux-gnueabihf-gcc –version

arm-linux-gnueabihf-gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Copyright (C) 2011 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

arm-linux-gnueabihf-gcc (Ubuntu/Linaro 4.8.2-16ubuntu4) 4.8.2

Copyright (C) 2013 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

** opencv 컴파일 버전 변경

$ pwd

/home/계정명/down

$ vi opencv-2.4.9/platforms/linux/arm-gnueabi.toolchain.cmake

5라인 정도에…

set(GCC_COMPILER_VERSION “4.6” CACHE STRING “GCC Compiler version”)

–> set(GCC_COMPILER_VERSION “4.8” CACHE STRING “GCC Compiler version”)

** opencv 빌드 디렉토리 생성

$ cd

$ cd down

$ mkdir build

$ cd build

$ pwd

/home/계정명/down/build

** opencv 컴파일 옵션 설정

$ rm -rf CMakeCache.txt

$ cmake \

    -DCMAKE_INSTALL_PREFIX=/usr/local/arm/opencv \

    -DWITH_FFMPEG=ON \

    -DWITH_JASPER=ON \

    -DWITH_JPEG=ON \

    -DWITH_PNG=ON \

    -DWITH_TIFF=ON \

    -DWITH_VFW=ON \

    -DWITH_WEBP=ON \

    -DWITH_TBB=ON \

    -DWITH_V4L=ON \

    -DWITH_OPENEXR=ON \

    -DWITH_OPENGL=ON \

    -DBUILD_JASPER=ON \

    -DBUILD_JPEG=ON \

    -DBUILD_PNG=ON \

    -DBUILD_OPENEXR=ON \

    -DBUILD_PACKAGE=ON \

    -DBUILD_TIFF=ON \

    -DBUILD_WITH_DEBUG_INFO=ON \

    -DBUILD_WITH_STATIC_CRT=ON \

    -DBUILD_ZLIB=ON \

    -DBUILD_EXAMPLES=ON \

    -DBUILD_NEW_PYTHON_SUPPORT=ON \

    -DINSTALL_PYTHON_EXAMPLES=ON \

    -DINSTALL_C_EXAMPLES=ON \

    -DSOFTFT=ON \

    -DUSE_NEON=ON \

    -DCMAKE_TOOLCHAIN_FILE=../opencv-2.4.9/platforms/linux/arm-gnueabi.toolchain.cmake \

    ../opencv-2.4.9

** opencv 컴파일 수행, 설치

$ make

$ sudo make install

** opencv cross 컴파일된 오브젝트 버전확인(32bit ARM, 확인해 보니 git로 받은 opencv는 3.0 인가보네…)

cd /usr/local/arm/opencv/lib

file libopencv_videostab.so.2.4.9 

libopencv_videostab.so.2.4.9: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=8be58a40b52473a2002b969a369fabf1b4aeba8d, not stripped

** 문자인식 관련 패키지  디렉토리 생성(계정의 홈디렉토리에서 생성함)

$ cd

$ cd down

$ mkdir ocr

$ cd ocr

$ pwd

/home/계정명/down/ocr

** 문자인식 관련 패키지 다운로드

$ wget http://www.leptonica.org/source/leptonica-1.70.tar.gz

$ wget https://tesseract-ocr.googlecode.com/files/tesseract-ocr-3.02.02.tar.gz

$ wget https://tesseract-ocr.googlecode.com/files/tesseract-ocr-3.02.kor.tar.gz

** 문자인식 관련 패키지 압축풀기

$ tar xvf tesseract-ocr-3.02.02.tar.gz

tar xvf tesseract-ocr-3.02.kor.tar.gz

$ tar xvf leptonica-1.70.tar.gz

** leptonica 패키지 이동

$ cd leptonica-1.70

$ pwd

/home/계정명/down/ocr/leptonica-1.70

** leptonica 컴파일 옵션 정의

CC=”arm-linux-gnueabihf-gcc” CXX=”arm-linux-gnueabihf-g++” \

./configure \

    –prefix=/usr/local/arm/leptonica \

    –target=arm-linux \

    –host=arm-linux

** leptonica 컴파일 수행, 설치

$ make

$ sudo make install

** leptonica cross 컴파일된 오브젝트 버전확인(32bit ARM)

cd /usr/local/arm/leptonica/lib

file liblept.so.4.0.1

liblept.so.4.0.1: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=358f8173e43fa39cabe5331a71b7ec3dc7c8a812, not stripped

** tesseract 패키지 이동

$ cd

$ cd down/ocr/tesseract-ocr/

$ pwd

/home/계정명/down/ocr/tesseract-ocr

** tesseract 컴파일 옵션 정의

$ ./autogen.sh

LIBLEPT_HEADERSDIR=/usr/local/arm/leptonica/include \

 CC=”arm-linux-gnueabihf-gcc” CXX=”arm-linux-gnueabihf-g++” \

./configure \

    –prefix=/usr/local/arm/tesseract-ocr \

    –target=arm-linux \

    –host=arm-linux \

    –with-extra-libraries=/usr/local/arm/leptonica/lib

** tesseract 컴파일 수행, 설치

$ make

$ sudo make install

** tesseract cross 컴파일된 오브젝트 버전확인(32bit ARM)

cd /usr/local/arm/tesseract-ocr/lib

file libtesseract.so.3.0.2 

libtesseract.so.3.0.2: ELF 32-bit LSB  shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=18c1b84e4915b1ceeacf568cde32b7ad10be073e, not stripped

** openalpr 패키지 이동

$ cd

$ cd down/ocr

$ pwd

/home/계정명/down/ocr

** openalpr git 소스 다운로드

$ git clone https://github.com/openalpr/openalpr.git –depth=1

** openalpr 컴파일 옵션 변경

$ pwd

/home/계정명/down/ocr

$ cd openalpr/src

$ vi CMakeLists.txt

*17라인 정도 opencv, tesseract-ocr path변경

SET(OpenCV_DIR “${CMAKE_SOURCE_DIR}/../libraries/opencv/”)

SET(Tesseract_DIR “${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr”)

–>  SET(OpenCV_DIR “/usr/local/arm/opencv/lib”)

       SET(Tesseract_DIR “/usr/local/arm/tesseract-ocr”)

* 20라인 컴파일중 에러가 난다면 include path추가
 include_directories(
         /usr/local/arm/opencv/include
         ${Tesseract_DIR}/include
         ${Tesseract_DIR}/api
         ${Tesseract_DIR}/ccutil/
         ${Tesseract_DIR}/ccstruct/
         ${Tesseract_DIR}/ccmain/
 )
 
 * 48라인 변경 l
ink_directories( ${Tesseract_DIR}/.api/libs/ )
–> link_directories( ${Tesseract_DIR}/lib/)

** openalpr 컴파일 옵션 정의

$ pwd

/home/계정명/down/ocr/openalpr/src

$ mkdir build

$ cd build

$ pwd

/home/계정명/down/ocr/openalpr/src/build

cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/arm/openalpr \

-DCMAKE_PREFIX_PATH=/usr/local/arm/opencv \

    -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/arm-linux-gnueabihf-g++ \

    -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/arm-linux-gnueabihf-gcc \

    ../

** openalpr 컴파일 수행, 설치

$ make

$ sudo make install

** openalpr 컴파일시 /usr/local/arm/tesseract-ocr/lib/libtesseract.so: undefined reference … 에러메세지 출력시

$ cd /usr/arm-linux-gnueabihf/lib

$ sudo cp -r /usr/local/arm/tesseract-ocr/lib/* .

$ sudo cp -r /usr/local/arm/leptonica/lib/* .

** openalpr ract cross 컴파일된 오브젝트 버전확인(32bit ARM)

cd /usr/local/arm/openalpr/bin

file alpr

alpr: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0dd51f34e6b0e3902773df82aaa039cd3de50033, not stripped

** traineddata 파일 복사

cd ~/down/ocr/openalpr/runtime_data/ocr/tessdata

$ sudo cp *.traineddata /usr/local/ocr/tesseract-ocr/share/tessdata/

$ sudo cp *.traineddata /usr/local/share/tessdata/

출처: http://gampol.tistory.com/entry/우분투-opencvopenalpr-closs-compile [유효하지 않네]

댓글 남기기

Close Menu