示例#1
0
        /// <summary>Flushes the input buffer and tries to receive the next frame</summary>
        bool CaptureFrame(out Image frame)
        {
            frame = new Image();

            if (!IsConnected)
            {
                throw new ApplicationException("Cannot capture frames when no device is connected.");
            }

            const int FrameTimeout = 150;    // ms

            // Flush input queue to remove any desync with device stream.
            GenICam.GigEVision_FlushInputQueue(DeviceHandle.Value);

            // 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.
            //mr?? GigEVision_TryReceiveImage() 是异步方法吗
            //public static bool GigEVision_TryReceiveImage
            //(
            //    int inDeviceHandle,
            //    int inTimeout,
            //    AvlNet.Image outImage,
            //    out ulong outFrameId,
            //    out ulong outTimestamp
            //)
            if (!GenICam.GigEVision_TryReceiveImage(DeviceHandle.Value, FrameTimeout, frame))
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        /// <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);
        }