private void FillResolutionList() { comboBoxResolutionList.Items.Clear(); if (!cameraControl.CameraCreated) { return; } ResolutionList resolutions = Camera.GetResolutionList(cameraControl.Moniker); if (resolutions == null) { return; } int index_to_select = -1; for (int index = 0; index < resolutions.Count; index++) { comboBoxResolutionList.Items.Add(resolutions[index].ToString()); if (resolutions[index].CompareTo(cameraControl.Resolution) == 0) { index_to_select = index; } } // select current resolution if (index_to_select >= 0) { comboBoxResolutionList.SelectedIndex = index_to_select; } }
//启动摄像头 private void BtnStartVideo_Click(object sender, EventArgs e) { try { cameraChoice.UpdateDeviceList(); cameraControl.SetCamera(cameraChoice.Devices[0].Mon, null); ResolutionList resolutions = Camera.GetResolutionList(cameraControl.Moniker); Resolution resolution = null; foreach (Resolution item in resolutions) { if (item.CompareTo(cameraControl.Resolution) == 0) { resolution = item; break; } } if (resolution == null) { resolution = resolutions[0]; } cameraControl.SetCamera(cameraChoice.Devices[0].Mon, resolution); this.btnStartVideo.Enabled = false; this.btnCloseVideo.Enabled = true; this.btnTake.Enabled = true; } catch (Exception ex) { MessageBox.Show("启动摄像头发生异常:" + ex.Message, "启动失败"); } }
private void comboBoxResolutionList_SelectedIndexChanged(object sender, EventArgs e) { if (!cameraControl.CameraCreated) { return; } int comboBoxResolutionIndex = comboBoxResolutionList.SelectedIndex; if (comboBoxResolutionIndex < 0) { return; } ResolutionList resolutions = Camera.GetResolutionList(cameraControl.Moniker); if (resolutions == null) { return; } if (comboBoxResolutionIndex >= resolutions.Count) { return; // throw } if (0 == resolutions[comboBoxResolutionIndex].CompareTo(cameraControl.Resolution)) { // this resolution is already selected return; } // Recreate camera //SetCamera(_Camera.Moniker, resolutions[comboBoxResolutionIndex]); cameraControl.SetCamera(cameraControl.Moniker, resolutions[comboBoxResolutionIndex]); }
//启动摄像头 private void btnStartVideo_Click(object sender, EventArgs e) { try { //刷新摄像头 cameraChoice.UpdateDeviceList(); cameraControl.SetCamera(cameraChoice.Devices[0].Mon, null);//要先启动摄像头,不然接下来这句报错:camera is not created ResolutionList resolutions = Camera.GetResolutionList(cameraControl.Moniker); Resolution currentResolution = null; foreach (Resolution item in resolutions) { if (item.CompareTo(cameraControl.Resolution) == 0) { currentResolution = item; break; } } if (currentResolution == null) { currentResolution = resolutions[0]; } cameraControl.SetCamera(cameraChoice.Devices[0].Mon, currentResolution); this.btnStartVideo.Enabled = false; this.btnCloseVideo.Enabled = true; this.btnTake.Enabled = true; } catch (Exception ex) { MessageBox.Show("摄像头启动失败:" + ex.Message, "异常提示"); } }
/// <summary> /// Gets available resolutions (which are appropriate for us) for capture filter. /// </summary> /// <param name="captureFilter">Capture filter for asking for resolution list.</param> private static ResolutionList GetResolutionsAvailable(IBaseFilter captureFilter) { ResolutionList resolution_list = null; IPin pRaw = null; try { pRaw = DsFindPin.ByDirection(captureFilter, PinDirection.Output, 0); //pRaw = DsFindPin.ByCategory(captureFilter, PinCategory.Capture, 0); //pRaw = DsFindPin.ByCategory(filter, PinCategory.Preview, 0); resolution_list = GetResolutionsAvailable(pRaw); } catch { throw; //resolution_list = new ResolutionList(); //resolution_list.Add(new Resolution(640, 480)); } finally { SafeReleaseComObject(pRaw); pRaw = null; } return(resolution_list); }
public Settings(ResolutionList postureResolutions, ResolutionList plantoResolutions) { InitializeComponent(); this.postureResolutions = postureResolutions; if (postureResolutions != null) { foreach (var resolution in postureResolutions) { postureResolution.Items.Add(resolution); } } if (plantoResolutions != null) { foreach (var resolution in plantoResolutions) { plantoResolution.Items.Add(resolution); } } linkLabel1.LinkColor = Properties.Settings.Default.colorLine; linkLabel2.LinkColor = Properties.Settings.Default.colorLine2; linkLabel4.LinkColor = Properties.Settings.Default.colorText; linkLabel3.LinkColor = Properties.Settings.Default.colorPoints; font.Text = Properties.Settings.Default.fontSize.Name.ToString() + " " + Properties.Settings.Default.fontSize.Size.ToString(); }
private void FillCameraResolutionComboBox() { this.ResolutionBox.Items.Clear(); if (Moniker == null) { return; } ResolutionList resolutions = Camera.GetResolutionList(Moniker); string lastRes = Settings.Get <Settings>().Read(Settings.LAST_USED, Settings.CAMERA_RESOLUTION, string.Empty); int found = -1; for (int i = 0; i < resolutions.Count; i++) { this.ResolutionBox.Items.Add(resolutions[i]); if (resolutions[i].ToString() == lastRes) { found = i; } } if (found != -1) { this.ResolutionBox.SelectedIndex = found; } }
private object CreateObject(Type type, ResolutionList resolutionPath, RegistrationKey keyToResolve) { var ctors = type.GetConstructors(); if (ctors.Length == 0) { ctors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance); } Debug.Assert(ctors.Length > 0, "Class must have a constructor!"); int maxParamCount = ctors.Max(ctor => ctor.GetParameters().Length); var maxParamCountCtors = ctors.Where(ctor => ctor.GetParameters().Length == maxParamCount).ToArray(); object obj; if (maxParamCountCtors.Length == 1) { ConstructorInfo ctor = maxParamCountCtors[0]; if (resolutionPath.Contains(type)) { throw new ObjectContainerException("Circular dependency found! " + type.FullName, resolutionPath); } var args = ResolveArguments(ctor.GetParameters(), keyToResolve, resolutionPath.AddToEnd(type)); obj = ctor.Invoke(args); } else { throw new ObjectContainerException("Multiple public constructors with same maximum parameter count are not supported! " + type.FullName, resolutionPath); } return(obj); }
/// <summary> /// Returns available resolutions with RGB color system for device moniker /// </summary> /// <param name="moniker">Moniker (device identification) of camera.</param> /// <returns>List of resolutions with RGB color system of device</returns> public static ResolutionList GetResolutionList(IMoniker moniker) { int hr; ResolutionList ResolutionsAvailable = null; //new ResolutionList(); // Get the graphbuilder object IFilterGraph2 filterGraph = new FilterGraph() as IFilterGraph2; IBaseFilter capFilter = null; try { // add the video input device hr = filterGraph.AddSourceFilterForMoniker(moniker, null, "Source Filter", out capFilter); DsError.ThrowExceptionForHR(hr); ResolutionsAvailable = GetResolutionsAvailable(capFilter); } finally { SafeReleaseComObject(filterGraph); filterGraph = null; SafeReleaseComObject(capFilter); capFilter = null; } return(ResolutionsAvailable); }
static void ListResolutions(ResolutionList resolutions) { Console.WriteLine("List of Resolution "); for (int i = 0; i < resolutions.Count; i++) { Console.WriteLine(" " + resolutions[i].HorizontalDpi + " dpi " + resolutions[i].VerticalDpi + " dpi"); } }
public void FillResolutionListWithDefaultResolutions() { ResolutionList.Add("10 x 10"); ResolutionList.Add("16 x 16"); ResolutionList.Add("20 x 20"); ResolutionList.Add("24 x 24"); ResolutionList.Add("50 x 50"); IsDrawingGrid = true; ChangeGrid("20 x 20"); }
/// <summary> /// Adds video source filter to the filter graph. /// </summary> private void AddFilter_Source() { int hr = 0; DX.CaptureFilter = null; hr = DX.FilterGraph.AddSourceFilterForMoniker(_Moniker, null, "Source Filter", out DX.CaptureFilter); DsError.ThrowExceptionForHR(hr); _ResolutionList = GetResolutionsAvailable(DX.CaptureFilter); }
public void Setting() { VMSetting.RefreshSetting(); Manager.ShowDialog(VMSetting); string sValue = Config.ThreadNum(); ThreadTool.SetThreadNum(int.Parse(sValue)); SelectQualityIndex = QualityList.IndexOf(Config.Quality().ToUpper()); SelectResolutionIndex = ResolutionList.IndexOf(Config.Resolution().ToUpper()); }
private void FillResolutionList() { if (log.IsInfoEnabled) { log.Info("preparing to get list of available resolutions for camera"); } cbResolutionList.Items.Clear(); if (!camControl.CameraCreated) { if (log.IsErrorEnabled) { log.Error("no camera selected that we can query the resolution list from"); } LogWriteLn("There is currently no camera selected that we can query the resolution list from, something's not right!"); return; } try { ResolutionList resolutions = Camera.GetResolutionList(camControl.Moniker); if (resolutions == null) { return; } int index_to_select = -1; for (int index = 0; index < resolutions.Count; index++) { cbResolutionList.Items.Add(resolutions[index].ToString()); if (resolutions[index].CompareTo(camControl.Resolution) == 0) { index_to_select = index; } } // select current resolution if (index_to_select >= 0) { cbResolutionList.SelectedIndex = index_to_select; } } catch (Exception ex) { if (log.IsErrorEnabled) { log.Error("Failed to get lis tof resultions", ex); } LogWriteLn("There was a problem while trying to set the resolution list for the camera: " + ex.Message); } }
private object InvokeFactoryDelegate(Delegate factoryDelegate, ResolutionList resolutionPath, RegistrationKey keyToResolve) { if (resolutionPath.Contains(keyToResolve)) { throw new ObjectContainerException("Circular dependency found! " + factoryDelegate.ToString(), resolutionPath.ToTypeList()); } var args = ResolveArguments(factoryDelegate.Method.GetParameters(), keyToResolve, resolutionPath.AddToEnd(keyToResolve, null)); return(factoryDelegate.DynamicInvoke(args)); }
private ResolutionList(RegistrationKey currentRegistrationKey, Type currentResolvedType, ResolutionList nextNode) { if (nextNode == null) { throw new ArgumentNullException("nextNode"); } this.currentRegistrationKey = currentRegistrationKey; this.currentResolvedType = currentResolvedType; this.nextNode = nextNode; }
public bool Init(Control control, int x, int y, string cameraName) { if (this.IsOpen && this.DeviceName.Equals(cameraName)) { throw new Exception("This camera is opend."); } this.DeviceName = cameraName; this.Width = x; this.Height = y; if (this.DeviceNames.Count <= 0) { throw new Exception("Not find this camera device."); } if (!this.DeviceNames.Contains(DeviceName)) { throw new Exception("Not find this set name device."); } if (control == null) { throw new Exception("The target control parent is null."); } control.Controls.Add(this.CameraControl); this.CameraControl.Dock = DockStyle.Fill; int cameraIndex = this.DeviceNames.IndexOf(DeviceName); var moniker = this.CameraChoice.Devices[cameraIndex].Mon; ResolutionList resolutions = Camera_NET.Camera.GetResolutionList(moniker); if (resolutions == null) { throw new Exception("This camera is not find resolutions"); } var resolution = resolutions.Find(delegate(Resolution a) { return(a.Height == y && a.Width == x); }); if (resolution == null) { throw new Exception("This resolution is not find."); } this.CameraControl.SetCamera(moniker, resolution); isOpen = true; return(IsOpen); }
private object ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath) { if (keyToResolve.Type.IsPrimitive || keyToResolve.Type == typeof(string) || keyToResolve.Type.IsValueType) { throw new ObjectContainerException("Primitive types or structs cannot be resolved: " + keyToResolve.Type.FullName, resolutionPath); } var registrationResult = GetRegistrationResult(keyToResolve) ?? new TypeRegistration(keyToResolve.Type); return(registrationResult.Resolve(this, keyToResolve, resolutionPath)); }
private void SetCameraControlSourceAndResolution(string camName, string res) { LogDebug(String.Format("Setting camera to {0} at res {1}", camName, res)); CameraChoice chooser = new CameraChoice(); chooser.UpdateDeviceList(); DsDevice chosenCam = chooser.GetCameraByName(camName); ResolutionList resolutions = Camera.GetResolutionList(chosenCam.Mon); Camera_NET.Resolution chosenRes = resolutions.Find(x => x.ToString() == res); camControl.SetCamera(chosenCam.Mon, chosenRes); }
private object Resolve(Type typeToResolve, ResolutionList resolutionPath, string name) { AssertNotDisposed(); var keyToResolve = new RegistrationKey(typeToResolve, name); var resolvedObject = resolvedObjects.GetOrAdd( keyToResolve, key => ResolveObject(key, resolutionPath)); return(resolvedObject); }
public IHardwareProxy LoadFromHardwareId(string hardwareId) { if (string.IsNullOrEmpty(hardwareId)) { return(null); } string[] parts = hardwareId.Split("|".ToCharArray()); if (parts.Length < 2) { return(null); } Guid id = new Guid(parts[0]); string resstr = parts[1]; CameraChoice cams = new CameraChoice(); IMoniker moniker = null; foreach (var camera_device in cams.Devices) { if (camera_device.Mon != null) { Guid camid; camera_device.Mon.GetClassID(out camid); if (camid == id) { moniker = camera_device.Mon; break; } } } if (moniker == null) { return(null); } ResolutionList resolutions = Camera.GetResolutionList(moniker); if (resolutions == null) { return(null); } for (int index = 0; index < resolutions.Count; index++) { if (resstr == resolutions[index].ToString()) { CameraProxy proxy = new CameraProxy(); proxy.SetCamera(moniker, resolutions[index]); return(proxy); } } return(null); }
// The trick here is that the index of the selected resolution in the combo box cbResolutionList // will match the index in the ResoltionsList returned by Camera.GetResolutionList void CbResolutionListSelectedIndexChanged(object sender, EventArgs e) { if (log.IsInfoEnabled) { log.Info("Changing camera resolution"); } if (!camControl.CameraCreated) { return; } int resolutionIndex = cbResolutionList.SelectedIndex; if (resolutionIndex < 0) { return; } try { ResolutionList resolutions = Camera.GetResolutionList(camControl.Moniker); if (resolutions == null) { return; } if (resolutionIndex >= resolutions.Count) { return; // throw } if (resolutions[resolutionIndex].CompareTo(camControl.Resolution) == 0) { // this resolution is already selected return; } // Recreate camera if (log.IsInfoEnabled) { log.Info("Setting camera resolution to " + resolutions[resolutionIndex].ToString()); } LogWriteLn("Setting camera resolution to " + resolutions[resolutionIndex].ToString() + Environment.NewLine); camControl.SetCamera(camControl.Moniker, resolutions[resolutionIndex]); } catch (Exception ex) { if (log.IsErrorEnabled) { log.Error("Unable to change resolution", ex); } LogWriteLn("Unable to set selected resolution: " + ex.Message); } }
private object Resolve(Type typeToResolve, ResolutionList resolutionPath, string name) { AssertNotDisposed(); var keyToResolve = new RegistrationKey(typeToResolve, name); object resolvedObject = ResolveObject(keyToResolve, resolutionPath); if (!resolvedKeys.Contains(keyToResolve)) { resolvedKeys.Add(keyToResolve); } Debug.Assert(typeToResolve.IsInstanceOfType(resolvedObject)); return(resolvedObject); }
private ResolutionList(Type type, ResolutionList nextNode) { if (type == null) { throw new ArgumentNullException("type"); } if (nextNode == null) { throw new ArgumentNullException("nextNode"); } this.type = type; this.nextNode = nextNode; }
private object ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath) { if (keyToResolve.Type.IsPrimitive || keyToResolve.Type == typeof(string) || keyToResolve.Type.IsValueType) { throw new ObjectContainerException("Primitive types or structs cannot be resolved: " + keyToResolve.Type.FullName, resolutionPath.ToTypeList()); } var registrationResult = GetRegistrationResult(keyToResolve) ?? new KeyValuePair <ObjectContainer, IRegistration>(this, new TypeRegistration(keyToResolve.Type)); var resolutionPathForResolve = registrationResult.Key == this ? resolutionPath : new ResolutionList(); return(registrationResult.Value.Resolve(registrationResult.Key, keyToResolve, resolutionPathForResolve)); }
public bool AddAndSelectResolution() { if (NewGridWidth <= 0 || NewGridHeight <= 0) { return(true); } SelectedResolution = NewGridWidth + " x " + NewGridHeight; if (ResolutionList.Contains(NewGridWidth + " x " + NewGridHeight)) { return(false); } RemoveOldestResolutionIfMoreThenTen(); ResolutionList.Add(NewGridWidth + " x " + NewGridHeight); return(false); }
public void RemoveOldestResolutionIfMoreThenTen() { if (ResolutionList.Count > 9) { for (int i = 0; i < 10; i++) { if (i == 9) { ResolutionList.RemoveAt(i); } else { ResolutionList[i] = ResolutionList[i + 1]; } } } }
private void FillResolutionList() { try { comboBoxResolutionList.Items.Clear(); if (!cameraControl.CameraCreated) { return; } ResolutionList resolutions = Camera.GetResolutionList(cameraControl.Moniker); if (resolutions == null) { return; } int index_to_select = -1; for (int index = 0; index < resolutions.Count; index++) { comboBoxResolutionList.Items.Add(resolutions[index].ToString()); if (resolutions[index].CompareTo(cameraControl.Resolution) == 0) { index_to_select = index; } } // select current resolution if (index_to_select >= 0) { comboBoxResolutionList.SelectedIndex = resolutions.Count - 1; } } catch (Exception ex) { MessageBox.Show("Please wait for the image to be loaded!", "Message"); } }
/// <summary> /// Constructor. /// </summary> public MainWindow() { InitializeComponent(); m_cameraChoice.UpdateDeviceList(); ResolutionList resolutions = Camera.GetResolutionList(m_cameraChoice.Devices[m_cameraIndex].Mon); Resolution max = null; // use the maximum resolution foreach (Resolution res in resolutions) { if (max == null) { max = res; continue; } if (res.Width > max.Width) { max = res; } } cameraControl.CameraControl.SetCamera(m_cameraChoice.Devices[m_cameraIndex].Mon, max); this.KeyDown += MainWindow_KeyDown; m_window.KeyDown += MainWindow_KeyDown; this.Closing += MainWindow_Closing; this.Loaded += MainWindow_Loaded; m_window.Visibility = Visibility.Hidden; m_timer.Tick += M_timer_Tick; m_timer.Interval = new TimeSpan(0, 0, 1); m_displayTimer.Tick += M_displayTimer_Tick; m_displayTimer.Interval = new TimeSpan(0, 0, 1); m_displayTimer.Start(); }
private void comboBoxResolutionList_SelectedIndexChanged(object sender, EventArgs e) { if (!cameraControl.CameraCreated) { return; } int comboBoxResolutionIndex = comboBoxResolutionList.SelectedIndex; if (comboBoxResolutionIndex < 0) { return; } ResolutionList resolutions = Camera.GetResolutionList(cameraControl.Moniker); if (resolutions == null || comboBoxResolutionIndex >= resolutions.Count() || resolutions[comboBoxResolutionIndex].CompareTo(cameraControl.Resolution) == 0) { return; } cameraControl.SetCamera(cameraControl.Moniker, resolutions[comboBoxResolutionIndex]); }
/// <summary> /// Gets available resolutions (which are appropriate for us) for capture pin (PinCategory.Capture). /// </summary> /// <param name="captureFilter">Capture pin (PinCategory.Capture) for asking for resolution list.</param> private static ResolutionList GetResolutionsAvailable(IPin pinOutput) { int hr = 0; ResolutionList ResolutionsAvailable = new ResolutionList(); //ResolutionsAvailable.Clear(); // Media type (shoudl be cleaned) AMMediaType media_type = null; //NOTE: pSCC is not used. All we need is media_type IntPtr pSCC = IntPtr.Zero; try { IAMStreamConfig videoStreamConfig = pinOutput as IAMStreamConfig; // ------------------------------------------------------------------------- // We want the interface to expose all media types it supports and not only the last one set hr = videoStreamConfig.SetFormat(null); DsError.ThrowExceptionForHR(hr); int piCount = 0; int piSize = 0; hr = videoStreamConfig.GetNumberOfCapabilities(out piCount, out piSize); DsError.ThrowExceptionForHR(hr); for (int i = 0; i < piCount; i++) { // --------------------------------------------------- pSCC = Marshal.AllocCoTaskMem(piSize); videoStreamConfig.GetStreamCaps(i, out media_type, pSCC); // NOTE: we could use VideoStreamConfigCaps.InputSize or something like that to get resolution, but it's deprecated //VideoStreamConfigCaps videoStreamConfigCaps = (VideoStreamConfigCaps)Marshal.PtrToStructure(pSCC, typeof(VideoStreamConfigCaps)); // --------------------------------------------------- if (IsBitCountAppropriate(GetBitCountForMediaType(media_type))) { ResolutionsAvailable.AddIfNew(GetResolutionForMediaType(media_type)); } FreeSCCMemory(ref pSCC); FreeMediaType(ref media_type); } } catch { throw; } finally { // clean up FreeSCCMemory(ref pSCC); FreeMediaType(ref media_type); } return ResolutionsAvailable; }