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(); // Set Line0 to input IEnum enumLineSelector = nodeMap.GetNode <IEnum>("LineSelector"); enumLineSelector.FromString("Line0"); IEnum enumLineMode = nodeMap.GetNode <IEnum>("LineMode"); enumLineMode.FromString("Input"); // Switch on Trigger Mode(IEnumeration). IEnum enumTriggerMode = nodeMap.GetNode <IEnum>("TriggerMode"); enumTriggerMode.FromString("On"); // Set Trigger Source to Line0 as Hardware input IEnum enumTriggerSource = nodeMap.GetNode <IEnum>("TriggerSource"); enumTriggerSource.FromString("Line0"); // Set trigger activation to active high IEnum enumTriggerActive = nodeMap.GetNode <IEnum>("TriggerActivation"); enumTriggerActive.FromString("RisingEdge"); // ============================================================================================================== 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(); // ============================================================================================================== // 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)) { // ==== 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 { 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)) 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 Exposure Auto(IEnumeration). IEnum enumExposureAuto = nodeMap.GetNode <IEnum>("ExposureAuto"); enumExposureAuto.FromString("Continuous"); // Get Node for Auto Luminance Target(IInteger) IInteger intAutoLuminTgt = nodeMap.GetNode <IInteger>("AutoLuminanceTarget"); // Set Auto Luminance Target to 128 intAutoLuminTgt.Value = 128; // Get Node for ExposureAutoLimitMin(IFloat). IFloat floatExpoAutoMin = nodeMap.GetNode <IFloat>("ExposureAutoLimitMin"); // Set Auto Exposure time Min to 1,000 usec floatExpoAutoMin.Value = 1000; // Get Node for ExposureAutoLimitMax(IFloat). IFloat floatExpoAutoMax = nodeMap.GetNode <IFloat>("ExposureAutoLimitMax"); // Set Auto Exposure time Max to 150,000 usec floatExpoAutoMax.Value = 150000; // ============================================================================================================== 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(); } }
// Method for handling callback action static void OnCallback(IStCallbackParamBase paramBase, object[] param) { // Check callback type. Only NewBuffer event is handled in here if (paramBase.CallbackType == eStCallbackType.TL_DataStreamNewBuffer) { // In case of receiving a NewBuffer events: // Convert received callback parameter into IStCallbackParamGenTLEventNewBuffer for acquiring additional information. IStCallbackParamGenTLEventNewBuffer callbackParam = paramBase as IStCallbackParamGenTLEventNewBuffer; if (callbackParam != null) { try { // Get the IStDataStream interface object from the received callback parameter. IStDataStream dataStream = callbackParam.GetIStDataStream(); // Retrieve the buffer of image data for that callback indicated there is a buffer received. using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(0)) { // 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 CStImageDisplayWnd wnd = (CStImageDisplayWnd)param[0]; // 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."); } } } catch (Exception e) { // If any exception occurred, display the description of the error here. Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } } } }
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 { 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 decimation horizontal/vertical to 2. // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Get Node for Horizontal Decimation IInteger IntDeciH = nodeMap.GetNode <IInteger>("DecimationHorizontal"); // Set Decimation Horizontal to 2. IntDeciH.Value = 2; // Get Node for Vertical Decimation IInteger IntDeciV = nodeMap.GetNode <IInteger>("DecimationVertical"); // Set Decimation Vertical to 2. IntDeciV.Value = 2; // ============================================================================================================== 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 { // 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(); } }