我在运行$ sudo apt-get install python-opencv
的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
你能帮我吗?
答案 0 :(得分:3)
您应该导入cv2
而不是opencv
,也没有highgui
。您可能需要查看docs
答案 1 :(得分:1)
要安装opencv for python,您需要命令
$ pip install opencv-python
要导入它以便在应用程序中使用,调用包的导入是
import cv2