使用python做一些图像有关的工作时,除了PIL库,OpenCV也是更好的工具
使用cv2的im.read读取图片
import cv2
# 读取一张照片
img = cv2.imread('2.jpg',cv2.IMREAD_GRAYSCALE)
在打印图片的时候
cv2.imshow('image',img)
出现error
OpenCV(4.2.0)
C:\projects\opencv- python\opencv\modules\highgui\src\window.cpp:651:
error: (-2:Unspecified error) The function is not implemented. Rebuild
the library with Windows, GTK+ 2.x or Cocoa 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’
解决办法
安装opencv-contrib-python模块即可
pip install opencv-contrib-python
出错,大概率是因为下载太慢的原因
使用镜像
pip install opencv-contrib-python -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
还是出错
提示
Consider using the
--useroption or check the permissions.
这是pip社区的一些问题
要我们加--user
pip install --user opencv-contrib-python -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
终于成功
Installing collected packages: opencv-contrib-python Successfully
installed opencv-contrib-python-4.2.0.34
我们来看一看pip出什么问题了
pip is being invoked by an old script wrapper. This will fail in a
future version of pip. Please see
https://github.com/pypa/pip/issues/5599 for advice on fixing the
underlying issue. To avoid this problem you can invoke Python with ‘-m
pip’ instead of running pip directly.
pip出了一点问题!见这篇文章
https://www.cnblogs.com/qumogu/p/12487115.html
PS:常用镜像源
国内常用pip源如下:
阿里云 http://mirrors.aliyun.com/pypi/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
使用时,直接加-I url即可,如果有报错说网站不可信任,根据提示加上 --trusted-host *** 即可。
pip install XXX -i http://mirrors.aliyun.com/pypi/simple/