Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Button Snap Click
- if (pictureBox3.Image != null)
- {
- Bitmap varBmp = new Bitmap(pictureBox3.Image);
- //Save First
- //varBmp.Save(Application.StartupPath + "\\ImageTest\\1.bmp", ImageFormat.Bmp);
- //Now Dispose to free the memory
- //varBmp.Dispose();
- //varBmp = null;
- varBmp.Save(Application.StartupPath + "\\ImageTest\\1.bmp", ImageFormat.Bmp);
- varBmp.Dispose();
- }
- else
- { MessageBox.Show("null exception"); }
- string folder = Application.StartupPath + "\\ImageTest";
- foreach (string fileName in Directory.GetFiles(folder, "*.bmp", SearchOption.TopDirectoryOnly))
- {
- lstimages.Add(Path.GetFullPath(fileName));
- }
- foreach (string fileName in Directory.GetFiles(folder, "*.jpg", SearchOption.TopDirectoryOnly))
- {
- lstimages.Add(Path.GetFullPath(fileName));
- }
- foreach (string fileName in Directory.GetFiles(folder, "*.png", SearchOption.TopDirectoryOnly))
- {
- lstimages.Add(Path.GetFullPath(fileName));
- }
- if (current < lstimages.Count)
- {
- for (int i = 0; i < box.Length; i++)
- {
- this.Controls.Remove(box[i]);
- }
- ProcessImage(lstimages[current]);
- current++;
- if (PlateImagesList.Count != 0)
- {
- Image<Bgr, byte> src = new Image<Bgr, byte>(PlateImagesList[0].ToBitmap());
- Bitmap grayframe;
- FindContours con = new FindContours();
- Bitmap color;
- int c = con.IdentifyContours(src.ToBitmap(), 50, false, out grayframe, out color, out listRect);
- //int z = con.count;
- pictureBox1.Image = color;
- pictureBox2.Image = grayframe;
- textBox2.Text = c.ToString();
- Image<Gray, byte> dst = new Image<Gray, byte>(grayframe);
- //dst = dst.Dilate(2);
- //dst = dst.Erode(3);
- grayframe = dst.ToBitmap();
- //pictureBox2.Image = grayframe.Clone(listRect[2], grayframe.PixelFormat);
- string zz = "";
- // lọc và sắp xếp số
- List<Bitmap> bmp = new List<Bitmap>();
- List<int> erode = new List<int>();
- List<Rectangle> up = new List<Rectangle>();
- List<Rectangle> dow = new List<Rectangle>();
- int up_y = 0, dow_y = 0;
- bool flag_up = false;
- int di = 0;
- if (listRect == null) return;
- for (int i = 0; i < listRect.Count; i++)
- {
- Bitmap ch = grayframe.Clone(listRect[i], grayframe.PixelFormat);
- int cou = 0;
- full_tesseract.Clear();
- full_tesseract.ClearAdaptiveClassifier();
- string temp = full_tesseract.Apply(ch);
- while (temp.Length > 3)
- {
- Image<Gray, byte> temp2 = new Image<Gray, byte>(ch);
- temp2 = temp2.Erode(2);
- ch = temp2.ToBitmap();
- full_tesseract.Clear();
- full_tesseract.ClearAdaptiveClassifier();
- temp = full_tesseract.Apply(ch);
- cou++;
- if (cou > 10)
- {
- listRect.RemoveAt(i);
- i--;
- di = 0;
- break;
- }
- di = cou;
- }
- }
- for (int i = 0; i < listRect.Count; i++)
- {
- for (int j = i; j < listRect.Count; j++)
- {
- if (listRect[i].Y > listRect[j].Y + 100)
- {
- flag_up = true;
- up_y = listRect[j].Y;
- dow_y = listRect[i].Y;
- break;
- }
- else if (listRect[j].Y > listRect[i].Y + 100)
- {
- flag_up = true;
- up_y = listRect[i].Y;
- dow_y = listRect[j].Y;
- break;
- }
- if (flag_up == true) break;
- }
- }
- for (int i = 0; i < listRect.Count; i++)
- {
- if (listRect[i].Y < up_y + 50 && listRect[i].Y > up_y - 50)
- {
- up.Add(listRect[i]);
- }
- else if (listRect[i].Y < dow_y + 50 && listRect[i].Y > dow_y - 50)
- {
- dow.Add(listRect[i]);
- }
- }
- if (flag_up == false) dow = listRect;
- for (int i = 0; i < up.Count; i++)
- {
- for (int j = i; j < up.Count; j++)
- {
- if (up[i].X > up[j].X)
- {
- Rectangle w = up[i];
- up[i] = up[j];
- up[j] = w;
- }
- }
- }
- for (int i = 0; i < dow.Count; i++)
- {
- for (int j = i; j < dow.Count; j++)
- {
- if (dow[i].X > dow[j].X)
- {
- Rectangle w = dow[i];
- dow[i] = dow[j];
- dow[j] = w;
- }
- }
- }
- int x = 12;
- int c_x = 0;
- for (int i = 0; i < up.Count; i++)
- {
- Bitmap ch = grayframe.Clone(up[i], grayframe.PixelFormat);
- Bitmap o = ch;
- //ch = con.Erodetion(ch);
- string temp;
- if (i < 2)
- {
- temp = Ocr(ch, false, true); // nhan dien so
- }
- else
- {
- temp = Ocr(ch, false, false);// nhan dien chu
- }
- zz += temp;
- box[i].Location = new System.Drawing.Point(x + i * 50, 350);
- box[i].Size = new Size(50, 100);
- box[i].SizeMode = PictureBoxSizeMode.StretchImage;
- box[i].Image = ch;
- this.Controls.Add(box[i]);
- c_x++;
- }
- zz += "\r\n";
- for (int i = 0; i < dow.Count; i++)
- {
- Bitmap ch = grayframe.Clone(dow[i], grayframe.PixelFormat);
- //ch = con.Erodetion(ch);
- string temp = Ocr(ch, false, true); // nhan dien so
- zz += temp;
- box[i + c_x].Location = new System.Drawing.Point(x + i * 50, 450);
- box[i + c_x].Size = new Size(50, 100);
- box[i + c_x].SizeMode = PictureBoxSizeMode.StretchImage;
- box[i + c_x].Image = ch;
- this.Controls.Add(box[i + c_x]);
- }
- grayframe.Dispose();
- color.Dispose();
- textBox1.Text = zz;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement