Python 没有名为“cv2”的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47450179/
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
No module named 'cv2'
提问by solo
After spending hours trying out others' suggestions, I still can't get OpenCV to work. I'd like to build a Python script that checks an image's/PDF's color at a certain area (it's for a printing company to verify that documents have a 0.5mm white border, as this is their machine's preferred format). That said, I'm planning on using OpenCV's color detection capabilities to set an RGB tolerance for a document's contours.
在花了几个小时尝试其他人的建议后,我仍然无法让 OpenCV 工作。我想构建一个 Python 脚本来检查某个区域的图像/PDF 的颜色(供印刷公司验证文档是否有 0.5 毫米的白色边框,因为这是他们机器的首选格式)。也就是说,我计划使用 OpenCV 的颜色检测功能来设置文档轮廓的 RGB 容差。
I've tried installing OpenCV with brew
, brew install homebrew/science/
, sudo pip
, sudo pip3
, pip
and pip3
, but I keep getting the following error:
我试过用brew
, brew install homebrew/science/
, sudo pip
, sudo pip3
,pip
和安装 OpenCV pip3
,但我不断收到以下错误:
ModuleNotFoundError: No module named 'cv2'
What confuses me most is that it seems I've successfully installed OpenCV when I enter pkg-config opencv --cflags
in terminal:
最让我困惑的是,当我进入pkg-config opencv --cflags
终端时,我似乎已经成功安装了 OpenCV :
-I/usr/local/Cellar/opencv/3.3.1_1/include/opencv -I/usr/local/Cellar/opencv/3.3.1_1/include
Is the wrapper no longer supporter for Python 3.6? If so, where could I get a similar package?
包装器是否不再支持 Python 3.6?如果是这样,我在哪里可以获得类似的包裹?
Here's what I'm working with so far:
到目前为止,这是我正在使用的内容:
import cv2
import numpy as np
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
contours,_ = cv2.findContours(img, cv2.RETR_LIST, cv2.cv.CV_CHAIN_APPROX_NONE)
lst_intensites = [(255, 255, 255)]
for i in range(len(contours)):
cimg = np.zeros_like(img)
cv2.drawContours(cimg, contours, i, color=255, thickness=-1)
pts = np.where(cimg == 255)
lst_intensities.append(img[pts[0], pts[1]])
回答by X_Stark
Well I was also facing the same issue today but I finally installed it in Anaconda and it's working fine:
好吧,我今天也遇到了同样的问题,但我终于将它安装在 Anaconda 中,并且运行良好:
conda install -c conda-forge opencv
conda install -c conda-forge/label/broken opencv
source:Opencv Installation
来源:Opencv安装
Happy Coding:)
快乐编码:)
回答by DingDong
On Windows, you can install with pip:
在 Windows 上,您可以使用 pip 安装:
pip install opencv-python
回答by u5492179
On Ubuntu, you can install the opencv
depends like:
在 Ubuntu 上,您可以安装以下opencv
依赖项:
sudo apt-get install python-opencv
or install it with pip ( pyhon package management tools ):
或使用 pip ( pyhon 包管理工具) 安装它:
pip install opencv
Refer to similar questions OpenCV - cannot find module cv2.
参考类似问题OpenCV - 找不到模块 cv2。