简体   繁体   中英

Motion tracking using picamera and python script

I'm using and modifying this Python script for simple motion tracking. 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. However, when Image.open is called on imageData, I receive an error stating that the byte array cannot be coerced into an image. My understanding is that subprocess.check_output returns a byte representation of the returned value (assuming there is one). 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. Thus far i've used io.ByteIO, but this has given me the same issues as StringIO.

I've modified this function slightly, in that the command (raspistill) was running infinitely due to an argument being passed (-t 0). After removing this, the script was allowed to progress forward, up until the 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.

try

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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