[P]picamera 延时摄影

raspberrypi raspcam


###基于opencv-python

  • 能设置延时时间
  • 文件名按3位数字命名
# -*- coding: utf-8 -*-
import time
import picamera
from datetime import datetime, timedelta
def ask_delay(ask_delay,retries,complaint):
    while True:
		global delay
		global start
		start =False
		delay = raw_input(ask_delay)
		if delay.isdigit():
		#判断是否为数字
			delay = int(delay)
			start =True
			break
		retries = retries - 1
		if retries < 0:
		    raise IOError('run again')
		print complaint

def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
    while True:
    	global anwser
    	#全局变量
        anwser = raw_input(prompt)
        if anwser in ('y', 'ye', 'yes'):
          	#print anwser#
          	ask_delay('How many delay do you want?',4,'Please input number!')
        	break
        if anwser in ('n', 'no', 'nop', 'nope'):
        	print anwser
        	break
        retries = retries - 1
        if retries < 0:
            raise IOError('run again')
        print complaint

def take_pictures():
	if start == True:
		with picamera.PiCamera() as camera:
			#camera.start_preview()
			time.sleep(2)
			for filename in camera.capture_continuous('img{counter:03d}.jpg'):
			    
			    print('Captured %s' % filename)
			    print("taking picture per %r sec >>>>>>" %delay)
			    time.sleep(delay) # wait delays

ask_ok('Do you want to take timelapse pictures?', 4, 'Come on, only yes or no!')
take_pictures()


###TOP


Next: [P]Install opencv-python on RaspberryPi Previous: [P]opencv-python_01

You May Also Enjoy :

记raspberryPi上编译mt7610 wifi卡
Media center with raspberry pi b+
[P]opencv-python_11

Blog search

If you think my article can help you, please click on the ad to support me! ↓↓↓