简体   繁体   English

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

[英]Motion tracking using picamera and python script

I'm using and modifying this Python script for simple motion tracking. 我正在使用和修改 Python脚本以进行简单的运动跟踪。 Unfortunately, i've been running into issues with the function that captures an original image to base movement off of. 不幸的是,我遇到了捕获原始图像以使运动基本停止的功能的问题。

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

The function above becomes problematic when it reaches the line 上面的函数到达行时变得有问题

im = Image.open(imageData)

This line, in theory, takes the bytes written to imageData and converts them back into a useable image file. 从理论上讲,这行代码将字节写入imageData并将其转换回可用的图像文件。 However, when Image.open is called on imageData, I receive an error stating that the byte array cannot be coerced into an image. 但是,在imageData上调用Image.open时,我收到一条错误消息,指出无法将字节数组强制转换为图像。 My understanding is that subprocess.check_output returns a byte representation of the returned value (assuming there is one). 我的理解是subprocess.check_output返回返回值的字节表示形式(假设有一个)。 This clearly isn't the case, but I can't figure out how to convert my byte file (imageData) back into an actual image file. 显然不是这种情况,但是我不知道如何将字节文件(imageData)转换回实际的图像文件。 Thus far i've used io.ByteIO, but this has given me the same issues as StringIO. 到目前为止,我已经使用了io.ByteIO,但这给了我与StringIO相同的问题。

I've modified this function slightly, in that the command (raspistill) was running infinitely due to an argument being passed (-t 0). 我已经稍微修改了此函数,由于传递了一个参数(-t 0),命令(raspistill)无限运行。 After removing this, the script was allowed to progress forward, up until the Image.open. 删除此脚本后,脚本将继续前进,直到Image.open。

Any input would be appreciated. 任何输入将不胜感激。 Thanks! 谢谢!

You're not writing to STDOUT with raspistill, so you're not going to get any image data to STDOUT. 您不会使用raspistill写入STDOUT,因此不会将任何图像数据获取到STDOUT。

try 尝试

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