hsubryan at buffalo.edu
hsubryan at buffalo.edu
Mon Mar 27 07:22:01 CEST 2006
I need to save the compose image into another folder besides the one
that the program is running in. Also, how can delete the prececeding
images that are being saved in the current folder and only keep the new
one. So for instance, the only image that would exist in the folder that
the program is running is the image compose from the most update image
these images are being saved at a specified interval. so if compose_3
was the last image save, I would like for compose_1 and compose_2 to be
This code works and allows me to save the images in one folder, but
I would like to save each batch in their separate folder.
any help would be greatly appreciated.
from VideoCapture import Device
import time, string
import os, sys
## Specify the amount of seconds to wait between individual captures.
## interval = raw_input('Enter the amount time between each image
## If you get horizontal stripes or other errors in the captured picture
## (especially at high resolutions), try setting showVideoWindow=0.
cam = Device(devnum=0, showVideoWindow=0)
cam2 = Device(devnum=1, showVideoWindow=0)
## cam = Device(devnum=1, showVideoWindow=1)
print "press 'ctrl + c' to terminate"
print 'Duration is measured per seconds'
interval = input('Enter the amount time between each image capture: ')
i = 0
im1 = 0
im2 = 0
imsave = 0
quant = interval * .1
starttime = time.time()
compose = os.path.join("compose")
upstairs = os.path.join("upstairs")
downstairs = os.path.join("downstairs")
newfolder = os.path.save('c:robotics")
newsave = 0
lasttime = now = int((time.time() - starttime) / interval)
#cam.saveSnapshot(string.zfill(str(i), 2) + '.jpg')
cam.saveSnapshot(upstairs + '_' + string.zfill(i, 1) + '.jpg')
#cam2.saveSnapshot(string.zfill(str(j),3) + '.jpg')
cam2.saveSnapshot(downstairs + '_' + string.zfill(j, 1) + '.jpg')
i += 1
j += 1
#takes each image and opens them incrementally to begin filtering.
#imcomp = Image.open(string.zfill(str(im1),1) + '.jpg')
imcomp = Image.open(upstairs + '_' + string.zfill(im1, 1) + '.jpg')
#imcomp2 = Image.open(string.zfill(str(im2),1) + '.jpg')
imcomp2 = Image.open(downstairs + '_' + string.zfill(im2, 1) + '.jpg')
#compares the two images, pixel by pixel, and returns the new image
containing the darker values.
out = ImageChops.darker(imcomp, imcomp2)
# output the images into current folder while deleting.
out.save(compose + '_' + string.zfill(imsave, 1) + '.jpg')
#out.save(string.zfill(str(imsave), 1) + '.jpg')
#save images in a new location.
#newout = out.save(string.zfill(str(newsave), 1) + '.jpg')
newsave += 1
im1 += 1
im2 += 1
imsave += 1
# continues an incremental overlay for each each that is taken.
while now == lasttime:
now = int((time.time() - starttime) / interval)
More information about the Image-SIG