static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of Setting Software Trigger ON // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch on Trigger Mode(IEnumeration). IEnum enumTriggerMode = nodeMap.GetNode <IEnum>("TriggerMode"); enumTriggerMode.FromString("On"); // Set Trigger Source to Software IEnum enumTriggerSource = nodeMap.GetNode <IEnum>("TriggerSource"); enumTriggerSource.FromString("Software"); // Prepear Software Trigger Command for later calling ICommand cmdTriggerSoftware = nodeMap.GetNode <ICommand>("TriggerSoftware"); // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { // =============================================================================== // Demostration sending software trigger cmdTriggerSoftware.Execute(); Console.WriteLine("Software Trigger Sent."); // =============================================================================== using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); // ============================================================================================================== // Set Software Trigger OFF after using // Switch off Trigger Mode(IEnumeration) after acquiring. enumTriggerMode.FromString("Off"); // ============================================================================================================== } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of Setting Auto Gain Control with dedicated range. // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch on Gain Auto(IEnumeration). IEnum enumGainAuto = nodeMap.GetNode <IEnum>("GainAuto"); enumGainAuto.FromString("Continuous"); // Get Node for Auto Luminance Target(IInteger) IInteger intAutoLuminTgt = nodeMap.GetNode <IInteger>("AutoLuminanceTarget"); // Set Auto Luminance Target to 128 intAutoLuminTgt.Value = 128; // For setting analog gain, gain selector need to be set to AnalogAll to access analog gain. IEnum enumGainSelector = nodeMap.GetNode <IEnum>("GainSelector"); enumGainSelector.FromString("AnalogAll"); // Get Node for GainAutoLimitMin(IFloat). IFloat floatGainAutoMin = nodeMap.GetNode <IFloat>("GainAutoLimitMin"); // Set Auto Gain Min to 0 dB (0). floatGainAutoMin.Value = 20; // Get Node for GainAutoLimitMax(IFloat). IFloat floatGainAutoMax = nodeMap.GetNode <IFloat>("GainAutoLimitMax"); // Set Auto Gain Max to 10 dB (100). floatGainAutoMax.Value = 100; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
//public void CaptureSaveSyn(string SavePath, string FileType) //{ // try // { // stImage = null; // // 顯示裝置名稱 // Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // //dataStream.RegisterCallbackMethod(OnCallback); // // 主機端獲取影像 // dataStream.StartAcquisition(1); // // 開始由相機取得影像 // device.AcquisitionStart(); // // 逾時超過5000ms後,回收儲存影像資料的暫存區 // // 使用 'using' 語法可在不需使用時,自動管理暫存區重新排隊操作 // using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) // { // // 檢查取得的資料是否包含影像資料 // if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) // { // string sFT = FileType.ToLower(); // stImage = streamBuffer.GetIStImage(); // SavePath += (@"\" + device.GetIStDeviceInfo().DisplayName + @"\" + DateTime.Now.ToString("yyyyMMdd_HHmmss")); // if (sFT == "bitmap" || sFT == "bmp" || sFT == ".bmp") // { // SavePath += ".jpg"; // } // else if (sFT == "tiff" || sFT == "tif" || sFT == ".tif") // { // SavePath += ".tif"; // } // else if (sFT == "png" || sFT == ".png") // { // SavePath += ".png"; // } // else if (sFT == "jpeg" || sFT == "jpg" || sFT == ".jpg") // { // SavePath += ".jpg"; // stillImageFiler.Quality = 75; // } // else if (sFT == "csv" || sFT == ".csv") // { // SavePath += ".csv"; // } // else //要轉換的檔案格式(副檔名)錯誤 // throw new Exception("File Type was wrong."); // this.SaveImage(stImage, SavePath, sFT); // device.AcquisitionStop(); // dataStream.StopAcquisition(); // //// 顯示接收影像的詳細資訊 // //Byte[] imageData = stImage.GetByteArray(); // //Console.Write("BlockId=" + streamBuffer.GetIStStreamBufferInfo().FrameID); // //Console.Write(" Size:" + stImage.ImageWidth + " x " + stImage.ImageHeight); // //Console.Write(" First byte =" + imageData[0] + Environment.NewLine); // //var width = (int)stImage.ImageWidth; // //var height = (int)stImage.ImageHeight; // //myimg = new Bitmap(width, height); // ////TODO: https://stackoverflow.com/questions/3474434/set-individual-pixels-in-net-format16bppgrayscale-image // //for (var idx = 0; idx < imageData.Length; idx++) // //{ // // var val = imageData[idx]; // // var color = Color.FromArgb(val, val, val); // // myimg.SetPixel(idx % width, idx / width, color); // //} // } // else // { // // 如果取得的資料不含影像資料 // Console.WriteLine("Image data does not exist."); // } // } // } // catch (Exception ex) // { // device.AcquisitionStop(); // dataStream.StopAcquisition(); // throw ex; // } //} public Bitmap CaptureToImageSyn() { try { stImage = null; bmp = null; CStPixelFormatConverter m_Converter = new CStPixelFormatConverter(); // 顯示裝置名稱 Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); //dataStream.RegisterCallbackMethod(OnCallback); // 主機端獲取影像 dataStream.StartAcquisition(1); // 開始由相機取得影像 device.AcquisitionStart(); // 逾時超過5000ms後,回收儲存影像資料的暫存區 // 使用 'using' 語法可在不需使用時,自動管理暫存區重新排隊操作 using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { // 檢查取得的資料是否包含影像資料 if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { stImage = streamBuffer.GetIStImage(); #region 如果取得的影像是彩色,需經過轉換才能得到每Pixel以RGB排列的Byte[] bool isColor = CStApiDotNet.GetIStPixelFormatInfo(stImage.ImagePixelFormat).IsColor; if (isColor) { // Convert the image data to BGR8 format. m_Converter.DestinationPixelFormat = eStPixelFormatNamingConvention.BGR8; } else { // Convert the image data to Mono8 format. m_Converter.DestinationPixelFormat = eStPixelFormatNamingConvention.Mono8; } m_Converter.Convert(stImage, imageBuffer); #endregion //Byte[] imageData = stImage.GetByteArray(); byte[] imageData = imageBuffer.GetIStImage().GetByteArray(); var width = (int)stImage.ImageWidth; var height = (int)stImage.ImageHeight; //如果影像是彩色的 if (isColor) { bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb); } else//灰階影像 { bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed); //// 下面的代碼是為了修改生成位圖的索引表,從偽彩修改為灰度 ColorPalette palette = bmp.Palette; for (int i = 0; i < 256; i++) { palette.Entries[i] = Color.FromArgb(i, i, i); } bmp.Palette = palette; } // Lock the bits of the bitmap. BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bmp.PixelFormat); // Place the pointer to the buffer of the bitmap. IntPtr ptr = bmpData.Scan0; // fill in rgbValues Marshal.Copy(imageData, 0, ptr, imageData.Length); bmp.UnlockBits(bmpData); //bmp.Save(@"D:/" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".jpg", ImageFormat.Jpeg); } else { // 如果取得的資料不含影像資料 Console.WriteLine("Image data does not exist."); } } return(bmp); } catch (Exception ex) { device.AcquisitionStop(); dataStream.StopAcquisition(); throw ex; } finally { device.AcquisitionStop(); dataStream.StopAcquisition(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of PixelFormat change. // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Set Pixel Format to Mono8. IEnum enumPixelFormat = nodeMap.GetNode <IEnum>("PixelFormat"); enumPixelFormat.FromString("Mono8"); // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of setting ROI to 640 x 480 with offset (100, 200). // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Get Node for Width IInteger intWidth = nodeMap.GetNode <IInteger>("Width"); // Set Width to 640 intWidth.Value = 640; // Get Node for Height IInteger intHeight = nodeMap.GetNode <IInteger>("Height"); // Set Height to 480 intHeight.Value = 480; // Get Node for Offset X IInteger intOffsetX = nodeMap.GetNode <IInteger>("OffsetX"); // Set Offset X to 100 intOffsetX.Value = 100; // Get Node for Offset Y IInteger intOffsetY = nodeMap.GetNode <IInteger>("OffsetY"); // Set Offset Y to 200 intOffsetY.Value = 200; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of changing acquisition frame rate (FPS) // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch off exposure auto. If exposure auto is on, FPS setting may not able to implemented. IEnum enumExposureAuto = nodeMap.GetNode <IEnum>("ExposureAuto"); enumExposureAuto.FromString("Off"); // Also switch Exposure Mode to Off for not letting exposure time to influence the actual FPS. IEnum enumExposureMode = nodeMap.GetNode <IEnum>("ExposureMode"); enumExposureMode.FromString("Off"); // Get Node for Acquisition Frame Rate then set FPS to 2. IFloat floatFPS = nodeMap.GetNode <IFloat>("AcquisitionFrameRate"); floatFPS.SetValue(2, false); // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of Setting Line2 as Strobe Out // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Set Line2 to output IEnum enumLineSelector = nodeMap.GetNode <IEnum>("LineSelector"); enumLineSelector.FromString("Line2"); IEnum enumLineMode = nodeMap.GetNode <IEnum>("LineMode"); enumLineMode.FromString("Output"); // Switch Line2 output source to Timer 0 Active IEnum enumLineSource = nodeMap.GetNode <IEnum>("LineSource"); enumLineSource.FromString("Timer0Active"); // Set Timer 0 trigger source to Exposure Start, which means Timer 0 will output signal when camera start exposure IEnum enumTimerSelector = nodeMap.GetNode <IEnum>("TimerSelector"); enumTimerSelector.FromString("Timer0"); // Set exposure start as the trigger source of Timer0 IEnum enumTimerTriggerSource = nodeMap.GetNode <IEnum>("TimerTriggerSource"); enumTimerTriggerSource.FromString("ExposureStart"); // Set Timer0 output duration to 1000us IFloat floatTimerDuration = nodeMap.GetNode <IFloat>("TimerDuration"); floatTimerDuration.Value = 1000; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of Setting Hardware Trigger ON with active high // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch BalanceWhiteAuto to Preset0 for manual input value IEnum enumBalanceWhiteAuto = nodeMap.GetNode <IEnum>("BalanceWhiteAuto"); enumBalanceWhiteAuto.FromString("Preset0"); // Switch balance ration selector to Red for access Red ratio value IEnum enumBalanceRatioSelector = nodeMap.GetNode <IEnum>("BalanceRatioSelector"); enumBalanceRatioSelector.FromString("Red"); // Get Node for BalanceRatio IFloat floatBalanceRatio = nodeMap.GetNode <IFloat>("BalanceRatio"); // Set BalanceRatio to 10 floatBalanceRatio.Value = 10; // Switch balance ration selector to Blue for access Blue ratio value enumBalanceRatioSelector.FromString("Blue"); // Set BalanceRatio to 10 floatBalanceRatio.Value = 10; // Switch balance ration selector to Green for access Green ratio value enumBalanceRatioSelector.FromString("Green"); // Set BalanceRatio to 10 floatBalanceRatio.Value = 10; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of set digital Gain to 2 times. // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch off gain auto. If gain auto is on, gain value cannot be set. IEnum enumGainAuto = nodeMap.GetNode <IEnum>("GainAuto"); enumGainAuto.FromString("Off"); // For setting digital gain, gain selector need to be set to DigitalAll to access digital gain. IEnum enumGainSelector = nodeMap.GetNode <IEnum>("GainSelector"); enumGainSelector.FromString("DigitalAll"); // Get Node for Gain IFloat floatGain = nodeMap.GetNode <IFloat>("Gain"); // Set digital gain to 2 times(128). floatGain.Value = 128; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of changing exposure time(us) of camera. // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch off exposure auto. If exposure auto is on, exposure time cannot be set. IEnum enumExposureAuto = nodeMap.GetNode <IEnum>("ExposureAuto"); enumExposureAuto.FromString("Off"); // For setting camera exposure time, exposure mode must set to Timed to enable value input IEnum enumExpoMode = nodeMap.GetNode <IEnum>("ExposureMode"); enumExpoMode.FromString("Timed"); // Get Node for ExposureTime IFloat floatExpoTime = nodeMap.GetNode <IFloat>("ExposureTime"); // Set Exposure time to 100,000 usec floatExpoTime.Value = 100000; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of using Filter to rotate image clock wise 90 degree. // Create an ReverseConverter filter object. CStReverseConverter filter = new CStReverseConverter(); // Set ReverseConverter reverse to clock wise 90 degree. filter.RotationMode = eStRotationMode.Clockwise90; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } // ============================================================================================================== // Create another buffer for storing rotated image CStImageBuffer imageBuffer = CStApiDotNet.CreateStImageBuffer(); // Rotate original image and output to another buffer filter.Convert(stImage, imageBuffer); // Display rotated image wnd.RegisterIStImage(imageBuffer.GetIStImage()); // ============================================================================================================== } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) { // ==== Connect to target camera with camera serial. ================================================================ // Input Serial. System.Console.WriteLine("Please input serial number of target camera: "); string sTgtCameraSerial = System.Console.ReadLine(); // Acquire interface counts. uint uiInterfaceCnt = system.InterfaceCount; // Prepear gcstring for saving device ID if hit. string strTgtDeviceID = ""; // Prepear for # of interface for later use. uint uiTgtInterfaceNo = 0; // Camera found hit flag. bool bHit = false; // Check all interface if target camera is exist. for (uint i = 0; i < uiInterfaceCnt; i++) { IStInterface tmpInterface = system.GetIStInterface(i); uint uiCamCnt = tmpInterface.DeviceCount; for (uint j = 0; j < uiCamCnt; j++) { IStDeviceInfo tmpDevInfo = tmpInterface.GetIStDeviceInfo(j); if (tmpDevInfo.SerialNumber == sTgtCameraSerial) { strTgtDeviceID = tmpDevInfo.ID; uiTgtInterfaceNo = i; bHit = true; break; } } if (bHit) { break; } } if (!bHit) { // Not found, exit program with message. System.Console.WriteLine("Target camera not found."); System.Console.WriteLine("Press Enter to exit."); Console.ReadLine(); return; } // Create IStDevice via using found device ID. using (CStDevice device = system.GetIStInterface(uiTgtInterfaceNo).CreateStDevice(strTgtDeviceID)) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); // Display the information of the acquired image data. Byte[] imageData = stImage.GetByteArray(); Console.Write("BlockId=" + streamBuffer.GetIStStreamBufferInfo().FrameID); Console.Write(" Size:" + stImage.ImageWidth + " x " + stImage.ImageHeight); Console.Write(" First byte =" + imageData[0] + Environment.NewLine); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { // Initialize StApi before using. using (CStApiAutoInit api = new CStApiAutoInit()) // Create a system object for device scan and connection. using (CStSystem system = new CStSystem()) // Create a camera device object and connect to first detected device. using (CStDevice device = system.CreateFirstStDevice()) // Create a DataStream object for handling image stream data. using (CStDataStream dataStream = device.CreateStDataStream(0)) { // Displays the DisplayName of the device. Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // Start the image acquisition of the host (local machine) side. dataStream.StartAcquisition(nCountOfImagesToGrab); // Start the image acquisition of the camera side. device.AcquisitionStart(); // Get the path of the image files. string fileNameHeader = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); fileNameHeader += @"\" + device.GetIStDeviceInfo().DisplayName + @"\" + device.GetIStDeviceInfo().DisplayName; bool isImageSaved = false; // Get the file name of the image file of the StApiRaw file format string fileNameRaw = fileNameHeader + ".StApiRaw"; // Retrieve the buffer of image data with a timeout of 5000ms. using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { // Check if the acquired data contains image data. if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { // If yes, we create a IStImage object for further image handling. IStImage stImage = streamBuffer.GetIStImage(); Byte[] imageData = stImage.GetByteArray(); // Display the information of the acquired image data. Console.Write("BlockId=" + streamBuffer.GetIStStreamBufferInfo().FrameID); Console.Write(" Size:" + stImage.ImageWidth + " x " + stImage.ImageHeight); Console.Write(" First byte =" + imageData[0] + Environment.NewLine); // Create a still image file handling class object (filer) for still image processing. using (CStStillImageFiler stillImageFiler = new CStStillImageFiler()) { // Save the image file as StApiRaw file format with using the filer we created. Console.Write(Environment.NewLine + "Saving " + fileNameRaw + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.StApiRaw, fileNameRaw); Console.Write("done" + Environment.NewLine); isImageSaved = true; } } else { // If the acquired data contains no image data. Console.WriteLine("Image data does not exist."); } } // Stop the image acquisition of the camera side. device.AcquisitionStop(); // Stop the image acquisition of the host side. dataStream.StopAcquisition(); // The following code shows how to load the saved StApiRaw and process it. if (isImageSaved) { // Create a buffer for storing the image data from StApiRaw file. using (CStImageBuffer imageBuffer = CStApiDotNet.CreateStImageBuffer()) // Create a still image file handling class object (filer) for still image processing. using (CStStillImageFiler stillImageFiler = new CStStillImageFiler()) // Create a data converter object for pixel format conversion. using (CStPixelFormatConverter pixelFormatConverter = new CStPixelFormatConverter()) { // Load the image from the StApiRaw file into buffer. Console.Write(Environment.NewLine + "Loading " + fileNameRaw + "... "); stillImageFiler.Load(imageBuffer, fileNameRaw); Console.Write("done" + Environment.NewLine); // Convert the image data to BGR8 format. pixelFormatConverter.DestinationPixelFormat = eStPixelFormatNamingConvention.BGR8; pixelFormatConverter.Convert(imageBuffer.GetIStImage(), imageBuffer); // Get the IStImage interface to the converted image data. IStImage stImage = imageBuffer.GetIStImage(); // Save as Bitmap { // Bitmap file extension. string imageFileName = fileNameHeader + ".bmp"; // Save the image file in Bitmap format. Console.Write(Environment.NewLine + "Saving " + imageFileName + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.Bitmap, imageFileName); Console.Write("done" + Environment.NewLine); } // Save as Tiff { // Tiff file extension. string imageFileName = fileNameHeader + ".tif"; // Save the image file in Tiff format. Console.Write(Environment.NewLine + "Saving " + imageFileName + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.TIFF, imageFileName); Console.Write("done" + Environment.NewLine); } // Save as PNG { // PNG file extension. string imageFileName = fileNameHeader + ".png"; // Save the image file in PNG format. Console.Write(Environment.NewLine + "Saving " + imageFileName + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.PNG, imageFileName); Console.Write("done" + Environment.NewLine); } // Save as JPEG { // JPEG file extension. string imageFileName = fileNameHeader + ".jpg"; // Save the image file in JPEG format. stillImageFiler.Quality = 75; Console.Write(Environment.NewLine + "Saving " + imageFileName + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.JPEG, imageFileName); Console.Write("done" + Environment.NewLine); } // Save as CSV { // CSV file extension. string imageFileName = fileNameHeader + ".csv"; // Save the image file in CSV format. Console.Write(Environment.NewLine + "Saving " + imageFileName + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.CSV, imageFileName); Console.Write("done" + Environment.NewLine); } } } } } catch (Exception e) { // If any exception occurred, display the description of the error here. Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { // Wait until the Enter key is pressed. Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { // Initialize StApi before using. using (CStApiAutoInit api = new CStApiAutoInit()) // Create a system object for device scan and connection. using (CStSystem system = new CStSystem()) // Create a camera device object and connect to first detected device by using the function of system object. using (CStDevice device = system.CreateFirstStDevice()) #if ENABLED_ST_GUI // If using GUI for display, create a display window here. using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) #endif // Create a DataStream object for handling image stream data. using (CStDataStream dataStream = device.CreateStDataStream(0)) { // Displays the DisplayName of the device. Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // Start the image acquisition of the host (local machine) side. dataStream.StartAcquisition(nCountOfImagesToGrab); // Start the image acquisition of the camera side. device.AcquisitionStart(); // A while loop for acquiring data and checking status. // Here, the acquisition runs until it reaches the assigned numbers of frames. while (dataStream.IsGrabbing) { // Retrieve the buffer of image data with a timeout of 5000ms. // Use the 'using' statement for automatically managing the buffer re-queue action when it's no longer needed. using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { // Check if the acquired data contains image data. if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { // If yes, we create a IStImage object for further image handling. IStImage stImage = streamBuffer.GetIStImage(); #if ENABLED_ST_GUI // Acquire detail information of received image and display it onto the status bar of the display window. string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); // Check if display window is visible. if (!wnd.IsVisible) { // Set the position and size of the window. wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); // Create a new thread to display the window. wnd.Show(eStWindowMode.ModalessOnNewThread); } // Register the image to be displayed. // This will have a copy of the image data and original buffer can be released if necessary. wnd.RegisterIStImage(stImage); #else // Display the information of the acquired image data. Byte[] imageData = stImage.GetByteArray(); Console.Write("BlockId=" + streamBuffer.GetIStStreamBufferInfo().FrameID); Console.Write(" Size:" + stImage.ImageWidth + " x " + stImage.ImageHeight); Console.Write(" First byte =" + imageData[0] + Environment.NewLine); #endif } else { // If the acquired data contains no image data. Console.WriteLine("Image data does not exist."); } } } // Stop the image acquisition of the camera side. device.AcquisitionStop(); // Stop the image acquisition of the host side. dataStream.StopAcquisition(); } } catch (Exception e) { // If any exception occurred, display the description of the error here. Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { // Wait until the Enter key is pressed. Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }