用anaconda直接安装的opencv库,在调用cv2.namedWindow()时会报错。
cv2.error: /tmp/build/80754af9/opencv_1512687413662/work/modules/highgui/src/window.cpp:593: 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 cvNamedWindow
搜索问题后发现原因是conda安装的opencv是阉割版的,详情可见https://blog.csdn.net/aaon22357/article/details/81913465
不能实现视频和摄像头的读取功能。解决方案网上大多给出的是卸载conda的opencv,然后手动编译安装opencv,但是我是先安装的anaconda,在编译opencv时出现很多问题,导致编译失败,之后在知乎上看到对应的解决方案,非常方便,详情见https://www.zhihu.com/question/263917089
conda remove opencv
conda install -c menpo opencv
pip install --upgrade pip
pip install opencv-contrib-python
之后问题解决。