To install OpenCV on a Raspberry Pi, you can follow these steps:
Step 1: Update the Raspberry Pi
sudo apt update
sudo apt upgra
Step 2: Install Dependencies
sudo apt install build-essential cmake git pkg-config libjpeg-dev libtiff5-dev libjasper-dev libpng-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk-3-dev libcanberra-gtk* libatlas-base-dev gfortran python3-dev
Step 3: Download OpenCV Source Code
cd ~git clone https://github.com/opencv/opencv.git
cd opencv
git checkout <version> # Replace <version> with the desired version, e.g., 4.5.1
Step 4: Build OpenCV
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D OPENCV_ENABLE_NONFREE=ON ..
Step 5: Compile OpenC
make -j4
Note: The `-j4` option is used to compile using four threads, which speeds up the compilation process. You can adjust this value according to the number of CPU cores available on your Raspberry Pi.
Step 6: Install OpenCV
sudo make install
sudo ldconfig
Step 7: Verify Installation
python3
import cv2
cv2.__version__
Running the above Python code should output the version of OpenCV you installed, indicating that the installation was successful.
That's it! You have now installed OpenCV on your Raspberry Pi. Remember to replace `<version>` in Step 3 with the desired version number, such as 4.5.1, or you can omit it to download the latest version from the repository.
Please note that the compilation process may take a while on a Raspberry Pi, so be patient.
Comments
Please log in or sign up to comment.