源编译的OpenCV在Google Colab上崩溃,没有任何错误消息

时间:2019-07-04 15:09:49

标签: python c++ opencv google-colaboratory

我正在尝试从源代码在Google Colab上编译OpenCV。我的脚本如下:

!pip3 uninstall -y opencv_python
!pip2 uninstall -y opencv_python
!apt purge --remove libopencv-dev
!apt-get install build-essential cmake unzip pkg-config libjpeg-dev libpng-dev libtiff-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libx265-dev libgtk-3-dev libatlas-base-dev gfortran python3-dev checkinstall libeigen3-dev ccache
%cd /content
!mkdir opencv
%cd opencv
!wget https://github.com/opencv/opencv/archive/4.1.0.zip
!unzip -qq 4.1.0.zip
!git clone https://github.com/opencv/opencv_contrib.git 
%cd opencv-4.1.0
!mkdir build
%cd build
!cmake -DCPU_BASELINE_REQUIRE=SSE4_1,SSE4_2,AVX,FP16,AVX2,AVX512_SKX -DPYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 -DCMAKE_BUILD_TYPE=Release -DOPENCV_EXTRA_MODULES_PATH=/content/opencv/opencv_contrib/modules -DOPENCV_ENABLE_NONFREE=ON -DOPENCV_GENERATE_PKGCONFIG=ON -DENABLE_CCACHE=ON -DWITH_TBB=ON  -DWITH_EIGEN=ON -DWITH_CUDA=ON -DWITH_CUFFT=ON -DCUDA_ARCH_BIN=75 -DBUILD_opencv_cudacodec=OFF -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_JAVA=OFF -DBUILD_opencv_js=OFF -DBUILD_opencv_ts=OFF ..
!make -j2
!make install

所有内容均可成功编译并安装。我可以使用pkg-config检查OpenCV版本和已安装的文件。但是当我尝试在Python或C ++中使用任何OpenCV函数时,它就会崩溃。

此Python代码使VM崩溃并重新启动:

import cv2

任何带有OpenCV功能的C ++代码都将退出,而不会显示任何错误消息:

#include <iostream>
#include "opencv2/highgui.hpp"
#include <opencv2/core/utility.hpp>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
   try
   {   
         waitKey(1);
   }
   catch( const cv::Exception& e )
   {
         cerr << "exception caught: " << e.what() << endl;
   }

    cout<<"hello"<<endl;
    return 0;
}

我尝试禁用CUDA,将运行时类型更改为None而不是GPU,但是没有任何方法可以解决该问题。 ldd正确打印每个依赖项,而valgrind --leak-check=yes executable给出this output

有人可以在这里检测到问题吗?

0 个答案:

没有答案