OS/Orange PI

Orange Pi 5 Plus : OpenCV 4.5.5 설치

파란크리스마스 2023. 11. 4. 10:39
728x90

출처

기존 OpenCV 버전 제거

OpenCV 설치확인

orangepi@orangepi5plus:~$ pkg-config --modversion opencv
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found

OpenCV 패키지 삭제

orangepi@orangepi5plus:~$ sudo apt purge libopencv* python-opencv
orangepi@orangepi5plus:~$ sudo apt autoremove

기존에 설치된 opencv 라이브러리를 삭제

orangepi@orangepi5plus:~$ sudo find /usr/local/ -name "*opencv*" -exec rm  {} \;

OS 업데이트, 업그레이드

orangepi@orangepi5plus:~$ sudo apt update && sudo apt upgrade

OpenCV 빌드 관련 도구 설치

orangepi@orangepi5plus:~$ sudo apt install build-essential cmake cmake-gui

OpenCV 관련 라이브러리 설치

orangepi@orangepi5plus:~$ sudo apt install libjpeg-dev libtiff5-dev libavcodec-dev libavformat-dev libswscale-dev libxvidcore-dev libx264-dev libxine2-dev libv4l-dev v4l-utils libpng-dev

GStreamer 관련 패키지 설치

orangepi@orangepi5plus:~$ sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly

GTK 관련 라이브러리 설치

orangepi@orangepi5plus:~$ sudo apt install libgtk2.0-dev

GTK 관련 라이브러리 설치 오류시

OpenGL 라이브러리 설치

orangepi@orangepi5plus:~$ sudo apt install mesa-utils libgtkgl2.0-dev libgtkglext1-dev libgtk3.0-cil-dev

OpenCV 최적화를 위해 사용되는 라이브러리

orangepi@orangepi5plus:~$ sudo apt install libatlas-base-dev gfortran libeigen3-dev

Python 설치

orangepi@orangepi5plus:~$ sudo apt install python2.7-dev python3-dev python3-numpy

OpenCV 4.1.1 다운로드

OpenCV 4.1.1 소스 다운로드

orangepi@orangepi5plus:~$ mkdir OpenCV
orangepi@orangepi5plus:~$ cd OpenCV
orangepi@orangepi5plus:~/OpenCV$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.5.zip
orangepi@orangepi5plus:~/OpenCV$ unzip opencv.zip
orangepi@orangepi5plus:~/OpenCV$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.5.zip
orangepi@orangepi5plus:~/OpenCV$ unzip opencv_contrib.zip

디렉토리명 변경

orangepi@orangepi5plus:~/OpenCV$ cd opencv-4.5.5
orangepi@orangepi5plus:~/OpenCV/opencv-4.5.5$ mkdir build
orangepi@orangepi5plus:~/OpenCV/opencv-4.5.5$ cd build

OpenCV 컴파일

CMake 실행

orangepi@orangepi5plus:~/OpenCV/opencv-4.5.5/build$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
  -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.5.5/modules -D OPENCV_GENERATE_PKGCONFIG=ON \
  -D BUILD_opencv_java=OFF -D BUILD_opencv_python3=ON -D WITH_OPENMP=OFF -D WITH_GSTREAMER_0_10=OFF \
  -D WITH_VTK=OFF -D WITH_LIBV4L=ON -D WITH_OPENMP=ON -D WITH_OPENGL=ON -D WITH_TBB=ON \
  -D BUILD_SHARED_LIBS=ON -D ENABLE_PIC=ON -D WITH_ARITH_DEC=ON -D WITH_ARITH_ENC=ON \
  -D WITH_FFMPEG=ON -D WITH_GSTREAMER=ON -D WITH_IMGCODEC_HDR=ON -D WITH_IMGCODEC_PXM=ON \
  -D WITH_IMGCODEC_SUNRASTER=ON -D WITH_JASPER=ON -D WITH_JPEG=ON -D WITH_LAPACK=ON \
  -D WITH_PNG=ON -D WITH_QT=ON -D WITH_PTHREADS_PF=ON -D WITH_TIFF=ON -D WITH_WEBP=ON \
  -D WITH_GTK=ON -D BUILD_PNG=ON -D WITH_OPENCL=ON ..
 
