Python 导入错误:没有名为 cv2 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32662393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: No module named cv2
提问by Shatil Haque
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('1.jpg',0)
orb = cv2.ORB()
kp = orb.detect(img,None)
kp, des = orb.compute(img, kp)
img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
plt.imshow(img2),plt.show()
In here, I have installed numpy and opencv in my windows operating system. But i can't find out the proper way to add cv2 module.
在这里,我在我的 Windows 操作系统中安装了 numpy 和 opencv。但我找不到添加 cv2 模块的正确方法。
回答by 101
The easiest way to install OpenCV on Windows is to simply copy the cv2.pyd
file into Python's site-packages
directory (e.g. C:\python27\Lib\site-packages
).
在 Windows 上安装 OpenCV 的最简单方法是简单地将cv2.pyd
文件复制到 Python 的site-packages
目录中(例如C:\python27\Lib\site-packages
)。
To get the cv2.pyd
file, download and extract the latest version of the OpenCV installation executable from http://sourceforge.net/projects/opencvlibrary/files/opencv-win/and browse the extracted folder to find the file in the relevant build
directory (e.g. build\python\x86\2.7
).
要获取该cv2.pyd
文件,请从http://sourceforge.net/projects/opencvlibrary/files/opencv-win/下载并解压最新版本的 OpenCV 安装可执行文件,然后浏览解压的文件夹以在相关build
目录中找到该文件(例如build\python\x86\2.7
)。
回答by Lukasz Czerwinski
The fastest and cleanest way is to run pip
. It's a clean convenient tool for Python packages.
最快最干净的方法是运行pip
。这是一个干净方便的 Python 包工具。
Just run:
赶紧跑:
pip install opencv-python
or C:\Python27\Scripts\pip.exe install opencv-python
pip install opencv-python
或者 C:\Python27\Scripts\pip.exe install opencv-python