opencv
This article introduces the installation of OpenCV on Raspberry Pi 4B. Due to the relatively large project, it is developed in C++ rather than Python, making the installation of OpenCV somewhat more complex.
During the installation process, some issues may arise due to the OpenCV version being too high for the Raspberry Pi system. A relatively lower version can be used. This article uses OpenCV 4.1.0, and both C++ and Python versions are installed together.
The default version of Python on Raspberry Pi 4B is 2.7, so it is recommended to install Python 3.7.
As the official OpenCV GitHub repository automatically updates to the latest version, this article refers to two sources:
https://link.zhihu.com/?target=https%3A//blog.csdn.net/m0_37259197/article/details/102894697
https://link.zhihu.com/?target=https%3A//github.com/armstrong1972/Install-OpenCV4.1.1-on-RaspberryPi-4b/blob/master/How%2520to%2520Install%2520-%2520chn.txt
Research Background:
1. Using Raspberry Pi 4B to control the movement of a mobile robot and collect images for functional calculations.
2. Equipment: (This is an improvement based on Xiao-R Technology’s Raspberry Pi Wi-Fi car)
-
Raspberry Pi 4B
-
USB Plug-and-Play Camera
-
4 Track Mobile Robot
-
Power Amplifier (for DC motor)
-
24V Battery, 5V Battery
Operation Process:
Updating the version is important$ sudo apt-get update # Update software version directory list$ sudo apt-get upgrade # Update software
==============================================================Installing the Camera==============================================================USB camera should not be plugged in first$ lsusbPlug in the camera and run again. If there are additional devices, it indicates that the system has accepted it. For example, additional: Bus 001 Device 004: ID 0bda:58b0 Realtek Semiconductor Corp.
Photo Test$ sudo apt-get install fswebcam$ fswebcam /dev/video0 image.jpgCheck if image.jpg is normal in the Home directory
Set as a Network Camera$ sudo apt-get install motion$ sudo nano /etc/default/motionChange start_motion_daemon from no to yes, run in the background
$ sudo nano /etc/motion/motion.conf^w Quickly find and modify the following parameters: daemon onstream_localhost offwebcontrol_localhost offwidth 500 height 400
Start motion$ sudo motionOpen http://Raspberry_Pi_IP:8080 on other computers
Exit motion$ service motion stop
==============================================================Expand the root directory to the entire SD card in Raspberry Pi settings (Pi4B no longer needs this)==============================================================Installing OpenCV, Dlib, Darknet, etc. requires a lot of space, and failing to expand will result in installation failure$ sudo raspi-config select 7 Adv Options, then select A1. Exit and reboot$ sudo reboot
==============================================================Install Basic Libraries==============================================================$ sudo apt-get -y install build-essential cmake unzip pkg-config$ sudo apt-get -y install libjpeg-dev libpng-dev libtiff-dev$ sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev$ sudo apt-get -y install libxvidcore-dev libx264-dev$ sudo apt-get -y install libgtk-3-dev$ sudo apt-get -y install libcanberra-gtk*$ sudo apt-get -y install libatlas-base-dev gfortran$ sudo apt-get -y install python3-dev
==============================================================Install OpenCV==============================================================cdcd Downloads
git clone -b 4.1.0 --recursive https://github.com/opencv/opencv.gitgit clone -b 4.1.0 --recursive https://github.com/opencv/opencv_contrib.git
cdcd Downloadscd opencvmkdir buildcd build
Please modify the value of OPENCV_EXTRA_MODULES_PATH (I downloaded two zip files to ~/ai/opencv) You can use ls to check the directory to confirm the file is displayed, then use it as a parameter value$ cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib/modules \ -D ENABLE_NEON=ON \ -D ENABLE_VFPV3=ON \ -D BUILD_TESTS=OFF \ -D OPENCV_ENABLE_NONFREE=ON \ -D INSTALL_PYTHON_EXAMPLES=OFF \ -D CMAKE_SHARED_LINKER_FLAGS='-latomic' \ -D BUILD_EXAMPLES=OFF .. It is recommended to use 2 cores for compilation, which is more stable; 4 cores for compilation make -j4$ make -j2 Look for the following output content to indicate success[100%] Built target opencv_python2[100%] Linking CXX shared module ../../lib/python3/cv2.cpython-37m-arm-linux-gnueabihf.so[100%] Built target opencv_python3
If compilation issues occur, you can recompilemake cleanmake -j4
$ sudo make installLook for the following output content to indicate success-- Installing: /usr/local/lib/python3.7/dist-packages/cv2/python-3.7/cv2.cpython-37m-arm-linux-gnueabihf.so-- Set runtime path of "/usr/local/lib/python3.7/dist-packages/cv2/python-3.7/cv2.cpython-37m-arm-linux-gnueabihf.so" to "/usr/local/lib"
$ sudo ldconfig
Check if successful:$ python3>>> import cv2>>> cv2.__version__'4.1.1'
OK, finished.
“Learning PID Control through Lane Keeping”
This course will guide everyone to first understand the working principle of PID control and lane keeping, and build a PID controller based on MATLAB/Simulink. We will use the PID controller to continuously control our vehicle to drive in the center of the lane by tuning appropriate parameters.
Leave a Comment
Your email address will not be published. Required fields are marked *