// This function acts as the body of the example; please see // NodeMapInfo_CSharp example for more in-depth comments on setting up // cameras. public int RunSingleCamera(IManagedCamera cam) { int result = 0; try { // Retrieve TL device nodemap and print device information INodeMap nodeMapTLDevice = cam.GetTLDeviceNodeMap(); result = PrintDeviceInfo(nodeMapTLDevice); // Initialize camera cam.Init(); // Retrieve GenICam nodemap INodeMap nodeMap = cam.GetNodeMap(); // Acquire images result = result | AcquireImages(cam, nodeMap, nodeMapTLDevice); // Deinitialize camera cam.DeInit(); } catch (SpinnakerException ex) { writeLog(String.Format("Error: {0}\n", ex.Message)); result = -1; } return(result); }
private void GetNodeMapsAndInitialize() { nodeMapTLDevice = managedCamera.GetTLDeviceNodeMap(); nodeMapTLStream = managedCamera.GetTLStreamNodeMap(); managedCamera.Init(); nodeMap = managedCamera.GetNodeMap(); Console.WriteLine("Camera number {0} opened and initialized on thread {1}", camNumber, Thread.CurrentThread.ManagedThreadId); }
public override bool Init(int index = 0) { bool ret = false; try { // Retrieve singleton reference to system object ManagedSystem system = new ManagedSystem(); // Retrieve list of cameras from the system IList <IManagedCamera> camList = system.GetCameras(); LogHelper.AppLoger.DebugFormat("Number of cameras detected: {0}", camList.Count); if (camList.Count == 0) { LogHelper.AppLoger.Error("没有发现相机!"); return(ret); } m_Camera = camList[index]; // Retrieve TL device nodemap and print device information INodeMap nodeMapTLDevice = m_Camera.GetTLDeviceNodeMap(); // Initialize camera m_Camera.Init(); // Retrieve GenICam nodemap m_NodeMap = m_Camera.GetNodeMap(); //if (!m_camera.DeviceConnectionStatus.IsRegister) //{ // Dialogs.Show("连接相机失败!"); // return ret; //} //CameraInfo camInfo = m_camera.GetCameraInfo(); IString iDeviceSerialNumber = nodeMapTLDevice.GetNode <IString>("DeviceSerialNumber"); LogHelper.AppLoger.DebugFormat("camera serial number:{0}", iDeviceSerialNumber); //Set embedded timestamp to on //EmbeddedImageInfo embeddedInfo = m_camera.GetEmbeddedImageInfo(); //embeddedInfo.timestamp.onOff = true; //m_camera.SetEmbeddedImageInfo(embeddedInfo); SetAcquisitionMode("Continuous"); ret = true; } catch (Exception ex) { LogHelper.AppLoger.Error(ex); } return(ret); }
// This function acts as the body of the example; please see // NodeMapInfo_CSharp example for more in-depth comments on setting up // cameras. int RunSingleCamera(IManagedCamera cam) { int result = 0; int err = 0; try { // Retrieve TL device nodemap and print device information INodeMap nodeMapTLDevice = cam.GetTLDeviceNodeMap(); result = PrintDeviceInfo(nodeMapTLDevice); // Initialize camera cam.Init(); // Retrieve GenICam nodemap INodeMap nodeMap = cam.GetNodeMap(); // Acquire images List <IManagedImage> images = new List <IManagedImage>(); err = result | AcquireImages(cam, nodeMap, ref images); if (err < 0) { return(err); } // Create video result = result | SaveListToVideo(nodeMap, nodeMapTLDevice, ref images); // Deinitialize camera cam.DeInit(); } catch (SpinnakerException ex) { Console.WriteLine("Error: {0}", ex.Message); result = -1; } return(result); }
public IManagedImage RetrieveMonoImage() { IManagedImage imgResult = null; // Retrieve singleton reference to system object ManagedSystem system = new ManagedSystem(); // Retrieve list of cameras from the system IList <IManagedCamera> camList = system.GetCameras(); if (camList.Count < 1) { writeLog(String.Format("No camera detected. Aborted.\n\n")); return(null); } else { writeLog(String.Format("Number of cameras detected: {0}\n\n", camList.Count)); } // Use the first camera using (camList[0]) { writeLog(String.Format("Running example for the 1st camera...\n")); IManagedCamera cam = camList[0]; try { // Run for a camera // Retrieve TL device nodemap and print device information INodeMap nodeMapTLDevice = cam.GetTLDeviceNodeMap(); PrintDeviceInfo(nodeMapTLDevice); // Initialize camera cam.Init(); // Retrieve GenICam nodemap INodeMap nodeMap = cam.GetNodeMap(); /***** Acquire single BW image from the camera *****/ writeLog(String.Format("\n*** BW IMAGE ACQUISITION ***\n\n")); SetNodeMapItem(nodeMap, "AcquisitionMode", "Continuous"); cam.BeginAcquisition(); using (IManagedImage rawImage = cam.GetNextImage()) { if (rawImage.IsIncomplete) { writeLog(String.Format( "Image incomplete with image status {0}...\n", rawImage.ImageStatus)); imgResult = null; } else { // TODO: Need to return the acquired rawImage here. //IManagedImage monoImage = rawImage.Convert( // PixelFormatEnums.Mono16, ColorProcessingAlgorithm.EDGE_SENSING); IManagedImage monoImage = rawImage.Convert(PixelFormatEnums.Mono8); imgResult = monoImage; } } cam.EndAcquisition(); /***** Acquiring Complete *****/ // Deinitialize camera cam.DeInit(); } catch (SpinnakerException ex) { writeLog(String.Format("Error: {0}\n", ex.Message)); imgResult = null; } writeLog(String.Format("Camera example complete...\n")); } // Clear camera list before releasing system camList.Clear(); // Release system system.Dispose(); writeLog(String.Format("Done!\n")); return(imgResult); }
// This function queries an interface for its cameras and then prints // out device information. int QueryInterface(IManagedInterface managedInterface) { int result = 0; try { // // Retrieve TL nodemap from interface // // *** NOTES *** // Each interface has a nodemap that can be retrieved in order // to access information about the interface itself, any devices // connected, or addressing information if applicable. // INodeMap nodeMapInterface = managedInterface.GetTLNodeMap(); // // Print interface display name // // *** NOTES *** // Grabbing node information requires first retrieving the node // and then retrieving its information. There are two things to // keep in mind. First, a node is distinguished by type, which // is related to its value's data type. Second, nodes should be // checked for availability and readability/writability prior to // making an attempt to read from or write to them. // IString iInterfaceDisplayName = nodeMapInterface.GetNode <IString>("InterfaceDisplayName"); if (iInterfaceDisplayName != null && iInterfaceDisplayName.IsReadable) { string interfaceDisplayName = iInterfaceDisplayName.Value; Console.WriteLine("{0}", interfaceDisplayName); } else { Console.WriteLine("Interface display name not readable"); } // // Update list of cameras on the interface // // *** NOTES *** // Updating the cameras on each interface is especially important // if there has been any device arrivals or removals since the // last time UpdateCameras() was called. // managedInterface.UpdateCameras(); // // Retrieve list of cameras from the interface // // *** NOTES *** // Camera lists can be retrieved from an interface or the system // object. Camera lists retrieved from an interface, such as this // one, only return cameras attached on that specific interface // while camera lists retrieved from system returns all cameras // on all interfaces. // // *** LATER *** // Camera lists must be cleared manually. This must be done // prior to releasing the system and while the camera list is // still in scope. // List <IManagedCamera> camList = managedInterface.GetCameras(); // Return if no cameras detected if (camList.Count == 0) { Console.WriteLine("\tNo devices detected.\n"); return(0); } // Print device vendor and model name for each camera on the // interface for (int i = 0; i < camList.Count; i++) { // // Select camera // // *** NOTES *** // Each camera is retrieved from a camera list with an index. // If the index is out of range, an exception is thrown. // IManagedCamera cam = camList[i]; // Retrieve TL device nodemap; please see NodeMapInfo_CSharp // example for additional information on TL device nodemaps INodeMap nodeMapTLDevice = cam.GetTLDeviceNodeMap(); Console.Write("\tDevice {0} ", i); // Print device vendor name and device model name IString iDeviceVendorName = nodeMapTLDevice.GetNode <IString>("DeviceVendorName"); if (iDeviceVendorName != null && iDeviceVendorName.IsReadable) { String deviceVendorName = iDeviceVendorName.Value; Console.Write("{0} ", deviceVendorName); } IString iDeviceModelName = nodeMapTLDevice.GetNode <IString>("DeviceModelName"); if (iDeviceModelName != null && iDeviceModelName.IsReadable) { String deviceModelName = iDeviceModelName.Value; Console.WriteLine("{0}\n", deviceModelName); } // Dispose of managed camera cam.Dispose(); // // Clear camera list before losing scope // // *** NOTES *** // If a camera list (or an interface list) is not cleaned up // manually, the system will do so when the system is // released. // camList.Clear(); } } catch (SpinnakerException ex) { Console.WriteLine("Error " + ex.Message); result = -1; } return(result); }
public MainWindow() { InitializeComponent(); time.Tick += new EventHandler(Time_Tick); time.Interval = 10; exposureControl.sliderName.Content = "曝光时间"; exposureControl.sliderCheck.Content = "手动曝光"; frameRateControl.sliderName.Content = "帧率"; frameRateControl.sliderCheck.Content = "手动帧率"; blackLevelControl.sliderName.Content = "灰度偏移"; blackLevelControl.sliderCheck.Content = "手动偏移"; GainControl.sliderName.Content = "增益"; GainControl.sliderCheck.Content = "手动增益"; acceptPointValue.sliderName.Content = "接受阈值"; acceptPointValue.sliderCheck.Content = "手动"; if (SavePath == null) { SavePath = "./"; } FileStream fileStream; try { fileStream = new FileStream(SavePath + "test.txt", FileMode.Create); fileStream.Close(); File.Delete("test.txt"); } catch { Console.WriteLine("权限不足"); return; } // 单例 system = new ManagedSystem(); // 输出当前库版本 LibraryVersion spinVersion = system.GetLibraryVersion(); Console.WriteLine("Spinnaker library version: {0}.{1}.{2}.{3}\n\n", spinVersion.major, spinVersion.minor, spinVersion.type, spinVersion.build); //输出相机参数-0 camList = system.GetCameras(); if (camList.Count == 0) { camList.Clear(); system.Dispose(); Console.WriteLine("无相机!"); return; } cam = camList[0]; INodeMap nodeMapTLDevice = cam.GetTLDeviceNodeMap(); PrintDeviceInfo(nodeMapTLDevice); // 为文件名检索设备序列号 // *** NOTES *** // 设备序列号可以放置其他设备覆盖本设备图像 // 图像ID和帧ID // deviceSerialNumber = ""; while (true) { try { cam.Init(); break; } catch (SpinnakerException e) { Console.WriteLine("init error"); Thread.Sleep(1000); } } while (cam.DeviceIndicatorMode.Value != DeviceIndicatorModeEnums.Active.ToString()) { Thread.Sleep(1000); } //相机参数初始化 cam.ExposureAuto.Value = ExposureAutoEnums.Continuous.ToString(); cam.AcquisitionFrameRateEnable.Value = true; frameRateManualDisable(); //cam.BlackLevelAuto.Value = BlackLevelAutoEnums.Continuous.ToString(); cam.GainAuto.Value = GainAutoEnums.Continuous.ToString(); Console.WriteLine("设备序列号为: {0}", cam.DeviceSerialNumber.Value); Console.WriteLine("曝光时间设置为 {0} us", cam.ExposureTime.Value); cam.DeviceLinkThroughputLimit.Value = cam.DeviceLinkThroughputLimit.Max; Console.WriteLine("当前带宽:{0}", cam.DeviceLinkThroughputLimit.Value); Console.WriteLine("当前帧率:{0} Hz", cam.AcquisitionFrameRate.Value); #if DEBUG // 判断是否禁用了心跳检测 if (DisableHeartbeat() != 0) { Console.WriteLine("心跳检测未禁用"); System.Windows.Application.Current.Shutdown(); } #endif //调用刷新控件 flushControl(); //接受点阈值 acceptPointValue.slider.Maximum = 255; acceptPointValue.slider.Minimum = 0; acceptPointValue.slider.Value = 60; //控件委托 #region exposureControl.setSliderEvent += () => { cam.ExposureTime.Value = exposureControl.slider.Value; }; exposureControl.setCheckedEvent += () => { cam.ExposureAuto.Value = ExposureAutoEnums.Off.ToString(); }; exposureControl.setUnCheckEvent += () => { cam.ExposureAuto.Value = ExposureAutoEnums.Continuous.ToString(); }; frameRateControl.setSliderEvent += () => { cam.AcquisitionFrameRate.Value = frameRateControl.slider.Value; }; frameRateControl.setCheckedEvent += frameRateManualEnable; frameRateControl.setUnCheckEvent += frameRateManualDisable; //blackLevelControl.setSliderEvent += () => { cam.BlackLevelAuto.Value = BlackLevelAutoEnums.Off.ToString(); }; blackLevelControl.slider.IsEnabled = false; GainControl.setSliderEvent += () => { cam.Gain.Value = GainControl.slider.Value; }; GainControl.setCheckedEvent += () => { cam.GainAuto.Value = GainAutoEnums.Off.ToString(); }; GainControl.setUnCheckEvent += () => { cam.GainAuto.Value = GainAutoEnums.Continuous.ToString(); }; #endregion acceptPointValue.sliderCheck.IsChecked = true; }