コード例 #1
0
ファイル: TwainScanForm.cs プロジェクト: rajbindu/misc
        private void twainDevice_Scanned(object sender, ScannedEventArgs e)
        {
            IntPtr hdib = e.ScannedImage.ToHdib();

            //must set last parameter to true so Hdib will be cleaned up
            using (ImageX scannedImage = ImageX.FromHdib(imagXpress1, hdib, true))
            {
                imagesScanned.Add(scannedImage.Copy());
            }

            imagesScannedCount = imagesScanned.Count;
            imagesScannedIndex++;

            UpdatePageUI();
        }
コード例 #2
0
        private Boolean LoadImage(String ImageName)
        {
            if (!File.Exists(ImageName))
            {
                MessageBox.Show("Image Doesn't exist : " + ImageName);
                return(false);
            }

            //Zonal 2
            try
            {
                currentLayer.Elements.Clear();

                InputImg.Image = ImageX.FromFile(imagXpress1, ImageName);
                Processor prc = new PegasusImaging.WinForms.ImagXpress9.Processor(imagXpress1, InputImg.Image);
                if (InputImg.Image.ImageXData.BitsPerPixel != 1)
                {
                    prc.ColorDepth(1, PaletteType.Optimized, DitherType.NoDither);
                    //InputImg.Image = prc.Image;
                }

                //    prc.Rotate(270);
                prc.DocumentDeskew(0, 10, Color.White, true, 99);
                prc.DocumentDespeckle(10, 10);
                InputImg.Image = prc.Image.Copy();

                //InputImg.Image = this.PreprocessImage(this.InputImg.Image);

                frmFilledImage = FormImage.FromHdib(InputImg.Image.ToHdib(false), true, formFix1);

                OutputImg.Image = ImageX.FromHdib(imagXpress1, frmFilledImage.ToHdib(false), true);   //InputImg.Image.Copy();

                OnPictureChanged(ICRType.Image);
                //MessageBox.Show("Load Image");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }
コード例 #3
0
        private bool RegisterImage()
        {
            //Zonal 2
            try
            {
                regProcessor = new RegistrationProcessor(formFix1);

                regResult = regProcessor.RegisterToImage(frmFilledImage, frmTemplateImage);

                if (regResult.State == RegistrationState.Failure)
                {
                    MessageBox.Show(regResult.State.ToString());
                }

                frmAlignedImage = regResult.AlignImage(frmFilledImage);

                /*
                 * ImageX FieldImage = new ImageX(imagXpress1);
                 * DropOutProcessor oDrop = new DropOutProcessor(formFix1);
                 * oDrop.DropOutMethod = DropOutMethod.DropOut;
                 * //oDrop.Area = new Rectangle(0, 0, Field.Width, Field.Height);
                 * DropOutResult oDropOutResult = oDrop.CreateImageOfField(frmFilledImage, regResult);
                 */

                //InputImg.Image = ImageX.FromHdib(imagXpress1, oDropOutResult.Image.ToHdib(true), true); //ImageX.FromHdib(imagXpress1, frmAlignedImage.ToHdib(false), true);
                InputImg.Image = ImageX.FromHdib(imagXpress1, frmAlignedImage.ToHdib(false), true);
                // oDrop.Dispose();

                OutputImg.Image = InputImg.Image.Copy();
                OnPictureChanged(ICRType.ImageMatched);

                //  MessageBox.Show("Aligned Image");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(true);
        }
コード例 #4
0
        private Boolean LoadTemplate(String TemplateImageName)
        {
            String TemplateName = TemplateImageName.Substring(TemplateImageName.LastIndexOf("\\") + 1).ToUpper().Replace(".TIF", "");

            if (!File.Exists(TemplateImageName))
            {
                MessageBox.Show("This Template Doecn't Exist!! : " + TemplateImageName);
            }

            // Zonal
            try
            {
                InputImg.Image = ImageX.FromFile(imagXpress1, this.TemplateFile);

                /*
                 * Processor prc = new PegasusImaging.WinForms.ImagXpress9.Processor(imagXpress1, InputImg.Image);
                 * prc.Rotate(270);
                 * InputImg.Image = prc.Image.Copy();
                 */

                InputImg.Image = PreprocessImage(InputImg.Image);


                frmTemplateImage = FormImage.FromHdib(InputImg.Image.ToHdib(false), true, formFix1);

                OutputImg.Image = ImageX.FromHdib(imagXpress1, frmTemplateImage.ToHdib(false), true);   //InputImg.Image.Copy();
                OnPictureChanged(ICRType.Template);

                // MessageBox.Show("Load Template");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                IsTemplateLoaded = false;
                return(false);
            }

            IsTemplateLoaded = true;
            return(true);
        }
コード例 #5
0
        public void ProcessFields()
        {
            foreach (ICRField Field in this.Fields)
            {
                ImageX           FieldImage = new ImageX(imagXpress1);
                DropOutProcessor oDrop      = new DropOutProcessor(formFix1);
                oDrop.DropOutMethod         = DropOutMethod.DropOut;
                oDrop.PerformReconstruction = false;
                oDrop.Area = new Rectangle(Field.Left, Field.Top, Field.Width, Field.Height);
                DropOutResult oDropOutResult = oDrop.CreateImageOfField(frmFilledImage, regResult);

                FieldImage = ImageX.FromHdib(imagXpress1, oDropOutResult.Image.ToHdib(true), true);
                oDrop.Dispose();


                OutputFieldImg.Image = FieldImage.Copy();
                OnPictureChanged(ICRType.Field);
                // MessageBox.Show("Field Loaded");
                Application.DoEvents();

                // Set area and analyze field DIB
                SmartZone2.Reader.CharacterSet = Field.CharSet;
                SmartZone2.Reader.Segmentation.SplitMergedChars      = true;
                SmartZone2.Reader.Segmentation.SplitOverlappingChars = true;

                FieldImage = this.PreprocessField(FieldImage);

                OutputFieldImg.Image = FieldImage.Copy();
                OnPictureChanged(ICRType.FieldProcessed);
                //MessageBox.Show("Field Processed");
                Application.DoEvents();

                Rectangle currentArea = new Rectangle(0, 0, Field.Width, Field.Height);
                SmartZone2.Reader.Area = currentArea;
                myTextBlockRes         = SmartZone2.Reader.AnalyzeField(FieldImage.ToHdib(true));


                if (myTextBlockRes.NumberTextLines > 0)
                {
                    //  MessageBox.Show(myTextBlockRes.TextLine(0).Text);

                    Chars.Clear();
                    for (int i = 1; myTextBlockRes.NumberTextLines + 1 != i; i++)
                    {
                        LineResult = myTextBlockRes.TextLine(0);

                        String charResult   = "";
                        int    ControlIndex = 1;
                        for (int charIndex = 0; LineResult.NumberCharacters != charIndex; charIndex++)
                        {
                            CharacterResult characterResult = LineResult.Character(charIndex);
                            ICRChar         oChar           = new ICRChar(characterResult.Text, characterResult.Confidence);
                            for (int x = 0; x < characterResult.NumberResults; x++)
                            {
                                oChar.Results.Add(new ICRAlternateChar(characterResult.AlternateText(x), characterResult.AlternateConfidence(x)));
                            }

                            oChar.Area          = characterResult.Area;
                            oChar.NumberResults = characterResult.NumberResults;
                            Chars.Add(oChar);

                            charResult = charResult + characterResult.Text;
                            ControlIndex++;
                        }
                        Field.Result = charResult;
                        //MessageBox.Show(Field.Result);
                        Console.Out.WriteLine(Field.Result);
                    }
                }
                else
                {
                    Field.Result = "";
                }
            }
        }
コード例 #6
0
        private ImageX PreprocessField(ImageX Image)
        {
            scanFix1.FromHdib(Image.ToHdib(false));

            //Remove Lines

            /*          LineRemovalOptions LineOpts = new LineRemovalOptions();
             *        LineOpts.MinimumLength = 10;
             *        scanFix1.RemoveLines(LineOpts);
             */
            //Despeckle

            DespeckleOptions DespeckOpts = new DespeckleOptions();

            DespeckOpts.SpeckWidth  = 10;
            DespeckOpts.SpeckHeight = 10;
            scanFix1.Despeckle(DespeckOpts);

            //Deskew
            //scanFix1.Deskew();

            //Dilate



            //Comb options

            /*
             * comb = new PegasusImaging.WinForms.ScanFix5.CombRemovalOptions();
             *
             * comb.Area = new System.Drawing.Rectangle(AreaXBar.Value, AreaYBar.Value, AreaWBar.Value, AreaHBar.Value);
             * comb.CombHeight = CombHBar.Value;
             * comb.CombSpacing = SpaceBar.Value;
             * comb.HorizontalLineThickness = HBar.Value;
             * comb.VerticalLineThickness = VBar.Value;
             * comb.MinimumCombLength = LengthBar.Value;
             * comb.MinimumConfidence = ConfidenceBar.Value;
             *
             * scanFix1.RemoveCombs(comb);
             */

            //Smooth Options
            scanFix1.SmoothObjects(10);


            DilateOptions dilate = new DilateOptions();

            dilate.Amount    = 1;
            dilate.Direction = EnhancementDirections.All;

            scanFix1.Dilate(dilate);

            //Blob Options

            /*
             * blob = new PegasusImaging.WinForms.ScanFix5.BlobRemovalOptions();
             *
             * blob.Area = new System.Drawing.Rectangle(BlobAreaXBar.Value, BlobAreaYBar.Value, AreaWidthBar.Value, AreaHeightBar.Value);
             * blob.MaximumPixelCount = MaxCountBar.Value;
             * blob.MinimumPixelCount = MinCountBar.Value;
             * blob.MinimumDensity = DensityBar.Value;
             *
             * scanFix1.RemoveBlobs(blob);
             */

            //Remove Dot Shading

            /*
             * dot = new PegasusImaging.WinForms.ScanFix5.DotShadingRemovalOptions();
             *
             * dot.DensityAdjustment = DotDensityBar.Value;
             * dot.MaximumDotSize = DotSizeBar.Value;
             * dot.HorizontalSizeAdjustment = HAdjBar.Value;
             * dot.VerticalSizeAdjustment = VAdjBar.Value;
             * dot.MinimumAreaHeight = DotHBar.Value;
             * dot.MinimumAreaWidth = DotWBar.Value;
             *
             * scanFix1.RemoveDotShading(dot);
             */


            //Remove Border Options

            /*
             * border = new PegasusImaging.WinForms.ScanFix5.BorderRemovalOptions();
             *
             * border.BorderSpeckSize = BSpeckBar.Value;
             * border.CropBorder = chkcrop.Checked;
             * border.DeskewBorder = chkdeskew.Checked;
             * border.MaximumPageHeight = MaxHeightBar.Value;
             * border.MaximumPageWidth = MaxWidthBar.Value;
             * border.MinimumConfidence = MinConBar.Value;
             * border.MinimumPageHeight = MinHeightBar.Value;
             * border.MinimumPageWidth = SpeckWidthBar.Value;
             * border.PageSpeckSize = PSpeckBar.Value;
             * border.Quality = SpeckQualityBar.Value;
             * border.ReplaceBorder = chkreplace.Checked;
             *
             * if (true)
             * {
             *  border.PadColor = System.Drawing.Color.FromArgb(0, 0, 0);
             * }
             * else
             * {
             *  border.PadColor = System.Drawing.Color.FromArgb(255, 255, 255);
             * }
             * scanFix1.RemoveBorder(border);
             */

            Image = ImageX.FromHdib(imagXpress1, scanFix1.ToHdib(false));



            return(Image);
        }
コード例 #7
0
        public void Test()
        {
            #region Load Template
            try
            {
                InputImg.Image   = ImageX.FromFile(imagXpress1, @"I:\Templates\ICRTemplate.tif");
                frmTemplateImage = FormImage.FromHdib(InputImg.Image.ToHdib(false), true, formFix1);

                InputImg.Image  = ImageX.FromHdib(imagXpress1, (System.IntPtr) 0, true);
                OutputImg.Image = ImageX.FromHdib(imagXpress1, (System.IntPtr) 0, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endregion

            #region Load Image
            String ImageName = @"I:\Images\Order-0000000153.TIFF";
            try
            {
                InputImg.Image = ImageX.FromFile(imagXpress1, ImageName);
                frmFilledImage = FormImage.FromHdib(InputImg.Image.ToHdib(false), true, formFix1);

                OutputImg.Image = ImageX.FromHdib(imagXpress1, (System.IntPtr) 0, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            //it's all looking good, so we load our image into an ImageX object
            //imageXView1.Image = ImageX.FromFile(imagXpress1, strFileName);
            Processor prc = new Processor(imagXpress1, InputImg.Image);

            if (InputImg.Image.ImageXData.BitsPerPixel != 1)
            {
                prc.ColorDepth(1, PaletteType.Optimized, DitherType.NoDither);
                InputImg.Image = prc.Image;
            }



            #endregion

            #region Register Image
            try
            {
                regProcessor = new RegistrationProcessor(formFix1);

                regResult = regProcessor.RegisterToImage(frmFilledImage, frmTemplateImage);

                frmAlignedImage = regResult.AlignImage(frmFilledImage);

                InputImg.Image = ImageX.FromHdib(imagXpress1, frmAlignedImage.ToHdib(false), true);


                OutputImg.Image = InputImg.Image.Copy();
                OnPictureChanged(ICRType.ImageMatched);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:  " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endregion

            #region Preprocessing Image
            Processor proc = new Processor(imagXpress1, InputImg.Image);

            if (InputImg.Image.ImageXData.BitsPerPixel != 0)
            {
                proc.ColorDepth(1, 0, 0);
            }

            scanFix1.FromHdib(InputImg.Image.ToHdib(false));


            //Remove Lines
            LineRemovalOptions LineOpts = new LineRemovalOptions();
            LineOpts.MinimumLength = 20;
            scanFix1.RemoveLines(LineOpts);

            //Despeckle
            DespeckleOptions DespeckOpts = new DespeckleOptions();
            DespeckOpts.SpeckWidth  = 10;
            DespeckOpts.SpeckHeight = 14;
            scanFix1.Despeckle(DespeckOpts);

            //Deskew
            scanFix1.Deskew();

            //Comb options

            /*
             * comb = new PegasusImaging.WinForms.ScanFix5.CombRemovalOptions();
             *
             * comb.Area = new System.Drawing.Rectangle(AreaXBar.Value, AreaYBar.Value, AreaWBar.Value, AreaHBar.Value);
             * comb.CombHeight = CombHBar.Value;
             * comb.CombSpacing = SpaceBar.Value;
             * comb.HorizontalLineThickness = HBar.Value;
             * comb.VerticalLineThickness = VBar.Value;
             * comb.MinimumCombLength = LengthBar.Value;
             * comb.MinimumConfidence = ConfidenceBar.Value;
             *
             * scanFix1.RemoveCombs(comb);
             */

            //Smooth Options
            //scanFix1.SmoothObjects(SmoothBar.Value);


            //Blob Options

            /*
             * blob = new PegasusImaging.WinForms.ScanFix5.BlobRemovalOptions();
             *
             * blob.Area = new System.Drawing.Rectangle(BlobAreaXBar.Value, BlobAreaYBar.Value, AreaWidthBar.Value, AreaHeightBar.Value);
             * blob.MaximumPixelCount = MaxCountBar.Value;
             * blob.MinimumPixelCount = MinCountBar.Value;
             * blob.MinimumDensity = DensityBar.Value;
             *
             * scanFix1.RemoveBlobs(blob);
             */

            //Remove Dot Shading

            /*
             * dot = new PegasusImaging.WinForms.ScanFix5.DotShadingRemovalOptions();
             *
             * dot.DensityAdjustment = DotDensityBar.Value;
             * dot.MaximumDotSize = DotSizeBar.Value;
             * dot.HorizontalSizeAdjustment = HAdjBar.Value;
             * dot.VerticalSizeAdjustment = VAdjBar.Value;
             * dot.MinimumAreaHeight = DotHBar.Value;
             * dot.MinimumAreaWidth = DotWBar.Value;
             *
             * scanFix1.RemoveDotShading(dot);
             */


            //Remove Border Options

            /*
             * border = new PegasusImaging.WinForms.ScanFix5.BorderRemovalOptions();
             *
             * border.BorderSpeckSize = BSpeckBar.Value;
             * border.CropBorder = chkcrop.Checked;
             * border.DeskewBorder = chkdeskew.Checked;
             * border.MaximumPageHeight = MaxHeightBar.Value;
             * border.MaximumPageWidth = MaxWidthBar.Value;
             * border.MinimumConfidence = MinConBar.Value;
             * border.MinimumPageHeight = MinHeightBar.Value;
             * border.MinimumPageWidth = SpeckWidthBar.Value;
             * border.PageSpeckSize = PSpeckBar.Value;
             * border.Quality = SpeckQualityBar.Value;
             * border.ReplaceBorder = chkreplace.Checked;
             *
             * if (true)
             * {
             *  border.PadColor = System.Drawing.Color.FromArgb(0, 0, 0);
             * }
             * else
             * {
             *  border.PadColor = System.Drawing.Color.FromArgb(255, 255, 255);
             * }
             * scanFix1.RemoveBorder(border);
             */
            #endregion

            #region Read Fields

            InputImg.Image = ImageX.FromHdib(imagXpress1, scanFix1.ToHdib(false));


            // Set area and analyze field DIB
            SmartZone2.Reader.CharacterSet = CharacterSet.AllAlphas;
            Rectangle currentArea = new Rectangle(85, 170, 603, 79);
            SmartZone2.Reader.Area = currentArea;
            myTextBlockRes         = SmartZone2.Reader.AnalyzeField(InputImg.Image.ToHdib(false));


            if (myTextBlockRes.NumberTextLines > 0)
            {
                Boolean hasResult = true;

                LineResult = myTextBlockRes.TextLine(0);

                //   showBlockResult();
                //   showLineResult(0);
                //   showCharacterResult(0);
            }
            else
            {
                Boolean hasResult = false;
            }

            MessageBox.Show(myTextBlockRes.TextLine(0).Text);
            #endregion

            return;
        }