I've been trying to install the OpenCV2 libraries for Python 3 on my Raspberry PI 3B. I started this process by installing Python 3 through apt
and using pip3
to install OpenCV. However the process is rather slow and tends to hang up at times through the installation. It will normally free itself after a few hours, but after making some more progress it will throw and installation error. Yesterday I found a bash script that claimed to be able to install OpenCV on a Raspberry PI. I copied the script, debugged it, and ran it. It seemed to work fine until it reached the CMake build portion of the script. It hung up the build at 15% for several hours, it freed itself and continued building until it hit an internal compiler error at which point it aborted the installation. Below I have the bash script I was using to install OpenCV and the window output. I have no idea where to start debugging this, so any direction would be appreciated.
Installation Bash Script
# installOpenCV.sh
echo "OpenCV installation by learnOpenCV.com"
cvVersion="master"
# Clean build directories
rm -rf opencv/build
rm -rf opencv_contrib/build
# Create directory for installation
mkdir installation
mkdir installation/OpenCV-"$cvVersion"
# Save current working directory
cwd=$(pwd)
sudo apt -y update
sudo apt -y upgrade
sudo apt -y remove x264 libx264-dev
## Install dependencies
sudo apt -y install build-essential checkinstall cmake pkg-config yasm
sudo apt -y install git gfortran
sudo apt -y install libjpeg8-dev libjasper-dev libpng12-dev
sudo apt -y install libtiff5-dev
sudo apt -y install libtiff-dev
sudo apt -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt -y install libxine2-dev libv4l-dev
cd /usr/include/linux
sudo ln -s -f ../libv4l1-videodev.h videodev.h
cd $cwd
sudo apt -y install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt -y install libgtk2.0-dev libtbb-dev qt5-default
sudo apt -y install libatlas-base-dev
sudo apt -y install libmp3lame-dev libtheora-dev
sudo apt -y install libvorbis-dev libxvidcore-dev libx264-dev
sudo apt -y install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt -y install libavresample-dev
sudo apt -y install x264 v4l-utils
# Optional dependencies
# sudo apt -y install libprotobuf-dev protobuf-compiler
# sudo apt -y install libgoogle-glog-dev libgflags-dev
# sudo apt -y install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
# Install python
sudo apt -y install python3-dev python3-pip
sudo -H pip3 install -U pip numpy
sudo apt -y install python3-testresources
cd $cwd
# Install virtual environment
python3 -m venv OpenCV-"$cvVersion"-py3
echo "# Vitual Environment Wrapper" >> ~/.bashrc
echo "alias workoncv-$cvVersion=\source $cwd/OpenCv-$cvVersion-py3/bin/activate" >> ~/.bashrc
source "$cwd"/OpenCV-"$cvVersion"-py3/bin/activate
################### For Python 3 ########################
Now install python libararies wihin this virtaul environment\
sudo sed -i 's/CONF_SWAPSIZE=100/CONF_SWAPSIZE=1024/g' /etc/dpyhs-swapfile
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
pip install numpy dlib
quit vitual environment
deactivate
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout $cvVersion
cd ..
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout $cvVersion
echo $cwd
cd $cwd/opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D BUIL_opencv_python3=yes \
-D CMAKE_INSTALL_PREFIX=$cwd/installation/OpenCV \
-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 ..
make -j$(nproc)
make install
Terminal Output
Scanning dependencies of target opencv_test_core
[ 59%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/ocl/test_arithm.cpp.o
[ 59%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/ocl/test_channels.cpp.o
[ 59%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/ocl/test_dft.cpp.o
during GIMPLE pass: dom
In file included from /home/pi/Documents/OpenCVInstaller/opencv/modules/ts/include/opencv2/ts.hpp:125,
from /home/pi/Documents/OpenCVInstaller/opencv/modules/core/test/ocl/../test_precomp.hpp:7,
from /home/pi/Documents/OpenCVInstaller/opencv/modules/core/test/ocl/test_arithm.cpp:42:
/home/pi/Documents/OpenCVInstaller/opencv/modules/ts/include/opencv2/ts/ts_gtest.h: In member function ‘bool testing::internal::CartesianProductGenerator4<T1, T2, T3, T4>::Iterator::AtEnd() const [with T1 = std::pair<perf::{anonymous}::MatDepth, perf::{anonymous}::MatDepth>; T2 = cvtest::ocl::Channels; T3 = int; T4 = bool]’:
/home/pi/Documents/OpenCVInstaller/opencv/modules/ts/include/opencv2/ts/ts_gtest.h:16171:10: internal compiler error: Illegal instruction
bool AtEnd() const {
^~~~~
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [modules/core/CMakeFiles/opencv_test_core.dir/build.make:63: modules/core/CMakeFiles/opencv_test_core.dir/test/ocl/test_arithm.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
during GIMPLE pass: slp
during GIMPLE pass: ivopts
In member function ‘virtual void opencv_test::ocl::Dft_Mat_Test::Body()’:
cc1plus: internal compiler error: in gimplify_expr, at gimplify.c:11391
In static member function ‘static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = const testing::internal::linked_ptr<testing::internal::ParameterizedTestCaseInfo<opencv_test::ocl::ExtractChannel>::TestInfo>*; _ForwardIterator = testing::internal::linked_ptr<testing::internal::ParameterizedTestCaseInfo<opencv_test::ocl::ExtractChannel>::TestInfo>*; bool _TrivialValueTypes = false]’:
cc1plus: internal compiler error: in gimplify_expr, at gimplify.c:11391
during GIMPLE pass: ifcombine
In static member function ‘static cv::GMetaArgs cv::detail::MetaHelper<K, std::tuple<_Elements ...>, Out>::getOutMeta(const GMetaArgs&, const GArgs&) [with K = cv::gapi::core::GDivRC; Ins = {cv::GScalar, cv::GMat, double, int}; Out = cv::GMat]’:
cc1plus: internal compiler error: in gimplify_expr, at gimplify.c:11391
0x76a43717 __libc_start_main
/build/glibc-FUvrFr/glibc-2.28/csu/libc-start.c:308
0x76a41717 __libc_start_main
/build/glibc-FUvrFr/glibc-2.28/csu/libc-start.c:308
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
0x76a88717 __libc_start_main
/build/glibc-FUvrFr/glibc-2.28/csu/libc-start.c:308
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-8/README.Bugs> for instructions.
See <file:///usr/share/doc/gcc-8/README.Bugs> for instructions.
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-8/README.Bugs> for instructions.
make[2]: *** [modules/core/CMakeFiles/opencv_test_core.dir/build.make:89: modules/core/CMakeFiles/opencv_test_core.dir/test/ocl/test_dft.cpp.o] Error 1
[ 59%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/ocl/goclkernel.cpp.o
[ 59%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/ocl/goclimgproc.cpp.o
make[2]: *** [modules/core/CMakeFiles/opencv_test_core.dir/build.make:76: modules/core/CMakeFiles/opencv_test_core.dir/test/ocl/test_channels.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:2784: modules/core/CMakeFiles/opencv_test_core.dir/all] Error 2
make[2]: *** [modules/gapi/CMakeFiles/opencv_gapi.dir/build.make:674: modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/fluid/gfluidcore.cpp.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[2]: *** Waiting for unfinished jobs....
/home/pi/Documents/OpenCVInstaller/opencv/modules/gapi/src/backends/ocl/goclkernel.cpp: In member function ‘const cv::UMat& cv::GOCLContext::inMat(int)’:
/home/pi/Documents/OpenCVInstaller/opencv/modules/gapi/src/backends/ocl/goclkernel.cpp:14:34: internal compiler error: in gimplify_expr, at gimplify.c:11391
return (inArg<cv::UMat>(input));
^
0x76b34717 __libc_start_main
/build/glibc-FUvrFr/glibc-2.28/csu/libc-start.c:308
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-8/README.Bugs> for instructions.
make[2]: *** [modules/gapi/CMakeFiles/opencv_gapi.dir/build.make:700: modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/ocl/goclkernel.cpp.o] Error 1
/home/pi/Documents/OpenCVInstaller/opencv/modules/gapi/src/backends/ocl/goclimgproc.cpp: In function ‘cv::gapi::GKernelPackage cv::gapi::imgproc::ocl::kernels()’:
/home/pi/Documents/OpenCVInstaller/opencv/modules/gapi/src/backends/ocl/goclimgproc.cpp:295:11: internal compiler error: in gimplify_expr, at gimplify.c:11391
>();
^
0x76acd717 __libc_start_main
/build/glibc-FUvrFr/glibc-2.28/csu/libc-start.c:308
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-8/README.Bugs> for instructions.
make[2]: *** [modules/gapi/CMakeFiles/opencv_gapi.dir/build.make:713: modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/ocl/goclimgproc.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:17223: modules/gapi/CMakeFiles/opencv_gapi.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
[ 4%] Built target libwebp
[ 5%] Built target libopenjp2
[ 8%] Built target IlmImf
[ 10%] Built target libprotobuf
[ 11%] Built target quirc
[ 11%] Built target ittnotify
[ 12%] Built target ade
[ 12%] Built target opencv_videoio_plugins
[ 15%] Built target opencv_core
[ 17%] Built target opencv_imgproc
[ 18%] Built target opencv_imgcodecs
[ 19%] Built target opencv_videoio
[ 20%] Built target opencv_highgui
[ 21%] Built target opencv_ts
[ 21%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/ocl/test_arithm.cpp.o
In file included from /home/pi/Documents/OpenCVInstaller/opencv/modules/ts/include/opencv2/ts.hpp:18,
from /home/pi/Documents/OpenCVInstaller/opencv/modules/core/test/ocl/../test_precomp.hpp:7,
from /home/pi/Documents/OpenCVInstaller/opencv/modules/core/test/ocl/test_arithm.cpp:42:
/home/pi/Documents/OpenCVInstaller/opencv/modules/core/test/ocl/test_arithm.cpp: In member function ‘virtual void opencv_test::ocl::Lut_Mat_Test::TestBody()’:
/home/pi/Documents/OpenCVInstaller/opencv/modules/core/include/opencv2/core/utils/trace.hpp:164:82: internal compiler error: in gimplify_expr, at gimplify.c:11391
const CV_TRACE_NS::details::Region __region_fn(CV__TRACE_LOCATION_VARNAME(fn));
^
/home/pi/Documents/OpenCVInstaller/opencv/modules/ts/include/opencv2/ts/ts_ext.hpp:37:8: note: in expansion of macro ‘CV__TRACE_APP_FUNCTION_NAME’
CV__TRACE_APP_FUNCTION_NAME(name); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/Documents/OpenCVInstaller/opencv/modules/ts/include/opencv2/ts/ts_ext.hpp:158:72: note: in expansion of macro ‘CV__TEST_BODY_IMPL’
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() BODY_IMPL( #test_case_name "_" #test_name ) \
^~~~~~~~~
/home/pi/Documents/OpenCVInstaller/opencv/modules/ts/include/opencv2/ts/ts_ext.hpp:162:43: note: in expansion of macro ‘CV__TEST_P’
#define TEST_P(test_case_name, test_name) CV__TEST_P(test_case_name, test_name, Body, CV__TEST_BODY_IMPL)
^~~~~~~~~~
/home/pi/Documents/OpenCVInstaller/opencv/modules/ts/include/opencv2/ts/ocl_test.hpp:367:20: note: in expansion of macro ‘TEST_P’
#define OCL_TEST_P TEST_P
^~~~~~
/home/pi/Documents/OpenCVInstaller/opencv/modules/core/test/ocl/test_arithm.cpp:99:1: note: in expansion of macro ‘OCL_TEST_P’
OCL_TEST_P(Lut, Mat)
^~~~~~~~~~
0x76b2f717 __libc_start_main
/build/glibc-FUvrFr/glibc-2.28/csu/libc-start.c:308
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-8/README.Bugs> for instructions.
make[2]: *** [modules/core/CMakeFiles/opencv_test_core.dir/build.make:63: modules/core/CMakeFiles/opencv_test_core.dir/test/ocl/test_arithm.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:2784: modules/core/CMakeFiles/opencv_test_core.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
pi@raspberrypi:~/Documents/OpenCVInstaller $
sudo apt install gcc
andsudo apt install g++
both result in an "is already the newest version (4:8.3.0-1+rpi2)" message, so I should be up to date.