PyCharm下配置Opencv
- Opencv下载地址:
https://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.2.0/opencv-3.2.0-vc14.exe/download - 找到D:\Opencv\opencv\build\python\2.7\x64文件下cv2.pyd文件,将其复制到Anaconda文件夹下D:\Anaconda27\Lib\site-packages这个路径中即可
- 运行下述代码
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('F:/1.jpg')
color = ('b','g','r')
for i,col in enumerate(color):
histr = cv2.calcHist([img], [i], None, [256], [0, 256])
plt.plot(histr, color = col)
plt.xlim([0, 256])
plt.show()
表示配置成功
- 注:出现下述错误:
DLL load failed错误表明使用了位数不同的包,即64位电脑使用的是32位的opencv包,这时将opencv 路径下D:\Opencv\opencv\build\python\2.7\x64\cv2.pyd拷贝到D:\Anaconda27\Lib\site-packages路径下即可,注意选择x64而不是x86
再运行一次,问题应该就解决了!