2

I've been working on a project with OpenCV and Visual Studio but I want to perform some tests on a Raspberry Pi 3, I haven't found accurate information about how can I use OpenCV in a Raspberry Pi with c++ because most of the information is about using OpenCV with python. One of my ideas was to install windows on the Raspberry Pi and then installing Visual studio community (not the visual studio code) as I did on my laptop but I'm not quite sure that it is possible to do it that way. My other idea is to use Raspbian and then install OpenCV but I want to use c++ instead of python. I hope someone could help me to solve this issue.

1
1

Here is the BASH SCRIPT I used to install OpenCV on RPi4B.

Dave

#!/usr/bin/env bash

# originally from  Michael de Gans 2019

# changes by DK  September 2020

### !!!  Raspberry Pi 4 version !!!


set -e     # exit script immediately upon any error

cd ~

echo "DK-INFO: Download OpenCV from Github archive"

wget -O opencv.zip https://github.com/opencv/opencv/archive/4.4.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.4.0.zip

unzip opencv.zip
unzip opencv_contrib.zip

mv opencv-4.4.0 opencv
mv opencv_contrib-4.4.0 opencv_contrib

echo "DK-INFO: Install OpenCV build dependencies"

sudo apt update && sudo apt upgrade -y
sudo apt-get dist-upgrade -y --autoremove

sudo apt install -y \
        build-essential \
        cmake \
        git \
        pkg-config

sudo apt install -y \
    gfortran \
    libatlas-base-dev \
    liblapacke-dev \
    liblapack-dev \
    libavcodec-dev \
    libavformat-dev \
    libswscale-dev \
    libv4l-dev \
    v4l-utils \
    libxvidcore-dev \
    libx264-dev \
    libfontconfig1-dev \
    libcairo2-dev \
    libgdk-pixbuf2.0-dev \
    libpango1.0-dev \
    libgtk2.0-dev \
    libgtk-3-dev \
    libcanberra-gtk3* \
    libhdf5-dev \
    libhdf5-serial-dev \
    libhdf5-103 \
    libqtgui4 \
    libqtwebkit4 \
    libqt4-test \
    python3-pyqt5 \
        libgstreamer1.0-dev \
        libgstreamer-plugins-base1.0-dev \
    libjpeg-dev \
    libtiff-dev \
    libpng-dev \
    libjasper-dev \
    libtbb-dev \
    libtbb2 \
    python3-dev \
    python3-pip \
    python3-numpy


CMAKEFLAGS="
    -D CMAKE_BUILD_TYPE=RELEASE
    -D CMAKE_INSTALL_PREFIX=/usr/local
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules
    -D BUILD_EXAMPLES=OFF
    -D BUILD_TESTS=OFF
    -D BUILD_PERF_TESTS=OFF
    -D INSTALL_PYTHON_EXAMPLES=OFF
    -D INSTALL_C_EXAMPLES=OFF
    -D ENABLE_NEON=ON
    -D ENABLE_VFPV3=ON
    -D OPENCV_ENABLE_NONFREE=ON
    -D CMAKE_SHARED_LINKER_FLAGS=-latomic
    -D WITH_FFMPEG=ON
    -D WITH_TBB=ON
    -D BUILD_TBB=ON
    -D WITH_GSTREAMER=ON
    -D WITH_V4L=ON
    -D WITH_LIBV4L=ON
    -D BUILD_NEW_PYTHON_SUPPORT=ON
    -D ENABLE_PRECOMPILED_HEADERS=ON
    -D OPENCV_GENERATE_PKGCONFIG=ON"


echo "DK-INFO>cmake flags: ${CMAKEFLAGS}"
cd ~/opencv
mkdir build
cd build
cmake ${CMAKEFLAGS} ..

echo "DK-INFO>Make"
make -j4

echo "DK-INFO>Make Install"
sudo make install


echo "DK-INFO>Done! Now do this command to finish installion = sudo ldconfig"
1
  • Thank you for the base script! Do you also have the CMakeLists.txt for the project so I can see the set(OpenCV_DIR ) as well? Dec 21 '20 at 16:36
0

You are certainly not going to install Windows (at least not in the 'full form') on a Raspberry. What you do is "wire together" your Visual Studio Community IDE on the windows computer to the raspberry via GDB/SSH.

The process I have followed is pretty much this. Yes, it titles ".net core" but it works for C++ as well. Interestingly enough, the C++ guide is not relevant to Linux.

0

Note you can apt-get install an awful lot of open-cv stuff. I just ran

apt search open-cv

And yes, C++ is the preferred way to use much of the open-cv material so you are ahead. No idea about IDEs on a pi (I use vim and terminals!)

-1

Have you installed openCV on your RPi yet? I have successfully built and installed openCV 4.4.0 on my RPi4B. Its now working well... and I am using C++ for writing programs to use openCV for motion detection.

Dave

1
  • 1
    Hello Dave. I'm new using Linux, and I installed OpenCV on the RPI but I'm not quite sure that I did it right, could you help me on how you installed OpenCV? Also, how do you write your c++ codes, do you use an IDE like QT or Codeblocks?
    – dmta24
    Sep 12 '20 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.