RaspberryPi4에 OpenCV를 설치합니다.
                                            
                                                
                                                
                                                
                                                
                                                
                                                 5449 단어  RaspberryPi4OpenCV
                    
RaspberryPi4에 openCV3.4.1을 설치할 때 비망록
 파일 시스템을 확장합니다.
$ sudo raspi-config 
7 Advanced Options --> A1 Expand filesystem --> Finsh
 swap을 늘립니다.
$ sudo vi /etc/dphys-swapfile
# set size to absolute value, leaving empty (default) then uses computed value
#   you most likely don't want this, unless you have an special disk situation
# CONF_SWAPSIZE=100
CONF_SWAPSIZE=2048
 dphys-swapfile 재부팅
$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start
 이번에는 cmake-gui를 사용해 보자.
$ sudo apt install cmake-qt-gui
 종속성이 있는 라이브러리를 설치합니다.
$ sudo apt install libavcodec-dev libavformat-dev libswscale-dev libxvidcore-dev libx264-dev libxine2-dev
$ sudo apt install libv4l-dev v4l-utils libgtk2.0-dev 
$ sudo apt install libmesa-utils libgl1-mesa-dri libgtkglext1-dev libatlas-base-dev gfortran libeigen3-dev python-2.7-dev python3-dev python-numpy python3-numpy
 Opencv3.4.1 빌드
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.1.zip
$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.1.zip  
$ unzip opencv.zip
$ unzip opencv_contrib.zip
$ cd opencv-3.4.1
$ mkdir build 
$ cmake-gui
GUI가 표시되므로 소스 코드의 디렉토리와 빌드 디렉토리를 선택하고 [Configure] 버튼을 클릭합니다.
 
CMakeSetup 다이얼로그가 표시되므로 [Finish] 버튼을 클릭한다.
 
이런 식으로 설정이 시작된다.
 
설정 완료
 
OPENCV_EXTRA_MODULES_PATH를 추가합니다.
wget한 opencv_contrib-3.4.1/modules를 지정한다.
 
WITH_OPENGL을 체크하고 Configure 버튼을 클릭
 
Configuring done이 표시되면 [Generate] 버튼을 클릭
 
Generatin done이 표시되면 빌드의 전처리는 종료.
화면을 닫고 터미널로 돌아갑니다.
 
$ make -j4 
build 오류
cv2.cpp:889:34: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
 여기의 정보에 따르면
This version (and some older versions) don't compile (with Python3.7)
몇몇 낡은 버젼은 python3.7로 컴파일 할 수 없는 것 같다.
그래서
opencv-3.4.1/modules/python/src2/cv2.cpp의 889 행을 수정합니다.
bool pyopencv_to(PyObject* obj, String& value, const char* name)
{
   (void)name;
   if(!obj || obj == Py_None)
       return true;
-  char* str = PyString_AsString(obj);
+  const char* str = PyString_AsString(obj);
    if(!str)
       return false;
    value = String(str);
  return true;
}
수정 후 재빌드
$ make -j4
[100%] Linking CXX executable ../../bin/opencv_test_stitching
[100%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_estimators.cpp.o
[100%] Built target opencv_test_stitching
[100%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_main.cpp.o
[100%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_matchers.cpp.o
[100%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_stich.cpp.o
[100%] Linking CXX executable ../../bin/opencv_perf_stitching
[100%] Built target opencv_perf_stitching
[100%] Linking CXX shared module ../../lib/python3/cv2.cpython-37m-arm-linux-gnueabihf.so
[100%] Built target opencv_python3
[100%] Linking CXX shared module ../../lib/cv2.so
[100%] Built target opencv_python2
pi@raspberrypi:~/opencv-3.4.1/build$ 
빌드 성공
 다음은 openCV4계를 빌드해 보자
 그 전에 3.4.10 빌드를 시도하십시오.
 3.4.10은 소스 수정없이 빌드 성공
$ make -j4 
[100%] Linking CXX executable ../../bin/opencv_test_tracking
[100%] Built target opencv_test_tracking
[100%] Linking CXX shared module ../../lib/python3/cv2.cpython-37m-arm-linux-gnueabihf.so
[100%] Linking CXX shared module ../../lib/cv2.so
[100%] Built target opencv_python3
[100%] Built target opencv_python2
pi@raspberrypi:~/opencv3/opencv-3.4.10/build $ 
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(RaspberryPi4에 OpenCV를 설치합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/misoragod/items/28235ca32d68cf9e6b3f
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
$ sudo raspi-config 
7 Advanced Options --> A1 Expand filesystem --> Finsh
$ sudo vi /etc/dphys-swapfile
# set size to absolute value, leaving empty (default) then uses computed value
#   you most likely don't want this, unless you have an special disk situation
# CONF_SWAPSIZE=100
CONF_SWAPSIZE=2048
$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start
$ sudo apt install cmake-qt-gui
$ sudo apt install libavcodec-dev libavformat-dev libswscale-dev libxvidcore-dev libx264-dev libxine2-dev
$ sudo apt install libv4l-dev v4l-utils libgtk2.0-dev 
$ sudo apt install libmesa-utils libgl1-mesa-dri libgtkglext1-dev libatlas-base-dev gfortran libeigen3-dev python-2.7-dev python3-dev python-numpy python3-numpy
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.1.zip
$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.1.zip  
$ unzip opencv.zip
$ unzip opencv_contrib.zip
$ cd opencv-3.4.1
$ mkdir build 
$ cmake-gui
$ make -j4 
bool pyopencv_to(PyObject* obj, String& value, const char* name)
{
   (void)name;
   if(!obj || obj == Py_None)
       return true;
-  char* str = PyString_AsString(obj);
+  const char* str = PyString_AsString(obj);
    if(!str)
       return false;
    value = String(str);
  return true;
}
$ make -j4
[100%] Linking CXX executable ../../bin/opencv_test_stitching
[100%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_estimators.cpp.o
[100%] Built target opencv_test_stitching
[100%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_main.cpp.o
[100%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_matchers.cpp.o
[100%] Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_stich.cpp.o
[100%] Linking CXX executable ../../bin/opencv_perf_stitching
[100%] Built target opencv_perf_stitching
[100%] Linking CXX shared module ../../lib/python3/cv2.cpython-37m-arm-linux-gnueabihf.so
[100%] Built target opencv_python3
[100%] Linking CXX shared module ../../lib/cv2.so
[100%] Built target opencv_python2
pi@raspberrypi:~/opencv-3.4.1/build$ 
$ make -j4 
[100%] Linking CXX executable ../../bin/opencv_test_tracking
[100%] Built target opencv_test_tracking
[100%] Linking CXX shared module ../../lib/python3/cv2.cpython-37m-arm-linux-gnueabihf.so
[100%] Linking CXX shared module ../../lib/cv2.so
[100%] Built target opencv_python3
[100%] Built target opencv_python2
pi@raspberrypi:~/opencv3/opencv-3.4.10/build $ 
Reference
이 문제에 관하여(RaspberryPi4에 OpenCV를 설치합니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/misoragod/items/28235ca32d68cf9e6b3f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)