-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathsnap-save-image.py
87 lines (64 loc) · 2.59 KB
/
snap-save-image.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
import ctypes as C
import numpy as np
import sys,os
# Import PyhtonNet
import clr
# Load IC Imaging Control .NET
sys.path.append(os.getenv('IC35PATH') + "/redist/dotnet/x64")
clr.AddReference('TIS.Imaging.ICImagingControl35')
clr.AddReference('System')
# Import the IC Imaging Control namespace.
import TIS.Imaging
from System import TimeSpan
# Create the IC Imaging Control object.
ic = TIS.Imaging.ICImagingControl()
# Create the sink for snapping images on demand.
snapsink = TIS.Imaging.FrameSnapSink(TIS.Imaging.MediaSubtypes.RGB32)
ic.Sink = snapsink
ic.LiveDisplay = False
# Try to open the last used video capture device.
try:
ic.LoadDeviceStateFromFile("device.xml",True)
if ic.DeviceValid is True:
ic.LiveStart()
except Exception as ex:
ic.ShowDeviceSettingsDialog()
if ic.DeviceValid is True:
ic.SaveDeviceStateToFile("device.xml")
ic.LiveStart()
pass
# Query some properties
ExposureAuto = ic.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_Exposure,
TIS.Imaging.VCDIDs.VCDElement_Auto,TIS.Imaging.VCDIDs.VCDInterface_Switch)
#Absolute Values interface for exposure, so we can set exposure times in seconds
ExposureValue = ic.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_Exposure,
TIS.Imaging.VCDIDs.VCDElement_Value,TIS.Imaging.VCDIDs.VCDInterface_AbsoluteValue)
# Get the Gainautomatic propertiy
GainAuto = ic.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_Gain,
TIS.Imaging.VCDIDs.VCDElement_Auto,TIS.Imaging.VCDIDs.VCDInterface_Switch)
# Get the Gain value.
GainValue = ic.VCDPropertyItems.FindInterface(TIS.Imaging.VCDIDs.VCDID_Gain,
TIS.Imaging.VCDIDs.VCDElement_Value,TIS.Imaging.VCDIDs.VCDInterface_Range)
# Disable Gain automatic
if GainAuto is not None:
GainAuto.Switch = False
# Set minimum gain
if GainValue is not None:
GainValue.Value = GainValue.RangeMin
# Disable Exposure automatic
if ExposureAuto is not None:
ExposureAuto.Switch = False
# Set 1/30 second exosure time
if ExposureValue is not None:
ExposureValue.Value = 0.0303
# Snap two frames in order to be sure, the set values became effective in the sensor.
# It is not necessary, if we do not change properties directly before snapping an image.
# use the second frame
snapsink.SnapSingle(TimeSpan.FromSeconds(5))
frame = snapsink.SnapSingle(TimeSpan.FromSeconds(5))
# Save the frame as JPG with 75% quality.
TIS.Imaging.FrameExtensions.SaveAsJpeg( frame,"image.jpg", 75)
print("Image saved.")
#End the live video
ic.LiveStop()
ic.Dispose()