Python安装使用VideoCapture类

来源:互联网 发布:固定资产登记软件 编辑:程序博客网 时间:2024/06/08 12:36
Python使用摄像头需要使用VideoCapture类,本机使用的是Python2.7.14,测试的时候使用pip install的时候无法成功,会有如下返回:

这里写图片描述

这时候可以使用:(https://www.lfd.uci.edu/~gohlke/pythonlibs/)

打开地址之后直接Ctrl+f 搜索VideoCapture然后找到对应系统的文件,点击下载,会下载一个whl后缀的文件。然后在使用pip install 文件地址+下载的文件名的格式安装VideoCapture,比如我下载的文件名是VideoCapture-0.9.5-cp27-none-win_amd64.whl,所放在的文件目录是D:\Download,所以我的命令是

pip install D:\Download\VideoCapture-0.9.5-cp27-none-win_amd64.whl

这里写图片描述
就可以正确安装了。
安装完成之后开始我们的第一个小程序。

from VideoCapture import Devicecam = Device()cam.saveSnapshot('1.jpg')

执行后竟然有报错

这里写图片描述

从Traceback上看init.py中调用了fromstring这个方法,但是这个方法直接返回

def fromstring(*args, **kw):    raise NotImplementedError("fromstring() has been removed. " +                              "Please call frombytes() instead.")

所以也就是调用了就会返回错误,只能修改VideoCapture中的init.py提示错误的语句:

im = Image.fromstring(                'RGB', (width, height), buffer, 'raw', 'BGR', 0, -1)

将 fromstring修改为frombytes,然后在去运行程序,正确返回,生成图片,搞定!!

原创粉丝点击