Example #1
0
        //显示图片和相关信息
        private void ShowSpliteImage(List <Rect> rects, Mat matIn)
        {
            this.listShowSplitImage.Items.Clear();
            this.imgListSplitImage.Images.Clear();


            if (this.showTypes == UserSetting.ShowTypes.PLATE)
            {
                this.imgListSplitImage.ImageSize = new System.Drawing.Size(96, 32);

                int index = 0;
                foreach (Rect rect in rects)
                {
                    Mat roi = new Mat(matIn, rects[index]);

                    if (!UserSetting.isAutoProcessPlate)
                    {
                        this.imgListSplitImage.Images.Add(roi.ToBitmap());
                        this.listShowSplitImage.Items.Add(index.ToString());
                        this.listShowSplitImage.Items[index].ImageIndex = index;  //这三条顺序还还不能换,佛了
                    }
                    else
                    {
                        this.imgListSplitImage.Images.Add(roi.ToBitmap());
                        this.listShowSplitImage.Items.Add(PlateCategorySVM.Test(roi).ToString());
                        this.listShowSplitImage.Items[index].ImageIndex = index;  //这三条顺序还还不能换,佛了
                    }

                    index++;
                }
                return;
            }

            if (this.showTypes == UserSetting.ShowTypes.CHAR)
            {
                this.imgListSplitImage.ImageSize = new System.Drawing.Size(16, 32);
                int index = 0;

                rects = CharSegement.SortLeftRects(rects);

                foreach (Rect rect in rects)
                {
                    Mat roi = new Mat(matIn, rects[index]);

                    if (!UserSetting.isAutoProcessChar)
                    {
                        this.imgListSplitImage.Images.Add(roi.ToBitmap());
                        this.listShowSplitImage.Items.Add(index.ToString());
                        this.listShowSplitImage.Items[index].ImageIndex = index;  //这三条顺序还还不能换,佛了
                    }
                    else
                    {
                        this.imgListSplitImage.Images.Add(roi.ToBitmap());
                        this.listShowSplitImage.Items.Add(CharCategorySVM.Test(roi).ToString());
                        this.listShowSplitImage.Items[index].ImageIndex = index;  //这三条顺序还还不能换,佛了
                    }

                    index++;
                }
                return;
            }

            if (this.showTypes == UserSetting.ShowTypes.All)
            {
            }
        }
Example #2
0
        //车牌识别
        public static string PlateRecognite(Mat matIn)
        {
            string plate = null;

            if (!PlateCategorySVM.IsReady)
            {
                return("车牌识别库没有准备好");
            }

            if (!CharCategorySVM.IsReady)
            {
                return("字符识别库没有准备好");
            }


            //获取车牌
            List <Mat> roiPlates = PlateLocator.PlateLocateByColor(matIn); //疑似区域
            List <Mat> matPlates = new List <Mat>();                       //车牌区域

            for (int index = 0; index < roiPlates.Count; index++)
            {
                Mat mat = roiPlates[index];
                if (PlateCategory.车牌 != PlateCategorySVM.Test(mat))
                {
                    continue;
                }
                else
                {
                    matPlates.Add(mat);
                }
            }
            //颜色不行就用sobel
            if (matPlates.Count == 0)
            {
                roiPlates.Clear();
                roiPlates = PlateLocator.PlateLocateBySobel(matIn);
                for (int index = 0; index < roiPlates.Count; index++)
                {
                    Mat mat = roiPlates[index];
                    if (PlateCategory.车牌 != PlateCategorySVM.Test(mat))
                    {
                        continue;
                    }
                    else
                    {
                        matPlates.Add(mat);
                    }
                }
            }

            if (matPlates.Count == 0)
            {
                return("无识别出车牌");
            }

            //下面根据识别出的车牌进行字符识别
            for (int index = 0; index < matPlates.Count; index++)
            {
                Mat        mat      = matPlates[index];
                List <Mat> roiChars = new List <Mat>();
                roiChars = CharSegement.SplitePlateByOriginal(mat);

                if (roiChars.Count == 0)
                {
                    return("无识别字符");
                }

                for (int i = 0; i < roiChars.Count; i++)
                {
                    plate = plate + CharCategorySVM.Test(roiChars[i]).ToString();
                }
            }

            plate = plate.Replace("_", "");
            plate = plate.Replace("非字符", "");

            return(plate);
        }
Example #3
0
        //展示最终结果
        private void ProcessAndShowResult(Mat matIn)
        {
            currentTabCount = 0;

            AddTag("原图", matIn);
            this.listShowSplitImage.Items.Clear();
            this.imgListSplitImage.Images.Clear();
            this.imgListSplitImage.ImageSize = new System.Drawing.Size(192, 64);



            List <Mat> roiPlates = PlateLocator.PlateLocateByColor(matIn); //疑似区域
            List <Mat> matPlates = new List <Mat>();                       //车牌区域

            for (int index = 0; index < roiPlates.Count; index++)
            {
                Mat mat = roiPlates[index];
                if (PlateCategory.车牌 != PlateCategorySVM.Test(mat))
                {
                    continue;
                }
                else
                {
                    matPlates.Add(mat);
                }
            }
            //颜色不行就用sobel
            if (matPlates.Count == 0)
            {
                roiPlates.Clear();
                roiPlates = PlateLocator.PlateLocateBySobel(matIn);
                for (int index = 0; index < roiPlates.Count; index++)
                {
                    Mat mat = roiPlates[index];
                    if (PlateCategory.车牌 != PlateCategorySVM.Test(mat))
                    {
                        continue;
                    }
                    else
                    {
                        matPlates.Add(mat);
                    }
                }
            }

            if (matPlates.Count == 0)
            {
                MessageBox.Show("没有识别出车牌");
                return;
            }



            //下面根据识别出的车牌进行字符识别
            for (int index = 0; index < matPlates.Count; index++)
            {
                string plate = null;
                Mat    mat   = matPlates[index];

                List <Mat> roiChars = new List <Mat>();
                roiChars = CharSegement.SplitePlateByOriginal(mat);

                if (roiChars.Count == 0)
                {
                    continue;
                }

                for (int i = 0; i < roiChars.Count; i++)
                {
                    plate = plate + CharCategorySVM.Test(roiChars[i]).ToString();
                }
                plate = plate.Replace("_", "");
                plate = plate.Replace("非字符", "");

                this.imgListSplitImage.Images.Add(mat.ToBitmap());
                this.listShowSplitImage.Items.Add(plate);
                this.listShowSplitImage.Items[index].ImageIndex = index;
            }

            //MessageBox.Show(PlateRecognition.PlateRecognite(matIn));
        }