. ... 생략 ... 
 
-- General configuration for OpenCV 4.5.5 =====================================
--   Version control:               unknown
-- 
--   Extra modules:
--     Location (extra):            /home/orangepi/OpenCV/opencv_contrib-4.5.5/modules
--     Version control (extra):     unknown
-- 
--   Platform:
--     Timestamp:                   2023-11-05T00:40:39Z
--     Host:                        Linux 5.10.110-rockchip-rk3588 aarch64
--     CMake:                       3.22.1
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/gmake
--     Configuration:               RELEASE
-- 
--   CPU/HW features:
--     Baseline:                    NEON FP16
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 11.4.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fopenmp -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fopenmp -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--gc-sections -Wl,--as-needed  
--     Linker flags (Debug):        -Wl,--gc-sections -Wl,--as-needed  
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          dl m pthread rt
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 alphamat aruco barcode bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv hdf java julia matlab ovis python2 sfm viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI:                           GTK2
--     QT:                          NO
--     GTK+:                        YES (ver 2.24.33)
--       GThread :                  YES (ver 2.72.4)
--       GtkGlExt:                  YES (ver 1.2.0)
--     OpenGL support:              YES (/usr/lib/aarch64-linux-gnu/libGL.so /usr/lib/aarch64-linux-gnu/libGLU.so)
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         /lib/libpng12.so (ver 1.6.37)
--     TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.3.0)
--     JPEG 2000:                   build (ver 2.4.0)
--     OpenEXR:                     /usr/lib/aarch64-linux-gnu/libImath-2_5.so /usr/lib/aarch64-linux-gnu/libIlmImf-2_5.so /usr/lib/aarch64-linux-gnu/libIex-2_5.so /usr/lib/aarch64-linux-gnu/libHalf-2_5.so /usr/lib/aarch64-linux-gnu/libIlmThread-2_5.so (ver 2_5)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      YES (2.2.6)
--     FFMPEG:                      YES
--       avcodec:                   YES (58.134.100)
--       avformat:                  YES (58.76.100)
--       avutil:                    YES (56.70.100)
--       swscale:                   YES (5.9.100)
--       avresample:                NO
--     GStreamer:                   YES (1.20.3)
--     v4l/v4l2:                    YES (linux/videodev2.h)
-- 
--   Parallel framework:            TBB (ver 2021.5 interface 12050)
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Lapack:                      NO
--     Eigen:                       YES (ver 3.4.0)
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.19.1)
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/orangepi/OpenCV/opencv-4.5.5/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.10.12)
--     Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.10.so (ver 3.10.12)
--     numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.21.5)
--     install path:                lib/python3.10/dist-packages/cv2/python-3.10
-- 
--   Python (for build):            /usr/bin/python2.7
-- 
--   Java:                          
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/orangepi/OpenCV/opencv-4.5.5/build

CPU 코어 개수 확인

orangepi@orangepi5plus:~/OpenCV/opencv-4.5.5/build$ grep -c processor /proc/cpuinfo
8

OpenCV 컴파일

orangepi@orangepi5plus:~/OpenCV/opencv-4.5.5/build$ make -j8

OpenCV 설치

orangepi@orangepi5plus:~/OpenCV/opencv-4.5.5/build$ sudo make install 
orangepi@orangepi5plus:~/OpenCV/opencv-4.5.5/build$ sudo ldconfig

OpenCV 설치 확인

파이썬

orangepi@orangepi5plus:~/OpenCV/opencv-4.5.5/build$ python
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.5.5'
>>> exit()

C++

#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

int main( int argc, char** argv ) {
  cout << "OpenCV version : " << CV_VERSION << endl;
  cout << "Major version : " << CV_MAJOR_VERSION << endl;
  cout << "Minor version : " << CV_MINOR_VERSION << endl;
  cout << "Subminor version : " << CV_SUBMINOR_VERSION << endl; 
}
orangepi@orangepi5plus:~$ g++ version_check.cpp -o version_check -std=c++11 `pkg-config --cflags --libs opencv4`
orangepi@orangepi5plus:~$ ./version_check
OpenCV version : 4.5.5
Major version : 4
Minor version : 5
Subminor version : 5