Пример #1
0
        private void ExecutePickUpFilesCommand()
        {
            TiffImageLoader imageLoader = new TiffImageLoader();
            var             list        = imageLoader.GetFilesWithPicker();

            if (list.Count == 0)
            {
                return;
            }

            // Use work directory ,not to change original files
            if (Directory.Exists(workDirectory))
            {
                Directory.Delete(workDirectory, true);
            }
            Directory.CreateDirectory(workDirectory);

            imageLoader.DivideMultiTiffImageAndCopyToWorkDirectory(list, workDirectory);

            Items.Clear();

            DirectoryInfo di    = new DirectoryInfo(workDirectory);
            var           files = di.GetFiles();

            foreach (var file in files)
            {
                var item = new ImageFileWithOcrResults();
                item.FilePath = file.FullName;
                Items.Add(item);
            }

            Message = $"{ Items.Count } 件のファイルを取得しました。";

            SetButtonsEnabled();
        }
Пример #2
0
        private void ShowImageWithScrapingRects(bool singleScrapingRect = false)
        {
            // ImageSource
            TiffImageLoader imageLoader = new TiffImageLoader();

            this.ImageSource = imageLoader.CreateBitmapSourceFromPath(Items[imageIndex].FilePath, this.ocrParam);

            // OCR結果をもとにUIの画像を回転
            this.ImageAngle = Items[imageIndex].OcrAngle * -1;

            // ScrapingRectsImage
            var tempLoader    = new OcrTemplateLoader(this.deviceDpi);
            var templatePath  = Path.Combine("Templates", this.ocrTemplate);
            int lineThickness = 3;

            ScrapingRectsImage = tempLoader.GetImageFromTemplate(templatePath, lineThickness);

            // ImageFileWithOcrResult ScrapingRects の準備
            if (!Items[imageIndex].ScrapingRects.Any())
            {
                Items[imageIndex].ReadScrapingRectsFromTemplate(templatePath);
            }

            // ResultRects
            var scrapingRects = Items[imageIndex].ScrapingRects;

            if (scrapingRects.Any() && scrapingRectsImage != null)
            {
                int width  = (int)(this.ImageSource.PixelWidth / this.ocrParam);
                int height = (int)(this.ImageSource.PixelHeight / this.ocrParam);
                tempLoader.CreateOcrResultImage(width, height, 97);

                foreach (var rect in scrapingRects)
                {
                    if (string.IsNullOrEmpty(rect.Value))
                    {
                        continue;
                    }

                    var rectLeft   = (int)rect.Left;
                    var rectTop    = (int)rect.Top;
                    var rectWidth  = (int)rect.Width;
                    var rectHeight = (int)rect.Height;

                    tempLoader.DrawResultRectOnOcrResultImage(rectLeft, rectTop, rectWidth, rectHeight);
                }
                this.OcrResultImage = tempLoader.GetOcrResultImage();
            }

            // BoundingRectsImage
            if (ocrEngine.OcrResults.Count > 0 && !singleScrapingRect)
            {
                int width  = ImageSource.PixelWidth;
                int height = ImageSource.PixelHeight;
                BoundingRectsImage = ocrEngine.CreatBoundingRectImage(width, height, 97);
            }

            SetButtonsEnabled();
        }
Пример #3
0
        private void RotateImage(double angle)
        {
            ClearImages();

            string          path   = Items[imageIndex].FilePath;
            TiffImageLoader loader = new TiffImageLoader();

            loader.RotateTiffImage(path, angle);

            ShowImageWithScrapingRects();
        }
Пример #4
0
        private void ShowFileInfo()
        {
            if (Items.Count == 0)
            {
                Message = msgInitial;
            }
            else
            {
                string          filePath             = Items[imageIndex].FilePath;
                TiffImageLoader loader               = new TiffImageLoader();
                string          imageSize            = loader.GetFileProperty(filePath, "大きさ");
                string          horizontalResolution = loader.GetFileProperty(filePath, "水平方向の解像度");
                string          verticalResolution   = loader.GetFileProperty(filePath, "垂直方向の解像度");
                string          fileType             = loader.GetFileProperty(filePath, "項目の種類");
                string          fileSize             = loader.GetFileProperty(filePath, "サイズ");

                Message = $"{imageIndex + 1} / { Items.Count}" + Environment.NewLine +
                          $"大きさ : {imageSize}" + Environment.NewLine +
                          $"解像度(H/V) : {horizontalResolution} × {verticalResolution}" + Environment.NewLine +
                          $"種類 : {fileType}" + Environment.NewLine +
                          $"サイズ : {fileSize }";
            }
        }