def capture(): pygame.init() size = width, height = 620, 485 speed = [2, 2] black = 0, 0, 0 shots = 0 #pygame.display.set_caption('Capture') #screen = pygame.display.set_mode(size) SLEEP_TIME_LONG = 0.05 cam = Device(devnum=0, showVideoWindow=0) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() keyinput = pygame.key.get_pressed() if keyinput[K_q]: cam.displayCapturePinProperties() if keyinput[K_w]: cam.displayCaptureFilterProperties() if shots <= 2: if shots == 0: time.sleep(1.6) else: time.sleep(0.5) filename = 'face' + str(shots) + ".jpg" cam.saveSnapshot(filename, quality=80, timestamp=0) shots += 1 print("Photo " + str(shots) + " captured.") if shots == 3: return #cam.saveSnapshot('test.jpg', timestamp=3, boldfont=1, quality=75) #image = pygame.image.load('test.jpg') #screen.blit(image, speed) #pygame.display.flip() #capture()
class myCam: def __init__(self,show=0): self.cam = Device(devnum=0, showVideoWindow=show) self.cam.setResolution(width=720, height=480) self.baseDir='C:\\Andrew\\data\\' tmp=time.localtime() self.dayStr='%02.0f%02.0f%02.0f' % (tmp[0]-2000,tmp[1],tmp[2]) self.dataDir=self.baseDir + self.dayStr if not os.path.exists(self.dataDir): os.mkdir(self.dataDir) self.name='tmp' def setProperties(self): self.cam.displayCapturePinProperties() def grab(self,fn=None,q=90): if fn is None: fn='%stest.jpg' % self.baseDir self.cam.saveSnapshot(filename=fn, quality=q) def series(self,n=1,s=None): if not s is None: self.name=s for i in range(n): self.grab('%s\\%s%03.0f.jpg' % (self.dataDir,self.name,i))
from pygame.locals import * from PIL import ImageEnhance #import MssUnitChr2 as ms import MssUnit2 as ms # less talkative version of the MssUnit #import UniversalLibrary as UL import numpy as np # camera parameters res = (1344,1024) #res = (640,480) pixel_4x=[1.532,1.532] # one pixel in um at 4x, resolution 1344x1024 FRAMERATE = 25 # 25 pygame.init() cam = Device() cam.displayCapturePinProperties() cam.setResolution(res[0],res[1]) screen = pygame.display.set_mode(res) pygame.display.set_caption('CRACM Now') pygame.font.init() font = pygame.font.SysFont("Courier",11) brightness = 1.0 contrast = 1.0 shots = 0 # pygame control initial settings moveLeft = False moveRight = False moveUp = False moveDown = False
from VideoCapture import Device import time, string ## Specify the amount of seconds to wait between individual captures. interval = 2 ## 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=1) #cam = Device(devnum=1, showVideoWindow=1) ## Using the separate programs "setPropertiesDev0/1.pyw" before capturing ## works better for some devices. ## On the other hand, some devices don't remember their state, so the ## properties have to be set at every program start. cam.displayCapturePinProperties() #cam.displayCaptureFilterProperties() print "press 'ctrl + c' to terminate" i = 0 quant = interval * .1 starttime = time.time() while 1: lasttime = now = int((time.time() - starttime) / interval) #print i cam.saveSnapshot('C:\\Windows\\Temp\\' + string.zfill(str(i), 4) + '.jpg', timestamp=3, boldfont=1) i += 1 while now == lasttime: now = int((time.time() - starttime) / interval) time.sleep(quant)
last_capture_time = time.time() snapshots_persisted = False monitor = True while monitor: camshot = ImageEnhance.Brightness(cam.getImage()).enhance(brightness) camshot = ImageEnhance.Contrast(camshot).enhance(contrast) for event in pygame.event.get(): if event.type == pygame.QUIT: monitor = False elif event.type == pygame.KEYUP: if event.key == pygame.K_1: brightness -= .1 if event.key == pygame.K_2: brightness += .1 if event.key == pygame.K_3: contrast -= .1 if event.key == pygame.K_4: contrast += .1 if event.key == pygame.K_q: cam.displayCapturePinProperties() if event.key == pygame.K_w: cam.displayCaptureFilterProperties() if event.key == pygame.K_ESCAPE: pygame.event.post(pygame.event.Event(QUIT,)) if event.key == pygame.K_s: output_filename = current_directory + ".mp4" command_line = "ffmpeg.exe -r " + str(frames_per_second) + \ " -i " + os.path.join(current_directory, "%03d.jpg ") + \ output_filename print("Exporting video...") print("\t" + command_line) subprocess.call(command_line) print("Video exported to " + os.path.join(os.getcwd(), output_filename)) current_directory = str(time.time()) snapshots_persisted = True shots = 0