Código fonte do arquivo piCamExplorer.py.
O código fonte aplicação piCamExplorer.py segue abaixo.
# programa piCamExplorer.py # Copywright by Mauro Assis (assismauro@hotmail.com) import time import picamera import sys import cv2 import getopt camera = picamera.PiCamera() def header(): print print 'piCamExplorer v0.9' print def usage(): print print 'Usage: pyhton piCamExplorer -m(mode m,p or t) -d(secs delay) -n(numbers of pics) -i(secs interval) -h(help)' print def main(): nPic = 10 interval = 10 delay = 0 # processa linha de comando try: opts, args = getopt.getopt(sys.argv[1:],'m:d:n:i:h') except getopt.GetoptError: usage() sys.exit(2) camera.resolution = (1024, 768) camera.vflip = True mode = '' for opt, arg in opts: if opt == '-h': usage() elif opt == '-m': mode = arg; elif opt == '-n': nPic = int(arg) elif opt == '-i': interval = int(arg) elif opt == '-d': delay = int(arg) # funções # filme if mode == 'm': print 'Movie mode' camera.start_preview() time.sleep(interval) camera.stop_preview() elif mode == 'p': # foto print 'Picture mode' camera.capture('pict.jpg') time.sleep(2); img = cv2.imread('pict.jpg') cv2.imshow('pict',img) cv2.waitKey(0) cv2.destroyAllWindows() # timeslice elif mode == 't': print 'Time-lapse mode' print 'Delay (h): ', float(delay)/3600.0 print 'Now: ',time.ctime() time.sleep(delay) print 'Start time: ',time.ctime() for i in range(0,nPic): fName='pict'+str(i).rjust(5,'0')+'.jpg' camera.capture(fName) print fName time.sleep(interval) header() try: main() except: print 'Error: ',sys.exc_info()[0] usage()
Comentários
Postar um comentário