Exemplo n.º 1
0
        public virtual CameraSettingsDto GetCameraSettings()
        {
            CameraSettingsDto settings = null;

            if (File.Exists("CameraPhotoSettings.xml"))
            {
                using (var fs = File.OpenRead("CameraPhotoSettings.xml"))
                {
                    settings = (CameraSettingsDto) new XmlSerializer(typeof(CameraSettingsDto)).Deserialize(fs);
                }
            }
            else
            {
                settings = new CameraSettingsDto
                {
                    SelectedAeMode         = SDKData.Enums.AEMode.Manual,
                    SelectedAvValue        = SDKData.Enums.ApertureValue.AV_8,
                    SelectedIsoSensitivity = SDKData.Enums.CameraISOSensitivity.ISO_400,
                    SelectedWhiteBalance   = SDKData.Enums.WhiteBalance.Daylight,
                    SelectedShutterSpeed   = SDKData.Enums.ShutterSpeed.TV_200,
                };
                using (var fs = File.Open("CameraPhotoSettings.xml", FileMode.OpenOrCreate))
                {
                    new XmlSerializer(typeof(CameraSettingsDto)).Serialize(fs, settings);
                }
            }
            return(settings);
        }
Exemplo n.º 2
0
        public override void Initialize()
        {
            _imageProcessor.TimerElapsed       += ImageProcessorOnTimerElapsed;
            _imageProcessor.CameraErrorEvent   += ImageProcessorOnCameraErrorEvent;
            _imageProcessor.ImageChanged       += ImageProcessorOnStreamChanged;
            _imageProcessor.ImageNumberChanged += ImageProcessorOnImageNumberChanged;


            _imageProcessor.InitializeProcessor();
            OpenSession();
            if (!_sessionOpened)
            {
                return;
            }

            _settings = _settingsProvider.GetCameraSettings();

            if (_settings != null)
            {
                _imageProcessor.SetSetting((uint)PropertyId.AEMode, (uint)_settings.SelectedAeMode);
                _imageProcessor.SetSetting((uint)PropertyId.WhiteBalance, (uint)_settings.SelectedWhiteBalance);
                _imageProcessor.SetSetting((uint)PropertyId.Av, (uint)_settings.SelectedAvValue);
                _imageProcessor.SetSetting((uint)PropertyId.ExposureCompensation, (uint)_settings.SelectedCompensation);
                _imageProcessor.SetSetting((uint)PropertyId.ISOSpeed, (uint)_settings.SelectedIsoSensitivity);
                _imageProcessor.SetSetting((uint)PropertyId.Tv, (uint)_settings.SelectedShutterSpeed);
            }
            _cameraStreamSynchronize = new AutoResetEvent(false);
            StartLiveView();
        }
Exemplo n.º 3
0
        public CameraSettingsDto GetCameraSettings()
        {
            CameraSettingsDto settings = null;

            if (!File.Exists("CameraPhotoSettings.xml"))
            {
                settings = new CameraSettingsDto
                {
                    SelectedAeMode         = SDKData.Enums.AEMode.Manual,
                    SelectedAvValue        = SDKData.Enums.ApertureValue.AV_8,
                    SelectedIsoSensitivity = SDKData.Enums.CameraISOSensitivity.ISO_400,
                    SelectedWhiteBalance   = SDKData.Enums.WhiteBalance.Daylight,
                    SelectedShutterSpeed   = SDKData.Enums.ShutterSpeed.TV_200,
                    SelectedCompensation   = SDKData.Enums.ExposureCompensation.Zero
                };
                using (var file = File.Create("CameraPhotoSettings.xml"))
                {
                    new XmlSerializer(settings.GetType()).Serialize(file, settings);
                    file.Close();
                }
            }
            else
            {
                using (var file = File.OpenRead("CameraPhotoSettings.xml"))
                {
                    settings = (CameraSettingsDto) new XmlSerializer(typeof(CameraSettingsDto)).Deserialize(file);
                    file.Close();
                }
            }
            return(settings);
        }
Exemplo n.º 4
0
        public override void Initialize()
        {
            _logger.Trace("Инициализация");
            _imageProcessor.TimerElapsed       += ImageProcessorOnTimerElapsed;
            _imageProcessor.CameraErrorEvent   += ImageProcessorOnCameraErrorEvent;
            _imageProcessor.ImageChanged       += ImageProcessorOnStreamChanged;
            _imageProcessor.ImageNumberChanged += ImageProcessorOnImageNumberChanged;

            Capturing = false;

            _imageProcessor.InitializeProcessor();
            OpenSession();
            if (!_sessionOpened)
            {
                _dialogService.ShowInfo("Камера не готова, попробуйте ещё раз.");
                _logger.Trace("Неудачная поптыка открытия сессии");
                return;
            }

            _settings = _settingsProvider.GetCameraSettings();

            if (_settings != null)
            {
                _logger.Trace("Применение настроек для камеры");

                //_imageProcessor.SetSetting((uint)PropertyId.AEMode, (uint)_settings.SelectedAeMode); TODO Не поддерживается.
                _imageProcessor.SetSetting((uint)PropertyId.WhiteBalance, (uint)_settings.SelectedWhiteBalance);
                _imageProcessor.SetSetting((uint)PropertyId.Av, (uint)_settings.SelectedAvValue);
                _imageProcessor.SetSetting((uint)PropertyId.ExposureCompensation, (uint)_settings.SelectedCompensation);
                _imageProcessor.SetSetting((uint)PropertyId.ISOSpeed, (uint)_settings.SelectedIsoSensitivity);
                _imageProcessor.SetSetting((uint)PropertyId.Tv, (uint)_settings.SelectedShutterSpeed);
            }
            _cameraStreamSynchronize = new AutoResetEvent(false);
            _logger.Trace("Запуск LiveView");
            StartLiveView();
            var cancellTokenSource = new CancellationTokenSource();

            if (TakePictureCommand.CanExecute(cancellTokenSource.Token))
            {
                try
                {
                    TakePictureCommand.Execute(cancellTokenSource.Token);
                }
                catch (Exception ex)
                {
                    //_dialogService.ShowInfo("Упс... С камерой возникли неполадки. Приносим свои извинения. =(");
                    _logger.Error(ex, "Ошибка при инициализации камеры");
                    GoBack();
                }
            }
            else
            {
                //_dialogService.ShowInfo("Упс... С камерой возникли неполадки. Приносим свои извинения. =(");
                _logger.Trace("TakePictureCommand.CanExecute вернул false");
                GoBack();
            }
        }
        //protected async Task<byte[]> TakePictureInternal(Size liveViewImageStreamSize, CameraSettingsDto settings, CancellationToken token)
        //{
        //    return await Task.Run(() => Run(liveViewImageStreamSize, settings, token), token);
        //}

        private async Task <byte[]> Run(Size liveViewImageStreamSize, CameraSettingsDto settings, CancellationToken token)
        {
            var pictures = new List <byte[]>();

            for (var i = 0; i < _pattern.Images.Count; i++)
            {
                _logger.Trace($"Фото №{i}");

                token.ThrowIfCancellationRequested();
                RaiseImageNumberChanged(i + 1);

                await Task.Delay(TimeSpan.FromSeconds(1), token);

                CommandManager.InvalidateRequerySuggested();

                for (var j = 5; j >= 0; j--)
                {
                    var j1 = j;
                    RaiseTimerElapsed(j1);
                    await Task.Delay(TimeSpan.FromSeconds(1), token);
                }
                _logger.Trace("Отсчёт закончен. Начало применения настроек для камеры.");


                SetCameraSettings(settings.SelectedPhotoAeMode, settings.SelectedPhotoWhiteBalance,
                                  settings.SelectedPhotoAvValue, settings.SelectedPhotoIsoSensitivity,
                                  settings.SelectedPhotoShutterSpeed);
                _logger.Trace("Настройки для камеры применены.");

                //await Task.Delay(TimeSpan.FromSeconds(1));

                //RaiseImageNumberChanged(i + 1);
                //await Task.Delay(TimeSpan.FromSeconds(1), token);
                token.ThrowIfCancellationRequested();
                byte[] picture = await _imageProcessor.DoTakePictureAsync();

                pictures.Add(picture);

                token.ThrowIfCancellationRequested();
                //await Task.Delay(TimeSpan.FromSeconds(3), token); //todo
                _logger.Trace("Фотография сделана. Начало применения настроек для LiveView");

                SetCameraSettings(settings.SelectedAeMode, settings.SelectedWhiteBalance,
                                  settings.SelectedAvValue, settings.SelectedIsoSensitivity,
                                  settings.SelectedShutterSpeed);
                _logger.Trace("Настройки для камеры применены.");

                _logger.Trace("Стоп LiveView.");
                StopLiveView();
                _logger.Trace("Старт LiveView.");
                StartLiveView();
            }

            byte[] result = _imageUtils.ProcessImages(pictures, liveViewImageStreamSize, _pattern);
            return(result);
        }
Exemplo n.º 6
0
 private void StartLiveView()
 {
     _imageProcessor.StartLiveView();
     _settings = _settingsProvider.GetCameraSettings();
     if (_settings != null)
     {
         _imageProcessor.SetSetting((uint)PropertyId.WhiteBalance, (uint)_settings.SelectedWhiteBalance);
         _imageProcessor.SetSetting((uint)PropertyId.Av, (uint)_settings.SelectedAvValue);
         _imageProcessor.SetSetting((uint)PropertyId.ExposureCompensation, (uint)_settings.SelectedCompensation);
         _imageProcessor.SetSetting((uint)PropertyId.ISOSpeed, (uint)_settings.SelectedIsoSensitivity);
         _imageProcessor.SetSetting((uint)PropertyId.Tv, (uint)_settings.SelectedShutterSpeed);
     }
     _isLiveViewOn = true;
 }
        public async Task <byte[]> TakeTestPictureAsync(byte[] liveViewImageStream, CameraSettingsDto settings)
        {
            SetCameraSettings(settings.SelectedAeMode, settings.SelectedPhotoWhiteBalance,
                              settings.SelectedPhotoAvValue, settings.SelectedPhotoIsoSensitivity,
                              settings.SelectedPhotoShutterSpeed);
            byte[] picture = await _imageProcessor.DoTakePictureAsync();

            //byte[] picture = await Task.Run(async () =>
            //{
            //    //    await Task.Delay(500);//TODO Костыль, не понятно почему, но камере реально необходимо время, что бы свойства установились
            //    var res = await _imageProcessor.DoTakePictureAsync();
            //    return res;
            //});
            StopLiveView();
            return(picture);
        }
 public virtual async Task <CompositionProcessingResult> TakePictureAsync(Size liveViewImageStreamSize, CameraSettingsDto settings,
                                                                          CancellationToken token)
 {
     return(new CompositionProcessingResult(_pattern, await Run(liveViewImageStreamSize, settings, token)));
 }
Exemplo n.º 9
0
 public virtual void SaveCameraSettings(CameraSettingsDto settings)
 {
     _user.Value.CameraSettings = settings.Serialize();
     _userRepository.UpdateUser(_user.Value);
     _userRepository.Commit();
 }