예제 #1
0
        public virtual void FrameArrived(LiveFrame frame)
        {
            // When the first frame arrive, start the calibration operation. This won't work
            // if we try to do it right after calling _sensor.Open().
            if (_calibration == null)
            {
                _calibration = Calibrator.CalibrateAsync(_reader.Sensor);
            }

            if (_capturingShot == null)
            {
                return;
            }

            // (1) Serialize frame data

            if (_frameCount >= _frames.Length)
            {
                Console.WriteLine(string.Format("Too many frames! Got {0} but we only have room for {1}", _frameCount + 1, _frames.Length));
            }
            else
            {
                _frames[_frameCount].Update(frame, _serializer);
            }

            // Increment whether we saved the data or not (this allows an improved error message)
            _frameCount += 1;

            if (_frameCount < _capturingShot.ShotDefinition.MaximumFrameCount)
            {
                return;
            }

            // (2) Move to the next shot
            string message;

            if (!ValidateShot(out message))
            {
                this.ClearFrames();

                var ea2 = new SessionManagerEventArgs <TShot, TShotDefinition, TSavedItem>(_capturingShot, message);

                _capturingShot = null;

                if (ShotCompletedError != null)
                {
                    ShotCompletedError(this, ea2);
                }

                return;
            }

            var ea = new SessionManagerEventArgs <TShot, TShotDefinition, TSavedItem>(_capturingShot, message);

            _writingShot   = _capturingShot;
            _capturingShot = null;

            if (ShotCompletedSuccess != null)
            {
                ShotCompletedSuccess(this, ea);
            }

            FinishShot();
        }
        public virtual void FrameArrived(object sender, FrameArrivedEventArgs ea)
        {
            // When the first frame arrive, start the calibration operation. This won't work
            // if we try to do it right after calling _sensor.Open().
            if (_calibration == null)
            {
                _calibration = Calibrator.CalibrateAsync(_reader);
                // set device config once
                //_reader.Device.SetDeviceConfig();
            }

            if (_capturingShot == null)
            {
                return;
            }

            if (_mode == CaptureMode.Sweeping && !_sweeping)
            {
                return;
            }

            if (!_cameraConfigLocked)
            {
                LockCameraExposureAndGain();
                _cameraConfigLocked = true;
            }

            if (!_lastShotTaken.HasValue)
            {
                _lastShotTaken = DateTime.Now;
            }

            DateTime currentFrame = DateTime.Now;

            double durationFromLastShot = (currentFrame - _lastShotTaken.Value).TotalMilliseconds;


            if (durationFromLastShot != 0 && durationFromLastShot < _capturingShot.ShotDefinition.ShotDuration)
            {
                return;
            }
            // (1) Serialize frame data

            if (_frameCount >= _session.MaximumFrameCount)
            {
                Console.WriteLine(string.Format("Too many frames! Got {0} but we only have room for {1}", _frameCount + 1, _session.MaximumFrameCount));
            }

            _frameHandles.Add(ea.FrameHandle.Clone());

            // Increment whether we saved the data or not (this allows an improved error message)
            _frameCount += 1;

            if (FrameCaptured != null)
            {
                var outEvent = new Smithers.Sessions.SessionManagerEventArgs <TShot, TShotDefinition, TSavedItem>(_capturingShot, null, null);
                FrameCaptured(this, outEvent);
            }


            if (_mode == CaptureMode.Sweeping)
            {
                if (_capturingShot != null && _frameCount < _capturingShot.ShotDefinition.MaximumFrameCount)
                {
                    _lastShotTaken = DateTime.Now;
                    return;
                }
            }
            else if ((_mode != CaptureMode.Sweeping) && _frameCount < _capturingShot.ShotDefinition.MaximumFrameCount)
            {
                return;
            }

            if (_capturingShot != null)
            {
                MoveToNextShot();
            }
        }