[英]Installing opencv2 in Docker for Raspberry Pi (new OS image Bullseye)
[英]How do I deal with an internal compiler error (cc1plus: gimplify) when installing c based python libraries (OpenCV2) on a Raspberry PI?
我一直在嘗試在我的 Raspberry PI 3B 上安裝適用於 Python 3 的 OpenCV2 庫。 我通過apt
安裝 Python 3 並使用pip3
安裝 OpenCV 來開始這個過程。 然而,該過程相當緩慢,並且在安裝過程中有時會掛斷。 它通常會在幾個小時后自行釋放,但在取得更多進展后,它會拋出和安裝錯誤。 昨天我發現了一個 bash 腳本,聲稱可以在 Raspberry PI 上安裝 OpenCV。 我復制了腳本,調試了它,然后運行了它。 在到達腳本的 CMake 構建部分之前,它似乎工作正常。 它以 15% 的速度掛起構建幾個小時,它釋放自己並繼續構建,直到遇到內部編譯器錯誤,此時它中止安裝。 下面是我用來安裝 OpenCV 和窗口輸出的 bash 腳本。 我不知道從哪里開始調試這個,所以任何方向將不勝感激。
# 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
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 $
在樹莓派 3 B 上編譯 OpenCV 也出現了類似的錯誤,是因為交換空間小,所以一定要增加交換空間:
停止交換
sudo dphys-swapfile swapoff
增加CONF_SWAPSIZE
中/etc/dphys-swapfile
512( CONF_SWAPSIZE=512
)以上。
開始交換:
sudo dphys-swapfile swapon
我在安裝 openCV 時也遇到了同樣的問題,我再次重新安裝了 Raspbian,但這一次,我只是安裝了一些 lib,而不是你提到的所有這些。 實際上rpi沒有強大的cpu,並且您需要sd卡的所有有限空間,因此請嘗試安裝您真正需要的東西
在使用 python3 安裝最新版本的 pip 后,我來安裝
python -m pip install numpy
python -m pip install scipy
python -m pip install matplotlib
然后pip install opencv-python
和pip install opencv-contrib-python
,它碰巧發生了一個問題,所以請確保釋放 rpi 的所有資源。
如果缺少任何庫,請嘗試一個一個地安裝它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.