2 using System.Collections.Generic;
5 using AForge.Video.DirectShow;
10 partial class ConfigurationControl
15 private readonly Dictionary<string, string> videoSources =
new Dictionary<string, string>();
17 private readonly FilterInfoCollection filterInfoCollection =
new FilterInfoCollection(FilterCategory.VideoInputDevice);
23 private void InitCameraValues()
25 this.InitiateCameraDropdown();
27 this.textBoxMoniker.Text = this.configuration.Camera.Moniker;
29 this.textBoxCameraX.Text = this.configuration.Camera.WorldCoordinates.X.ToString(CultureInfo.InvariantCulture);
30 this.textBoxCameraX.TextChanged += this.TextBoxCameraXOnTextChanged;
32 this.textBoxCameraY.Text = this.configuration.Camera.WorldCoordinates.Y.ToString(CultureInfo.InvariantCulture);
33 this.textBoxCameraY.TextChanged += this.TextBoxCameraYOnTextChanged;
35 this.textBoxCameraZ.Text = this.configuration.Camera.WorldCoordinates.Z.ToString(CultureInfo.InvariantCulture);
36 this.textBoxCameraZ.TextChanged += this.TextBoxCameraZOnTextChanged;
38 this.textBoxCameraWidthCM.Text = this.configuration.Camera.WorldWidth.ToString(CultureInfo.InvariantCulture);
39 this.textBoxCameraWidthCM.TextChanged += this.TextBoxCameraWidthOnTextChanged;
41 this.textBoxCameraHeightPX.Text = this.configuration.Camera.Height.ToString();
42 this.textBoxCameraWidthPX.Text = this.configuration.Camera.Width.ToString();
49 private void InitiateCameraDropdown()
52 foreach (FilterInfo filterInfo
in this.filterInfoCollection)
54 this.comboBoxCamera.Items.Add(filterInfo.Name);
55 this.videoSources.Add(filterInfo.Name, filterInfo.MonikerString);
56 if (!String.IsNullOrEmpty(
this.configuration.Camera.Name) &&
57 filterInfo.Name == this.configuration.Camera.Name)
59 this.comboBoxCamera.SelectedIndex = i;
61 this.SetMaxFrameSizes(filterInfo.MonikerString);
68 this.comboBoxCamera.SelectedIndexChanged += this.ComboBoxCameras_SelectedIndexChanged;
80 if (!this.videoSources.ContainsKey(
this.comboBoxCamera.Text))
83 this.configuration.Camera.Name = this.comboBoxCamera.Text;
84 this.configuration.Camera.Moniker = this.videoSources[this.comboBoxCamera.Text];
86 this.textBoxMoniker.Text = this.configuration.Camera.Moniker;
88 this.SetMaxFrameSizes(this.configuration.Camera.Moniker);
97 private void SetMaxFrameSizes(
string monikerString)
99 VideoCaptureDevice source =
new VideoCaptureDevice(monikerString);
101 if (source.VideoCapabilities.Length > 0)
103 VideoCapabilities max = source.VideoCapabilities.OrderBy(p => p.FrameSize.Width).Last();
104 source.VideoResolution = max;
106 if (null != source.VideoResolution)
108 this.configuration.Camera.Height = source.VideoResolution.FrameSize.Height;
109 this.configuration.Camera.Width = source.VideoResolution.FrameSize.Width;
110 this.textBoxCameraHeightPX.Text = source.VideoResolution.FrameSize.Height.ToString();
121 private void TextBoxCameraXOnTextChanged(
object sender, EventArgs eventArgs)
123 this.configuration.Camera.WorldCoordinates.X =
float.Parse(this.textBoxCameraX.Text);
133 private void TextBoxCameraYOnTextChanged(
object sender, EventArgs eventArgs)
135 this.configuration.Camera.WorldCoordinates.Y =
float.Parse(this.textBoxCameraY.Text);
145 private void TextBoxCameraZOnTextChanged(
object sender, EventArgs eventArgs)
147 this.configuration.Camera.WorldCoordinates.Z =
float.Parse(this.textBoxCameraZ.Text);
158 private void TextBoxCameraWidthOnTextChanged(
object sender, EventArgs e)
160 this.configuration.Camera.WorldWidth =
float.Parse(this.textBoxCameraWidthCM.Text);
165 private void buttonLoadCameraDefaults_Click(
object sender, EventArgs e)
167 this.DetachCameraEvents();
168 this.comboBoxCamera.Items.Clear();
169 string tempCamera = this.configuration.Camera.Name;
170 string tempMoniker = this.configuration.Camera.Moniker;
172 this.configuration.Camera.
Name = tempCamera;
173 this.configuration.Camera.Moniker = tempMoniker;
174 this.InitCameraValues();
177 private void DetachCameraEvents()
179 this.textBoxCameraX.TextChanged -= this.TextBoxCameraXOnTextChanged;
180 this.textBoxCameraY.TextChanged -= this.TextBoxCameraYOnTextChanged;
181 this.textBoxCameraZ.TextChanged -= this.TextBoxCameraZOnTextChanged;
182 this.textBoxCameraWidthCM.TextChanged -= this.TextBoxCameraWidthOnTextChanged;
183 this.comboBoxCamera.SelectedIndexChanged -= this.ComboBoxCameras_SelectedIndexChanged;
string Name
Gets or sets the name.
void ComboBoxCameras_SelectedIndexChanged(object sender, EventArgs e)
Handles the SelectedIndexChanged event of the ComboBoxCameras control.
static Camera CreateDefaultCamera()
Creates the default camera.
Class for accessing the configuration.