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!

  • What operating system do you use? Why isn't it an option to you use opencv from the default software repository if you use Raspbian? – Ingo Sep 1 '19 at 8:09
  • I had a similar problem on a RPi 3 and I had to lower the number of threads (-jX) and everything went well. Maybe it can be useful to you. – Ephemeral Sep 1 '19 at 12:25
  • @Ephemeral I wish that worked. I changed make to make -j1 and it still errored out at 48%. Any other thoughts? – greyBow Sep 1 '19 at 17:22
  • @greyBow, and without -j maybe ? just make ? (I know that for my case the compilation took a very long time) I think It' s a 'thread' synchronization problem , then without -j we force thread sync. I seem to have thought like this during the same problem – Ephemeral Sep 1 '19 at 22:01
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!

| improve this answer | |
0

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

| improve this answer | |
0

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.

| improve this answer | |

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.