繁体   English   中英

使用picamera和python脚本进行运动跟踪

[英]Motion tracking using picamera and python script

我正在使用和修改 Python脚本以进行简单的运动跟踪。 不幸的是,我遇到了捕获原始图像以使运动基本停止的功能的问题。

def captureTestImage():
count[0] = count[0] + 1
command = "raspistill -w %s -h %s -e bmp -o %s%s" % (100, 75, filepath, filenamePrefix)   
imageData = StringIO.StringIO()
imageData.write(subprocess.check_output(command, shell=True))
imageData.seek(0)
im = Image.open(imageData)
buffer = im.load()
imageData.close()
return im, buffer

上面的函数到达行时变得有问题

im = Image.open(imageData)

从理论上讲,这行代码将字节写入imageData并将其转换回可用的图像文件。 但是,在imageData上调用Image.open时,我收到一条错误消息,指出无法将字节数组强制转换为图像。 我的理解是subprocess.check_output返回返回值的字节表示形式(假设有一个)。 显然不是这种情况,但是我不知道如何将字节文件(imageData)转换回实际的图像文件。 到目前为止,我已经使用了io.ByteIO,但这给了我与StringIO相同的问题。

我已经稍微修改了此函数,由于传递了一个参数(-t 0),命令(raspistill)无限运行。 删除此脚本后,脚本将继续前进,直到Image.open。

任何输入将不胜感激。 谢谢!

您不会使用raspistill写入STDOUT,因此不会将任何图像数据获取到STDOUT。

尝试

command = "raspistill -w %s -h %s -e bmp -o -" % (100, 75) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM