/// <summary> /// Captures two sequent frames from the camera with different exposure parameter values. /// Each frame is captured after explicit software trigger is sent to the device. /// </summary> private static bool CaptureFramesPair(int handle, double exposure1, double exposure2, Image outFrame1, Image outFrame2) { const int FrameTimeout = 150; // ms // Flush input queue to remove any desync with device stream. GenICam.GigEVision_FlushInputQueue(handle); // Calculate timeouts for frames depending on required exposure time. int timeoutFrame1 = FrameTimeout + (int)(exposure1 / 1000); int timeoutFrame2 = FrameTimeout + (int)(exposure2 / 1000); // Set first exposure time and capture the frame. GenICam.GenApi_SetFloatParam(handle, "ExposureTimeAbs", exposure1); GenICam.GenApi_ExecuteCommand(handle, "TriggerSoftware"); // Await and receive first frame. If this frame gets corrupted or lost we need to explicitly react, otherwise we could // crash because of single frame error or desync with device stream. if (!GenICam.GigEVision_TryReceiveImage(handle, timeoutFrame1, outFrame1)) { return(false); } // Set second exposure time, capture and receive frame. GenICam.GenApi_SetFloatParam(handle, "ExposureTimeAbs", exposure2); GenICam.GenApi_ExecuteCommand(handle, "TriggerSoftware"); if (!GenICam.GigEVision_TryReceiveImage(handle, timeoutFrame2, outFrame2)) { return(false); } return(true); }
/// <summary> /// <para>Setups and verifies capabilities of general camera device of unknown type for this demo. Usually /// application should be created for specific device or device class, some of this setup and verification is /// not obligatory.</para> /// <para>Device parameter setup is based on GenICam SFNC standard.</para> /// </summary> static void SetupDevice(int handle) { Console.WriteLine("Setting up device..."); // Device parameter setup is based on GenICam SFNC standard. // When selector is available, select "FrameStart" trigger in device. This parameter // must be set first because it determines what further parameters point to. if (GenICam.GenApi_GetParamExists(handle, "TriggerSelector")) { GenICam.GenApi_GetEnumParam(handle, "TriggerSelector", true, out defaultTriggerSelector); GenICam.GenApi_SetEnumParam(handle, "TriggerSelector", "FrameStart", true); } // Setup device so that it waits for software command to trigger new frame. GenICam.GenApi_GetEnumParam(handle, "TriggerSource", true, out defaultTriggerSource); GenICam.GenApi_SetEnumParam(handle, "TriggerSource", "Software", true); // Verify that command for software trigger exists. if (!GenICam.GenApi_GetParamExists(handle, "TriggerSoftware")) { throw new MemberAccessException("Command \"TriggerSoftware\" is not defined by device description."); } // Enable trigger if (GenICam.GenApi_GetParamExists(handle, "TriggerMode")) { GenICam.GenApi_GetEnumParam(handle, "TriggerMode", true, out defaultTriggerMode); GenICam.GenApi_SetEnumParam(handle, "TriggerMode", "On", true); } // Set acquisition mode to continuous - device should continue to // wait for triggers after each frame capture. GenICam.GenApi_SetEnumParam(handle, "AcquisitionMode", "Continuous", true); // If this device has automatic exposure, turn it off - we will be controlling // this parameter manually. if (GenICam.GenApi_GetParamExists(handle, "ExposureAuto")) { GenICam.GenApi_SetEnumParam(handle, "ExposureAuto", "Off", false); } // Set initial exposure value (this will also verify, if parameter is available). GenICam.GenApi_SetFloatParam(handle, "ExposureTimeAbs", 15000, true); }