def GetPhoto(f = None, quality = None):
"""
Photo aquisition
"""
global filename, FAILCOUNTER, error_tries
debug("GetPhoto: failcounter=%d" % FAILCOUNTER)
if FAILCOUNTER < 0:
print "Fail counter reached maximum attempts. Failed."
debug("Trying to return a failed img.")
filename = getfailedimg()
if not filename:
sys.exit(1)
debug("Using failed img: %s" % filename)
# it needs to be 0ed or it will fail
FAILCOUNTER = 0
return 0
filename = None
debug("Camera init")
camera = PiCamera()
debug("Camera start")
camera.start_preview()
time.sleep(10)
#if not os.path.exists(SAVEDIR):
# os.makedirs(SAVEDIR)
year = time.strftime("%Y", time.localtime())
month = time.strftime("%m", time.localtime())
if not os.path.exists("%s/%s/%s" % (SAVEDIR, year, month)):
os.makedirs("%s/%s/%s" % (SAVEDIR, year, month) )
if not f:
timestamp = time.strftime("%Y-%m-%d_%H%M%S", time.localtime())
filename = "%s/%s/%s/%s.jpg" % (SAVEDIR, year, month, timestamp)
else:
filename = f
debug("Saving file %s" % filename)
camera.capture(filename)
camera.stop_preview()
评论列表
文章目录