ImportError:在Ubuntu 14.04中安装python-opencv后没有名为opencv的模块

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (172)

我在python中安装opencv并运行$ sudo apt-get install python-opencv并成功安装。但是在运行此代码时

import opencv
import opencv.highgui
import time
import commands

def get_image():
    image = opencv.highgui.cvQueryFrame(camera)
    return opencv.adaptors.Ipl2PIL(image)

camera = opencv.highgui.cvCreateCameraCapture(-1)

while 1:
    image = get_image()
    image.thumbnail((32, 24, ))
    image = tuple(ord(i) for i in image.tostring())
    x = int((int((max(image) / 256.0) * 10) + 1) ** 0.5 / 3 * 10)
    cmd = ("sudo su -c 'echo " + str(x) +
        " > /sys/devices/virtual/backlight/acpi_video0/brightness'")
    status, output = commands.getstatusoutput(cmd)
    assert status is 0

得到了关注错误

$ python bright.py 
Traceback (most recent call last):
  File "bright.py", line 1, in <module>
    import opencv
ImportError: No module named opencv

你可以帮我吗?

提问于
用户回答回答于
用户回答回答于

要安装opencv for python,您需要命令 $ pip install opencv-python 要导入它以便在应用程序中使用导入来调用包 import cv2

扫码关注云+社区

领取腾讯云代金券