Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResultsViewModel"/> class.
        /// </summary>
        /// <param name="tabName">The tab name string</param>
        /// <param name="templateId">Id of template used for recognition</param>
        /// <param name="isGenerated">Indicates if template was generated</param>
        public ResultsViewModel(string tabName, string templateId, bool isGenerated)
        {
            this.templateId = templateId;
            this.TabName    = tabName;

            this.IsGeneratedTemplate           = isGenerated;
            this.PreviewImages                 = new ObservableCollection <ImagePreviewViewModel>();
            this.InitialPreviewPanelVisibility = Visibility.Visible;
            this.PresetShown = false;

            if (PreprocessingConfigurationManager.CheckConfigExists(this.templateId))
            {
                this.SelectedPreprocessingConfiguration =
                    PreprocessingConfiguration.Deserialize(
                        PreprocessingConfigurationManager.GetConfigByKey(this.templateId));
                this.PresetShown = true;
            }

            ZoomKoefficient = 1;
            this.zoomLevel  = 1;

            this.InitCommands();

            if (this.PreviewImages.Count == 0)
            {
                this.CurrentStage = ResultProcessingStages.NoImages;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Display preset settings and update configuration after view closed
        /// </summary>
        private void OnShowPresets()
        {
            this.PresetShown = true;

            PreprocessingPresetsViewModel viewModel = new PreprocessingPresetsViewModel(this.IsGeneratedTemplate,
                                                                                        this.SelectedPreprocessingConfiguration);

            if (viewModel.Configuration != null)
            {
                this.SelectedPreprocessingConfiguration = viewModel.Configuration;

                PreprocessingConfigurationManager.AddConfig(this.templateId,
                                                            PreprocessingConfiguration.Serialize(this.SelectedPreprocessingConfiguration));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Preprocess image according to selected configuration
        /// </summary>
        /// <param name="pathToImage">Path to the image</param>
        /// <param name="config">Preprocessing configuration</param>
        /// <returns>Preprocessed image data</returns>
        private byte[] PreprocessImage(string pathToImage, PreprocessingConfiguration config)
        {
            long fileLengthKb = new FileInfo(pathToImage).Length / 1024;

            // if preprocessing enabled and image size is bigger then threshold preprocess
            if (config.IsPreprocessingEnabled && fileLengthKb > config.ExcludeImagesSize)
            {
                byte[] imageData = ImageProcessor.CompressAndResizeImage(pathToImage, config.JpegCompressionLevel,
                                                                         config.DesiredWidth, config.DesiredHeight);

                return(imageData);
            }
            // simply pack data without resize
            else
            {
                byte[] imageData = File.ReadAllBytes(pathToImage);
                return(imageData);
            }
        }