라즈베리파이 세팅

2021. 8. 10. 17:46HARDWARE/Raspberry Pi

===================

* device : raspberry pi 4

* OS version : buster

* 당부의 말 : 부디 인터넷 환경이 좋은 곳에서 하시오.. (매우 오래걸림)

 

라즈베리파이 맥에서 SSH 연결

ssh pi@192.xx.xx.xx

 

 

PyQt설치

sudo apt-get install python3-pyqt5

1. expanding file system

 

2. updating system

sudo apt-get update && sudo apt-get upgrade

download any latest packages available and install them. (15~20min)

sudo apt-get update

 

3. Installing CMake

CMake = compiling the openCV library.

sudo apt install snapd

after download snapd,

sudo snap install cmake --classic

에러가 나는 경우

raspi-config > performance > GPU Memory = 256 이상으로 하기 (256으로 설정해도 충분)

 

4. Installing Python

install the python 3 development headers

sudo apt-get install python3-dev

 

5. Getting openCV packages

wget opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip
wget opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.0.zip

these packages may be installed on your home directory.

and change files name to "opencv.zip" & "opencv_contrib.zip"

 

6. Installing openCV packages

unzip opencv.zip
unzip opencv_contrib.zip

then you would have two directories named “opencv-4.0.0” and “opencv_contrib-4.0.0” in our home directory.

The next step would be to compile the Open CV library, to do that we need to create a new directory called “build” inside the opencv-4.0.0 directory. Follow the below commands to do the same. (at step 8)

 

7. Installing Numpy

pip install numpy

 

8. Building directory & Instructions for compiling

cd ~/opencv-4.0.0
mkdir build
cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.0.0/modules \
    -D ENABLE_NEON=ON \
    -D ENABLE_VFPV3=ON \
    -D BUILD_TESTS=OFF \
    -D WITH_TBB=OFF \
    -D INSTALL_PYTHON_EXAMPLES=OFF \
    -D BUILD_EXAMPLES=OFF ..
  • It should get configured without any errors and you should see the text “Configuring done” and “Generating done” as shown below.
  • If you get any error in this process then make sure you have typed in the proper path and you have two directories named “opencv-4.0.0” and “opencv_contrib-4.0.0” in the home directory path.

9. compiling openCV

make -j4
  • He would start building OpenCV and you would be able to see the progress in percentage. The process would take around 30-40 Minutes and if it gets completely built, you should see a screen like this above.
  • The command “make –j4” makes use of all four cores to compile OpenCV. At 99% percentage, some people might find it taking too long for the process to complete wait patiently and it should get finished.
  • For me, it did not work even after waiting for 25 minutes and an error came like in the above image so I build it again using “make –j1” and it worked.
  • Using make –j1 uses only a single core of pi and it would take a longer time than make j4 but it's stable, so it is recommended to use make j4 and then uses make j1 since most of the compilation would be done by make j4.

In case your code is not compiling at 100% and it gets an error like above, try using "make -j1". Also if it gets stuck at 63% or in the middle somewhere, delete all the files from the build folder and rebuild again with proper steps.

 

10. installing libopencv

  • If you have reached this step then, you have sailed through the process. The final step would be to install libopecv using the following command.
sudo apt-get install libopencv-devpython-opencv

 

11. Testing opencv

  • Finally, you can check if the library was added successfully by running a simple python command.

"import cv2" to test in python script