[Image-SIG] deleting

hsubryan at buffalo.edu hsubryan at buffalo.edu
Mon Mar 27 07:22:01 CEST 2006


Hi,

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
taken. 

i.e 

compose_1
compose_2
compose_3 
etc.
etc.

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
deleted. 


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.
thanks
 
..subryan

from VideoCapture import Device
import time, string
import Image
import os, sys
import Image
import ImageFilter
import ImageChops


## Specify the amount of seconds to wait between individual captures.
## interval = raw_input('Enter the amount time between each image
capture: ')

## 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)
cam.setResolution(640,480)

cam2 = Device(devnum=1, showVideoWindow=0)
cam2.setResolution(640,480)

## cam = Device(devnum=1, showVideoWindow=1)

## cam.displayCapturePinProperties()

#cam.displayCaptureFilterProperties()
#cam2.displayCaptureFilterProperties()


print "press 'ctrl + c' to terminate"
print 'Duration is measured per seconds'

interval = input('Enter the amount time between each image capture: ')

i = 0
j=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
while 1:
    lasttime = now = int((time.time() - starttime) / interval)
    print i
    print j
    

    #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')
    #newout.save('robotics', 'JPEG')

    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)
        time.sleep(quant)


More information about the Image-SIG mailing list