public bool OpenCameraByCameraID(string CamID) { bool res = false; int camIdx = GetCameraID(CamID); if (camIdx == -1) { return(res); } try { if (!m_imageProvider.IsOpen) { m_imageProvider.Open((uint)camIdx); } res = true; //m_imageProvider.ContinuousShot(); /* Start the grabbing of images until grabbing is stopped. */ } catch (Exception) { //ShowException(e, m_imageProvider.GetLastErrorMessage()); res = false; } //res = true; return(res); }
/* Handles the selection of cameras from the list box. The currently open device is closed and the first * selected device is opened. */ private void deviceListView_SelectedIndexChanged(object sender, EventArgs ev) { /* Close the currently open image provider. */ /* Stops the grabbing of images. */ Stop(); /* Close the image provider. */ CloseTheImageProvider(); /* Open the selected image provider. */ if (deviceListView.SelectedItems.Count > 0) { /* Get the first selected item. */ ListViewItem item = deviceListView.SelectedItems[0]; /* Get the attached device data. */ DeviceEnumerator.Device device = item.Tag as DeviceEnumerator.Device; try { /* Open the image provider using the index from the device data. */ m_imageProvider.Open(device.Index); } catch (Exception e) { ShowException(e, m_imageProvider.GetLastErrorMessage()); } } }
private void Open() { if (grabbing) { Stop(); } try { deviceHandle = Pylon.CreateDeviceByIndex(deviceIndex); imageProvider.Open(deviceHandle); } catch (Exception e) { log.Error("Could not open Basler device."); LogError(e, imageProvider.GetLastErrorMessage()); return; } if (!deviceHandle.IsValid) { return; } SpecificInfo specific = summary.Specific as SpecificInfo; if (specific == null) { return; } // Store the handle into the specific info so that we can retrieve device informations from the configuration dialog. specific.Handle = deviceHandle; GenApiEnum currentStreamFormat = PylonHelper.ReadEnumCurrentValue(deviceHandle, "PixelFormat"); if (!string.IsNullOrEmpty(specific.StreamFormat) && specific.StreamFormat != currentStreamFormat.Symbol) { PylonHelper.WriteEnum(deviceHandle, "PixelFormat", specific.StreamFormat); } // The bayer conversion mode will be set during Prepare(). if (firstOpen) { // Restore camera parameters from the XML blurb. // Regular properties, including image size. // First we read the current properties from the API to get fully formed properties. // We merge the values saved in the XML into the properties. // (The restoration from the XML doesn't create fully formed properties, it just contains the values). // Then commit the properties to the camera. Dictionary <string, CameraProperty> cameraProperties = CameraPropertyManager.Read(deviceHandle, summary.Identifier); CameraPropertyManager.MergeProperties(cameraProperties, specific.CameraProperties); specific.CameraProperties = cameraProperties; CameraPropertyManager.WriteCriticalProperties(deviceHandle, specific.CameraProperties); } else { CameraPropertyManager.WriteCriticalProperties(deviceHandle, specific.CameraProperties); } }
private void UpdateDeviceList() { try { /* 向設備列舉器詢問設備列表。 */ List <DeviceEnumerator.Device> list = DeviceEnumerator.EnumerateDevices(); /* 將每個新設備添加到列表中。 */ foreach (DeviceEnumerator.Device device in list) { ListViewItem item = new ListViewItem(device.Name); if (device.Tooltip.Length > 0) { item.ToolTipText = device.Tooltip; } item.Tag = device; //******// try { // 使用設備數據中的索引打開圖像提供者。 m_imageProvider.Open(device.Index); } catch (Exception e) { ShowException(e, m_imageProvider.GetLastErrorMessage()); } //*******// } } catch (Exception e) { ShowException(e, m_imageProvider.GetLastErrorMessage()); } }
/// <summary> /// Opens the Pylon library to Camera Index. /// </summary> public void Open() { try { ImageProvider.Open(Index); } catch (Exception ex) { log.Fatal("ERROR while opening device with Index " + Index); log.Fatal("Device Info: " + FullName); log.Fatal("Exception: " + ex.ToString()); OnErrorReceived?.Invoke(this, ex); } }
public SnapshotRetriever(CameraSummary summary, uint deviceIndex) { this.summary = summary; imageProvider.GrabErrorEvent += imageProvider_GrabErrorEvent; imageProvider.DeviceRemovedEvent += imageProvider_DeviceRemovedEvent; imageProvider.ImageReadyEvent += imageProvider_ImageReadyEvent; try { imageProvider.Open(deviceIndex); } catch (Exception e) { LogError(e, imageProvider.GetLastErrorMessage()); } }
//打开相机 public void Open_Cam() { /* Close the currently open image provider. */ /* Stops the grabbing of images. */ Stop(); /* Close the image provider. */ CloseTheImageProvider(); //选择相机 if (Device_list.Count > 0) { m_imageProvider.Open(Device_list[0].Index); } else { MessageBox.Show("无可用相机!!"); } }
public override void Connect() { //Stop,and Close m_imageProvider.Stop(); m_imageProvider.Close(); setStatus(GrabInstruction.Connect, GrabStage.Closed, GrabState.Idle); Status.IsConnection = false; List <DeviceEnumerator.Device> list = DeviceEnumerator.EnumerateDevices(); var device = list.FirstOrDefault(); if (device != null) { m_imageProvider.Open(device.Index); setStatus(GrabInstruction.Connect, GrabStage.Connected, GrabState.Idle); Status.IsConnection = true; } }
/* Handles the selection of cameras from the list box. The currently open device is closed and the first * selected device is opened. */ private void deviceListView_SelectedIndexChanged(object sender, EventArgs ev) { /* Close the currently open image provider. */ /* Stops the grabbing of images. */ Stop(); /* Close the image provider. */ CloseTheImageProvider(); /* Open the selected image provider. */ if (deviceListView.SelectedItems.Count > 0) { /* Get the first selected item. */ ListViewItem item = deviceListView.SelectedItems[0]; /* Get the attached device data. */ DeviceEnumerator.Device device = (DeviceEnumerator.Device)item.Tag; try { /* Open the image provider using the index from the device data. */ m_imageProvider.Open(device.Index); m_imageProvider.GetNodeFromDevice(device.Name); hDev = Pylon.CreateDeviceByIndex(device.Index); } catch (Exception e) { ShowException(e, m_imageProvider.GetLastErrorMessage()); } } // Console.WriteLine(m_imageProvider.get_integerParam("Width").ToString()); // hDev = new PYLON_DEVICE_HANDLE(); // Pylon.Initialize(); /* Enumerate all camera devices. You must call * PylonEnumerateDevices() before creating a device. */ /* if (0 == Pylon.EnumerateDevices()) * { * throw new Exception("No devices found."); * } */ }
public SnapshotRetriever(CameraSummary summary, uint deviceIndex) { this.summary = summary; imageProvider.GrabErrorEvent += imageProvider_GrabErrorEvent; imageProvider.DeviceRemovedEvent += imageProvider_DeviceRemovedEvent; imageProvider.ImageReadyEvent += imageProvider_ImageReadyEvent; try { stopwatch.Start(); imageProvider.Open(deviceIndex); log.DebugFormat("{0} opened in {1} ms.", summary.Alias, stopwatch.ElapsedMilliseconds); stopwatch.Stop(); } catch (Exception e) { LogError(e, imageProvider.GetLastErrorMessage()); } }
private void Open() { // Unlike in the DirectShow module, we do not backup and restore camera configuration. // If the user configured the camera outside of Kinovea we respect the new settings. // Two reasons: // 1. In DirectShow we must do the backup/restore to work around drivers that inadvertently reset the camera properties. // 2. Industrial cameras have many properties that won't be configurable in Kinovea // so the user is more likely to configure the camera from the outside. if (grabbing) { Stop(); } try { deviceHandle = Pylon.CreateDeviceByIndex(deviceIndex); imageProvider.Open(deviceHandle); } catch (Exception e) { log.Error("Could not open Basler device."); LogError(e, imageProvider.GetLastErrorMessage()); return; } if (!deviceHandle.IsValid) { return; } SpecificInfo specific = summary.Specific as SpecificInfo; if (specific == null) { return; } // Store the handle into the specific info so that we can retrieve device informations from the configuration dialog. specific.Handle = deviceHandle; GenApiEnum currentStreamFormat = PylonHelper.ReadEnumCurrentValue(deviceHandle, "PixelFormat"); // Some properties can only be changed when the camera is opened but not streaming. // We store them in the summary when coming back from FormConfiguration, and we write them to the camera here. // Only do this if it's not the first time we open the camera, to respect any change that could have been done outside Kinovea. if (!firstOpen) { if (specific.StreamFormat != currentStreamFormat.Symbol) { PylonHelper.WriteEnum(deviceHandle, "PixelFormat", specific.StreamFormat); } if (specific.CameraProperties != null && specific.CameraProperties.ContainsKey("framerate")) { if (specific.CameraProperties.ContainsKey("enableFramerate") && specific.CameraProperties["enableFramerate"].Supported) { bool enabled = bool.Parse(specific.CameraProperties["enableFramerate"].CurrentValue); if (!enabled && !specific.CameraProperties["enableFramerate"].ReadOnly) { specific.CameraProperties["enableFramerate"].CurrentValue = "true"; CameraPropertyManager.Write(deviceHandle, specific.CameraProperties["enableFramerate"]); } } CameraPropertyManager.Write(deviceHandle, specific.CameraProperties["framerate"]); } if (specific.CameraProperties != null && specific.CameraProperties.ContainsKey("width") && specific.CameraProperties.ContainsKey("height")) { CameraPropertyManager.Write(deviceHandle, specific.CameraProperties["width"]); CameraPropertyManager.Write(deviceHandle, specific.CameraProperties["height"]); } } else { specific.StreamFormat = currentStreamFormat.Symbol; } }