python 2.7 linux cv2,【Linux】【Opencv】【Python】安装opencv以及无法使用cv2.imshow()解决办法(Ubuntu14.04)...
------【2017.07.14 更新】-------------------------------------------------------
安装opencv3每次cmake都要下载3rdparty,下载很慢还总失败。附上自行下载链接及解决办法:
opencv3.2也可以去官网下载。
先解压缩opencv3.2
cd opencv-3.2.0/3rdparty/ippicv
mkdir unpack
然后解压缩ippicv_linux_20151201.tgz
将解压后的目录mv到unpack目录中
替换ippicv目录中downloader.cmake文件内容为:
#
# The script downloads ICV package
#
# On return this will define:
# OPENCV_ICV_PATH - path to unpacked downloaded package
#
function(_icv_downloader)
# Commit SHA in the opencv_3rdparty repo
set(IPPICV_BINARIES_COMMIT "81a676001ca8075ada498583e4166079e5744668")
# Define actual ICV versions
if(APPLE)
set(OPENCV_ICV_PACKAGE_NAME "ippicv_macosx_20151201.tgz")
set(OPENCV_ICV_PACKAGE_HASH "4ff1fde9a7cfdfe7250bfcd8334e0f2f")
set(OPENCV_ICV_PLATFORM "macosx")
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_osx")
elseif(UNIX)
if(ANDROID AND NOT (ANDROID_ABI STREQUAL x86 OR ANDROID_ABI STREQUAL x86_64))
return()
endif()
set(OPENCV_ICV_PACKAGE_NAME "ippicv_linux_20151201.tgz")
set(OPENCV_ICV_PACKAGE_HASH "808b791a6eac9ed78d32a7666804320e")
set(OPENCV_ICV_PLATFORM "linux")
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_lnx")
elseif(WIN32 AND NOT ARM)
set(OPENCV_ICV_PACKAGE_NAME "ippicv_windows_20151201.zip")
set(OPENCV_ICV_PACKAGE_HASH "04e81ce5d0e329c3fbc606ae32cad44d")
set(OPENCV_ICV_PLATFORM "windows")
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_win")
else()
return() # Not supported
endif()
set(OPENCV_ICV_UNPACK_PATH "${CMAKE_CURRENT_LIST_DIR}/unpack")
set(OPENCV_ICV_PATH "${OPENCV_ICV_UNPACK_PATH}${OPENCV_ICV_PACKAGE_SUBDIR}")
message(STATUS "ICV: Package successfully downloaded")
set(OPENCV_ICV_PATH "${OPENCV_ICV_PATH}" PARENT_SCOPE)
endfunction()
_icv_downloader()
然后就可以正常cmake,make,make install 了
-----------------------------------------------------------------------------------------------------------------------------------------
提示错误:
cv2.error: /io/opencv/modules/highgui/src/window.cpp:583: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage
这个问题真是。。RLGL。。。
依赖包我就不说了,安装好就是了。特别是libgtk2.0-dev和pkg-config。
简单说一下怎么手动安装opencv2吧
先去官网http://opencv.org/
点release
下载opencv-2.4.13的source源码包
unzip opencv-2.4.13.zip
cd opencv-2.4.13/
cmake -D WITH_GTK=ON -D CMAKE_INSTALL_PREFIX=/usr/local .
make
sudo make install
新安装的opencv在/usr/local/include/目录里
这时候找cv2.so
可能在/usr/local/lib/python2.7/site-packages/ 目录里
也可能在/usr/local/lib/python2.7/dist-packages/ 目录里
第一种情况将cv2.so复制到/usr/lib/python2.7/site-packages/目录里
第二种情况复制到/usr/lib/python2.7/dist-packages/目录里
好了!!!最坑爹的来了,正常这样操作后就没问题了啊。
如果你运行代码不再提示错误可以无视下面的内容。
还出问题的小伙伴们看一看/usr/local/lib/python2.7/site-packages/或者/usr/local/lib/python2.7/dist-packages/目录下是不是有个名字为cv2的文件夹
删掉它!问题就解决了。
来来回回重新安装了一下午的opencv,崩溃的要死!