ubuntu anaconda opencv问题

在ubuntu16.04上使用opencv3时, 发现视频与imshow函数无法使用,经查资料发现 安装opencv时采用的简易的安装方法,没有编译opencv的源码。

因此会出现以上问题。

下载源码进行编译不断报错

最后卸载了anaconda后,编译opencv成功。

卸载anaconda: 先删除anaconda的整个文件夹,再删除path。(sudo nano ~/.bashrc)

具体编译方法见

http://www.cnblogs.com/farewell-farewell/p/6125761.html

其中cmake 为:

cmake     \
-D CMAKE_BUILD_TYPE=DEBUG -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2 \
-D WITH_CUDA=ON -D WITH_CUBLAS=ON -D CUDA_FAST_MATH=ON \
-D WITH_CUFFT=ON -D WITH_NVCUVID=ON -D WITH_V4L=ON \
-D WITH_LIBV4L=ON -D WITH_OPENGL=ON -D WITH_FFMPEG=ON \
-D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D BUILD_PYTHON_SUPPORT=ON ..

 附:卸载并重新安装opencv的方法 http://blog.csdn.net/sinat_21258931/article/details/61195530

        编译完后的path设置和测试可见  http://blog.csdn.net/obsession2015/article/details/56665884

编译完后运行出错:

/usr/bin/ld: 找不到 -lImath
/usr/bin/ld: 找不到 -lIlmImf
/usr/bin/ld: 找不到 -lIex
/usr/bin/ld: 找不到 -lHalf
/usr/bin/ld: 找不到 -lIlmThread

经查证,这几个都是3rdparty/openexr中的库,因此 猜想在cmake中应加上编译该库应该就可以了。

(cmake编译时各个参数见 http://m.blog.csdn.net/skykingf/article/details/78036738)

重新尝试,cmake变为:

cmake     \
-D CMAKE_BUILD_TYPE=DEBUG     -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2    \
-D WITH_CUDA=ON     -D WITH_CUBLAS=ON     -D CUDA_FAST_MATH=ON    \
-D WITH_CUFFT=ON     -D WITH_NVCUVID=ON     -D WITH_V4L=ON     \
-D WITH_LIBV4L=ON     -D WITH_OPENGL=ON     -D WITH_FFMPEG=ON   \
-D INSTALL_C_EXAMPLES=ON     -D BUILD_EXAMPLES=ON  -D BUILD_PYTHON_SUPPORT=ON -D BUILD_OPENEXR=ON .. 

最后,果然解决了以上问题,但是在测试cmake . 时出现如下错误:

CMake Error at CMakeLists.txt:10 (find_package):
  By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "OpenCV", but
  CMake did not find one.

  Could not find a package configuration file provided by "OpenCV" with any
  of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake

  Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
  "OpenCV_DIR" to a directory containing one of the above files.  If "OpenCV"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
See also "/home/godzilla/opencv-3.2.0/samples/cpp/example_cmake/CMakeFiles/CMakeOutput.log".

解决方法为:在samples/cpp/example_cmake/中的CMakeLists.txt中增加如下语句:

set(OpenCV_DIR /home/godzilla/opencv-3.2.0/build)
#后面路径为  opencv安装路径下的build

然后,运行成功!终于!!!(耗了2天了,期间卸载重装无数回)

最后就可以将opencv添加到python:在build下在lib目录中找到cv2.so文件,复制到python的site-packages文件夹中即可

sudo cp cv2.so /usr/local/lib/python2.7/site-packages/

然后测试,仍无法打开摄像头,与之前的情况相同,再次查询原因,发现如下解决方法:http://blog.csdn.net/chenhezhuyan/article/details/23384637

于是又卸载了opencv,再来一次!!!

卸载后,先安装如下库(以下为我需要安装的,完整版请看原文):

sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev

sudo apt-get install libxine2-ffmpeg libxine2-bin libxine2

sudo apt-get install libunicap2 libunicap2-dev

sudo apt-get install libdc1394-utils

sudo apt-get install swig 

 装完后将cv2移至python文件夹后,重启电脑后。发现python import cv2报错了!!!!!崩溃。。。。

决定先安装anaconda吧。

bash Anaconda2-4.0.0-Linux-x86.sh

添加path后记得

source .bashrc

 

posted @ 2019-03-26 20:09  Not-Bad  阅读(931)  评论(0编辑  收藏  举报