-
Notifications
You must be signed in to change notification settings - Fork 1
/
EX05_recordSingleImages_async.py
115 lines (90 loc) · 3.44 KB
/
EX05_recordSingleImages_async.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import platform
import sys
import time
from datetime import timedelta
import cuvis
import asyncio as a
### default directories and files
data_dir = None
lib_dir = None
if platform.system() == "Windows":
lib_dir = os.getenv("CUVIS")
data_dir = os.path.normpath(os.path.join(lib_dir, os.path.pardir, "sdk",
"sample_data", "set_examples"))
elif platform.system() == "Linux":
lib_dir = os.getenv("CUVIS_DATA")
data_dir = os.path.normpath(
os.path.join(lib_dir, "sample_data", "set_examples"))
# default factory
loc_factory = os.path.join(lib_dir, os.pardir,
"factory")
# default settings
loc_settings = os.path.join(data_dir, "settings")
# default output
loc_output = os.path.join(os.getcwd(), "EX05_images")
# parameters
loc_exptime = 100 #in msw
loc_nimgs = 10
async def run_example_recordSingleImage(
userSettingsDir=loc_settings,
factoryDir=loc_factory,
recDir=loc_output,
exposure=loc_exptime,
nrImgs=loc_nimgs):
print("loading user settings...")
cuvis.init(userSettingsDir)
cuvis.set_log_level("info")
print(
"loading calibration, processing and acquisition context (factory)...")
calibration = cuvis.Calibration(factoryDir)
processingContext = cuvis.ProcessingContext(calibration)
acquisitionContext = cuvis.AcquisitionContext(calibration)
saveArgs = cuvis.SaveArgs(export_dir=recDir, allow_overwrite=True,
allow_session_file=True)
cubeExporter = cuvis.CubeExporter(saveArgs)
while acquisitionContext.state == cuvis.HardwareState.Offline:
print(".", end="")
time.sleep(1)
print("\n")
print("Camera is online")
await acquisitionContext.set_operation_mode_async(cuvis.OperationMode.Software)
await acquisitionContext.set_integration_time_async(exposure)
print("Start recoding now")
for i in range(nrImgs):
print("Record image #{}/{} ... (async)".format(i + 1, nrImgs))
mesu = await acquisitionContext.capture()
if mesu is not None:
processingContext.apply(mesu)
cubeExporter.apply(mesu)
print("done")
else:
print("failed")
cuvis.shutdown()
print("finished.")
if __name__ == "__main__":
print("Example 05: Record single image. Please provide:")
userSettingsDir = input(
"User settings directory (default: {}): ".format(loc_settings))
if userSettingsDir.strip().lower() in ["", "default"]:
userSettingsDir = loc_settings
factoryDir = input("Factory directory (default: {}): ".format(loc_factory))
if factoryDir.strip().lower() in ["", "default"]:
factoryDir = loc_factory
recDir = input(
"Name of recording directory (default: {}): ".format(loc_output))
if recDir.strip().lower() in ["", "default"]:
recDir = loc_output
exposure = input(
"Exposure/Integration time in ms (default: {}): ".format(loc_exptime))
if exposure.strip().lower() in ["", "default"]:
exposure = loc_exptime
exposure = int(exposure)
nrImgs = input("Number of Images (default: {}): ".format(loc_nimgs))
if nrImgs.strip().lower() in ["", "default"]:
nrImgs = loc_nimgs
nrImgs = int(nrImgs)
a.run(run_example_recordSingleImage(userSettingsDir, factoryDir, recDir, exposure,
nrImgs))
while 1:
sys.exit(0)