/
captureScript.py
74 lines (47 loc) · 1.53 KB
/
captureScript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import OlympusAir
import os
import datetime
import requests
from OlympusAir import OlympusAir, OlympusAirError, OlympusAirLiveViewFrame
cam = OlympusAir()
cam.commInterface()
cam.switchMode('rec')
cam.setProperty('FOCUS_STILL','FOCUS_SAF')
cam.setProperty('RAW','ON')
cam.setProperty('TAKE_DRIVE','DRIVE_NORMAL')
cam.setProperty('TAKEMODE','P')
cam.setProperty('DESTINATION_FILE','DESTINATION_FILE_MEDIA')
cam.setZoom(20)
dirPath = './' + datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
print '======= ' + dirPath + ' ======='
os.mkdir(dirPath)
cam.startPreview()
for i in range(10):
cam.setProperty('FOCUS_STILL','FOCUS_SAF')
attempts = 0
while attempts < 10:
try:
cam.takePicture()
break
except requests.exceptions.HTTPError as err:
# leave the script ?
# Recreate camera object?
pass
except OlympusAirError as err:
if err.value == OlympusAirError.AF:
print 'Autofocus error'
cam.setProperty('FOCUS_STILL','FOCUS_MF')
attempts = attempts + 1
cam.waitOnCardWrite()
cam.stopPreview()
for i in range(10):
jpeg, raw = cam.getLatestFile(i)
jpegFile = open(dirPath + '/' + 'LED%02i.jpg' % (9 - i),'w')
jpegFile.write(jpeg)
rawFile = open(dirPath + '/' + 'LED%02i.orf' % (9 - i),'w')
rawFile.write(jpeg)
# What if we tried enough times
cam.disconnect()