Beispiel #1
0
        private void process()
        {
            bmpWork = new Grayscale(0.2125, 0.7154, 0.0721).Apply(exteactTicketNoImg);
            bmpWork = bmpWork.Clone(new Rectangle(0, 0, exteactTicketNoImg.Width, exteactTicketNoImg.Height), PixelFormat.Format24bppRgb);
            pictureBox_work.Image = bmpWork;


            ImageProcess.FilterBackground(bmpWork);
            pictureBox_work.Image = bmpWork;


            ImageProcess.FilterDisturb(bmpWork);
            pictureBox_work.Image = bmpWork;

            ImageProcess.Binarizate(bmpWork);
            bmpWork = ImageProcess.CutBlankEdge(bmpWork);
            pictureBox_work.Image = bmpWork;

            splitBmpList = ImageProcess.Split(bmpWork, 7);
            PictureBox[] pxs = { pictureBox_slpit1, pictureBox_slpit2, pictureBox_slpit3, pictureBox_slpit4, pictureBox_slpit5, pictureBox_slpit6, pictureBox_slpit7 };
            for (int i = 0; i < splitBmpList.Count; i++)
            {
                pxs[i].Image = splitBmpList[i];
            }

            if (splitBmpList == null)
            {
                label_result.Text = "";
                return;
            }
            label_result.Text = OCRTicketNo(splitBmpList);
        }
Beispiel #2
0
 private void button4_Click(object sender, EventArgs e)
 {
     splitBmpList = ImageProcess.SplitTicketNoByDefinedWidth(bmpWork, bmpTicket.Width, bmpTicket.Height);
     PictureBox[] pxs = { pictureBox_slpit1, pictureBox_slpit2, pictureBox_slpit3, pictureBox_slpit4, pictureBox_slpit5, pictureBox_slpit6, pictureBox_slpit7 };
     for (int i = 0; i < splitBmpList.Count; i++)
     {
         pxs[i].Image = splitBmpList[i];
     }
 }
Beispiel #3
0
 private void button11_Click(object sender, EventArgs e)
 {
     if (exteactTicketCodeImg != null)
     {
         Bitmap b = ImageProcess.FilterBalckBlob(exteactTicketCodeImg);
         if (pictureBox_code.Image != null)
         {
             pictureBox_code.Image.Dispose();
             pictureBox_code.Image = null;
             pictureBox_code.Image = b;
         }
         else
         {
             pictureBox_code.Image = b;
         }
     }
 }
Beispiel #4
0
 private void button3_Click(object sender, EventArgs e)
 {
     ImageProcess.Binarizate(bmpWork);
     bmpWork = ImageProcess.CutBlankEdge(bmpWork);
     pictureBox_work.Image = bmpWork;
 }
        /// <summary>
        /// 提取21位码图像
        /// </summary>
        /// <param name="source"></param>
        /// <param name="ticketType"></param>
        /// <returns></returns>
        public Bitmap GetTicketCodeImgs(Bitmap source, int ticketType)
        {
            Bitmap tempBin = source.Clone() as Bitmap; //Clone image to keep original image

            int minHeight, maxHeight, charWidth, charHeight, charOffset;

            if (Config.BLUE_TICKET == ticketType)
            {
                minHeight  = Convert.ToInt16(Config.BLUE_CODE_CHAR_HEIGHT_RATIO * 0.7 * Config.BLUE_TICKET_HEIGHT);
                maxHeight  = Convert.ToInt16(Config.BLUE_CODE_CHAR_HEIGHT_RATIO * 1.1 * Config.BLUE_TICKET_HEIGHT);
                charHeight = Convert.ToInt16(Config.BLUE_CODE_CHAR_HEIGHT_RATIO * Config.BLUE_TICKET_HEIGHT);
                charWidth  = Convert.ToInt16(Config.BLUE_CODE_CHAR_WIDTH_RATIO * Config.BLUE_TICKET_WIDTH);
                charOffset = Convert.ToInt16(Config.BLUE_CODE_CHAR_OFFSET_RATIO * Config.RED_TICKET_WIDTH);
            }
            else
            {
                minHeight  = Convert.ToInt16(Config.RED_CODE_CHAR_HEIGHT_RATIO * 0.7 * Config.RED_TICKET_HEIGHT);
                maxHeight  = Convert.ToInt16(Config.RED_CODE_CHAR_HEIGHT_RATIO * 1.1 * Config.RED_TICKET_HEIGHT);
                charHeight = Convert.ToInt16(Config.RED_CODE_CHAR_HEIGHT_RATIO * Config.RED_TICKET_HEIGHT);
                charWidth  = Convert.ToInt16(Config.RED_CODE_CHAR_WIDTH_RATIO * Config.RED_TICKET_WIDTH);
                charOffset = Convert.ToInt16(Config.RED_CODE_CHAR_OFFSET_RATIO * Config.RED_TICKET_WIDTH);
            }
            tempBin = commonSeq.Apply(source); // Apply filters on source image
            Bitmap temp = tempBin.Clone() as Bitmap;

            temp = extractCodeSeq.Apply(temp);
            temp = ImageProcess.CutBlankEdge(temp);

            Bitmap bmp = new Bitmap(charWidth * 21, charHeight + 4);

            BlobCounter blobCounter = new BlobCounter(temp); //把图片上的联通物体都分离开来

            Blob[]         blobs    = blobCounter.GetObjects(temp, false);
            IList <Bitmap> codeImgs = new List <Bitmap>();

            var blobFilters = from o in blobs where o.Image.Height >= minHeight orderby o.Rectangle.Y descending select o;

            if (blobFilters.Count <Blob>() < 1)
            {
                return(bmp);
            }
            //var rectYList = from o in codeImgDic.Values orderby o.Rectangle.Y select o;
            int maxY = blobFilters.First <Blob>().Rectangle.Y;

            Graphics g = Graphics.FromImage(bmp);

            g.FillRectangle(new SolidBrush(Color.Black), 0, 0, charWidth * 21, charHeight + 4);
            int offset = 0;

            var imgList = from img in blobFilters where Math.Abs(img.Rectangle.Y - maxY) <= charHeight orderby img.Rectangle.X select img;
            var list    = imgList.ToList <Blob>();

            for (int i = 0; i < list.Count; i++)
            {
                Blob blob = list[i];

                if (i > 0)
                {
                    Blob preBlob = list[i - 1];
                    if (Math.Abs(blob.Rectangle.X - preBlob.Rectangle.X - preBlob.Rectangle.Width) <= charWidth)
                    {
                        Crop   c = new Crop(blob.Rectangle);
                        Bitmap b = c.Apply(tempBin);
                        PointF p = new PointF(offset, 2);
                        g.DrawImage(b, p);
                        offset += blob.Rectangle.Width + 1;
                    }
                    else
                    {
                        Bitmap b  = blob.Image.ToManagedImage();
                        Bitmap pb = preBlob.Image.ToManagedImage();

                        Console.WriteLine(Math.Abs(blob.Rectangle.X - preBlob.Rectangle.X - preBlob.Rectangle.Width));
                    }
                }
                else
                {
                    Crop   c = new Crop(blob.Rectangle);
                    Bitmap b = c.Apply(tempBin);
                    PointF p = new PointF(offset, 2);
                    g.DrawImage(b, p);
                    offset += blob.Rectangle.Width + 1;
                }
            }
            g.Dispose();
            return(commonSeq.Apply(bmp));
            //return bmp;
        }