Exemple #1
0
        void Button2Click(object sender, EventArgs e)
        {
            Bitmap roibmp;
            Pix    roipix;
            Mat    src;

            buttonRight.Enabled = false;
            buttonNext.Enabled  = false;
            button2.Enabled     = false;
            OpenCvSharp.Rect roi = ramka.getRoi();
            Cursor = Cursors.WaitCursor;
            if (roi.X != -1)
            {
                src = ramka.Image[roi];
            }
            else
            {
                src = ramka.Image;
            }
            roibmp = src.ToBitmap();
            roipix = PixConverter.ToPix(roibmp);
            Pix roipix1 = roipix.Deskew();

            Bitmap newbm  = PixConverter.ToBitmap(roipix1);
            Mat    newmat = BitmapConverter.ToMat(newbm);

            ramka.Image = newmat;
            Cursor      = Cursors.Default;
            src.Dispose();
            newbm.Dispose();
            roipix.Dispose();
            buttonRight.Enabled = true;
            buttonNext.Enabled  = true;
            button2.Enabled     = true;
        }
Exemple #2
0
        void Button2Click(object sender, EventArgs e)
        {
            Bitmap roibmp;
            Pix    roipix;

            buttonRight.Enabled = false;
            buttonNext.Enabled  = false;
            button2.Enabled     = false;
            Rectangle roi = ramka.getRoi();

            Cursor = Cursors.WaitCursor;
            roibmp = ramka.Image.Clone(roi, ramka.Image.PixelFormat);
            roipix = PixConverter.ToPix(roibmp);
            roibmp.Dispose();

            Pix    roipix1 = roipix.Deskew();
            Bitmap newbm   = PixConverter.ToBitmap(roipix1);

            roipix.Dispose();
            ramka.Image         = newbm;
            Cursor              = Cursors.Default;
            buttonRight.Enabled = true;
            buttonNext.Enabled  = true;
            button2.Enabled     = true;
        }
Exemple #3
0
        /// <summary>
        /// Remove speckles using Leptonica library.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="selStr"></param>
        /// <param name="selSize"></param>
        /// <returns></returns>
        public static Bitmap RemoveSpeckles(Bitmap image, string selStr, int selSize)
        {
            //var sourcePixFilename = @"processing\w91frag.jpg";
            using (Pix pix = PixConverter.ToPix(image))
            {
                PixColormap map = pix.Colormap;
                pix.Colormap = null;  // work around NPE during despeckle

                // remove speckles
                using (Pix result = pix.Despeckle(selStr, selSize))
                {
                    if (result == null)
                    {
                        return(image);
                    }

                    return(InvertColor(PixConverter.ToBitmap(result))); // somehow, invert is needed
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Remove lines or borders using Leptonica library.
 /// </summary>
 /// <param name="image"></param>
 /// <returns></returns>
 public static Bitmap RemoveLines(Bitmap image)
 {
     using (Pix pix = PixConverter.ToPix(image))
     {
         // remove horizontal lines
         using (Pix result = pix.RemoveLines())
         {
             // rotate 90 degrees CW
             using (Pix result1 = result.Rotate90(1))
             {
                 // effectively remove vertical lines
                 using (Pix result2 = result1.RemoveLines())
                 {
                     // rotate 90 degrees CCW
                     using (Pix result3 = result2.Rotate90(-1))
                     {
                         return(PixConverter.ToBitmap(result3));
                     }
                 }
             }
         }
     }
 }