2

I've been trying to install OpenCV on my RaspBerry Pi 4 using:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
            -D CMAKE_INSTALL_PREFIX=$cwd/installation/OpenCV-"$cvVersion" \
            -D INSTALL_C_EXAMPLES=ON \
            -D INSTALL_PYTHON_EXAMPLES=ON \
            -D WITH_TBB=ON \
            -D WITH_V4L=ON \
            -D OPENCV_PYTHON3_INSTALL_PATH=$cwd/OpenCV-$cvVersion-py3/lib/python3.5/site-packages \
        -D WITH_QT=ON \
        -D WITH_OPENGL=ON \
        -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
        -D BUILD_EXAMPLES=ON ..

This completes successfully but when I then run make -j$(nproc) I am getting the error **make: [Makefile:163: all] Error 2** Here are the last few lines of install before the error.

[ 36%] Building CXX object modules/cvv/CMakeFiles/opencv_cvv.dir/src/view/singlefilterview.cpp.o

[ 36%] Building CXX object modules/cvv/CMakeFiles/opencv_cvv.dir/src/view/translationsmatchview.cpp.o

[ 36%] Building CXX object modules/cvv/CMakeFiles/opencv_cvv.dir/opencv_cvv_autogen/mocs_compilation.cpp.o

[ 36%] Linking CXX shared library ../../lib/libopencv_cvv.so

[ 36%] Built target opencv_cvv

make: *** [Makefile:163: all] Error 2

What is going wrong? I've been following this guide exactly so I'm not sure what's wrong. https://www.learnopencv.com/install-opencv-4-on-raspberry-pi/ Thank you!

greyBow
  • 121
  • 1
  • 4

3 Answers3

2

From here, Willprice user say exaclty what I say in the comment :

OpenCV builds can sometimes fail due to using too many threads, try running make instead of make -j $(nproc)

or

Make sure to increase your swap file size!

Ephemeral
  • 2,167
  • 1
  • 8
  • 19
1

It would be easier to install using pip and python3 with the command sudo apt install python3-opencv. It works for me every time and it installs the latest version of opencv

Atia
  • 21
  • 2
1

I would try installing with the command

sudo apt-get install python3-opencv #For python3
sudo apt-get install python-opencv #For python2

and if that doesn't work, compile it from source with this script

Read the comments from the gists, they solve some problems that you might encounter.