-
Notifications
You must be signed in to change notification settings - Fork 5
/
LifeCamCamera.cs
208 lines (180 loc) · 4.63 KB
/
LifeCamCamera.cs
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Video.DirectShow.Internals;
namespace CameraPrefsApp
{
class LifeCamCamera
{
public VideoCaptureDevice Source;
private IAMCameraControl cameraControls;
private IAMVideoProcAmp videoProcAmp;
private String _name;
public LifeCamCamera(string name)
{
_name = name;
String moniker = null;
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
// Match specified camera name to device
for (int i = 0, n = videoDevices.Count; i < n; i++)
{
if (name == videoDevices[i].Name)
{
moniker = videoDevices[i].MonikerString;
break;
}
}
if (moniker == null)
return;
//throw new Exception("Video device with name '" + name + "' not found.");
Source = new VideoCaptureDevice(moniker);
Source.DesiredFrameRate = 30;
cameraControls = (IAMCameraControl)Source.SourceObject;
videoProcAmp = (IAMVideoProcAmp)Source.SourceObject;
}
static public LifeCamCamera CreateFromPrefs(CameraPrefs prefs)
{
LifeCamCamera newCamera = new LifeCamCamera(prefs.Name);
if (newCamera.Source == null)
throw new Exception("Camera \"" + prefs.Name + "\" not found. Skipping.");
FieldInfo[] fields = prefs.GetType().GetFields();
Console.WriteLine("\nApplying \"" + prefs.Name + "\" settings...\n");
foreach (FieldInfo field in fields)
{
try
{
newCamera.GetType().GetProperty(field.Name).SetValue(newCamera, field.GetValue(prefs), null);
Console.WriteLine(" => " + field.Name + ": " + field.GetValue(prefs));
}
catch (Exception e)
{
continue;
}
}
return newCamera;
}
public String Name
{
get { return _name; }
set { }
}
/**
* Camera Control
*/
public int Focus
{
get { return Source.GetFocus(); }
set { Source.SetFocus(value); }
}
public Boolean AutoFocus
{
get { return Source.GetAutoFocus(); }
set { Source.SetAutoFocus(value); }
}
public void GetFocusRange(ref int minimum, ref int maximum, ref int step)
{
//int defaultValue;
//Source.GetFocusRange(out minimum, out maximum, out step, out defaultValue);
}
public int Zoom
{
get { return Source.GetZoom(); }
set { Source.SetZoom(value); }
}
public void GetZoomRange(out int minimum, out int maximum, out int step)
{
int defaultValue;
Source.GetZoomRange(out minimum, out maximum, out step, out defaultValue);
}
public int Pan
{
get { return Source.GetPan(); }
set { Source.SetPan(value); }
}
public void GetPanRange(ref int min, ref int max, ref int step, ref int def)
{
Source.GetPanRange(ref min, ref max, ref step, ref def);
}
public int Tilt
{
get { return Source.GetTilt(); }
set { Source.SetTilt(value); }
}
public void GetTiltRange(ref int min, ref int max, ref int step, ref int def)
{
Source.GetTiltRange(ref min, ref max, ref step, ref def);
}
/**
* Video Settings
*/
public int Brightness
{
get
{
int value;
VideoProcAmpFlags flags;
return videoProcAmp.Get(VideoProcAmpProperty.Brightness, out value, out flags);
}
set
{
videoProcAmp.Set(VideoProcAmpProperty.Brightness, value, VideoProcAmpFlags.Manual);
}
}
public int WhiteBalance
{
get
{
int value;
VideoProcAmpFlags flags;
return videoProcAmp.Get(VideoProcAmpProperty.WhiteBalance, out value, out flags);
}
set
{
videoProcAmp.Set(VideoProcAmpProperty.WhiteBalance, value, VideoProcAmpFlags.Manual);
}
}
public int Saturation
{
get
{
int value;
VideoProcAmpFlags flags;
return videoProcAmp.Get(VideoProcAmpProperty.Saturation, out value, out flags);
}
set
{
videoProcAmp.Set(VideoProcAmpProperty.Saturation, value, VideoProcAmpFlags.Manual);
}
}
public int Exposure
{
get
{
int value;
CameraControlFlags flags;
return cameraControls.Get(CameraControlProperty.Exposure, out value, out flags);
}
set
{
cameraControls.Set(CameraControlProperty.Exposure, value, CameraControlFlags.Manual);
}
}
public int Contrast
{
get
{
int value;
VideoProcAmpFlags flags;
return videoProcAmp.Get(VideoProcAmpProperty.Contrast, out value, out flags);
}
set
{
videoProcAmp.Set(VideoProcAmpProperty.Contrast, value, VideoProcAmpFlags.Manual);
}
}
}
}