예제 #1
0
        //自动样品分割
        public static List <CharInfo> SplitePlateForAutoSample(Mat plateMat)
        {
            List <CharInfo> result = new List <CharInfo>();
            List <CharInfo> charInfos_Original_Blue       = SplitePlateByOriginal(plateMat, plateMat, PlateColor.蓝牌);
            List <CharInfo> charInfos_IndexTransform_Blue = SplitePlateByIndexTransform(plateMat,
                                                                                        PlateColor.蓝牌);
            List <CharInfo> charInfos_GammaTransform_Blue = SplitePlateByGammaTransform(plateMat,
                                                                                        PlateColor.蓝牌);
            List <CharInfo> charInfos_LogTransform_Blue = SplitePlateByLogTransform(plateMat, PlateColor.蓝牌);
            List <CharInfo> charInfos_Blue = new List <CharInfo>();

            charInfos_Blue.AddRange(charInfos_Original_Blue.ToArray());
            charInfos_Blue.AddRange(charInfos_IndexTransform_Blue.ToArray());
            charInfos_Blue.AddRange(charInfos_GammaTransform_Blue.ToArray());
            charInfos_Blue.AddRange(charInfos_LogTransform_Blue.ToArray());
            int isCharCount = 0;

            for (int index = 0; index < charInfos_Blue.Count; index++)
            {
                CharInfo charInfo = charInfos_Blue[index];
                charInfo.PlateChar = PlateChar_SVM.Test(charInfo.OriginalMat);
                if (charInfo.PlateChar != PlateChar.非字符)
                {
                    isCharCount++;
                }
            }
            if (isCharCount >= 15)
            {
                return(charInfos_Blue);
            }
            //如果用蓝色切分字符,少于15个,就再用黄色尝试切分
            List <CharInfo> charInfos_Original_Yellow       = SplitePlateByOriginal(plateMat, plateMat, PlateColor.黄牌);
            List <CharInfo> charInfos_IndexTransform_Yellow = SplitePlateByIndexTransform(plateMat,
                                                                                          PlateColor.黄牌);
            List <CharInfo> charInfos_GammaTransform_Yellow = SplitePlateByGammaTransform(plateMat,
                                                                                          PlateColor.黄牌);
            List <CharInfo> charInfos_LogTransform_Yellow = SplitePlateByLogTransform(plateMat,
                                                                                      PlateColor.黄牌);
            List <CharInfo> charInfos_Yellow = new List <CharInfo>();

            charInfos_Yellow.AddRange(charInfos_Original_Yellow.ToArray());
            charInfos_Yellow.AddRange(charInfos_IndexTransform_Yellow.ToArray());
            charInfos_Yellow.AddRange(charInfos_GammaTransform_Yellow.ToArray());
            charInfos_Yellow.AddRange(charInfos_LogTransform_Yellow.ToArray());
            isCharCount = 0;
            for (int index = 0; index < charInfos_Yellow.Count; index++)
            {
                CharInfo charInfo = charInfos_Yellow[index];
                charInfo.PlateChar = PlateChar_SVM.Test(charInfo.OriginalMat);
                if (charInfo.PlateChar != PlateChar.非字符)
                {
                    isCharCount++;
                }
            }
            if (isCharCount >= 15)
            {
                return(charInfos_Yellow);
            }
            return(new List <CharInfo>()); //返回?长度为零的集合
        }
예제 #2
0
        //
        public static PlateInfo GetPlateInfo(PlateInfo plateInfo, PlateColor plateColor, CharSplitMethod
                                             splitMethod)
        {
            PlateInfo result = new PlateInfo();

            result.PlateCategory     = plateInfo.PlateCategory;
            result.OriginalMat       = plateInfo.OriginalMat;
            result.OriginalRect      = plateInfo.OriginalRect;
            result.PlateLocateMethod = plateInfo.PlateLocateMethod;
            result.PlateColor        = plateColor;
            List <CharInfo> charInfos = new List <CharInfo>();

            switch (splitMethod)
            {
            case CharSplitMethod.伽马:
                charInfos = CharSegment_V3.SplitePlateByGammaTransform(plateInfo.OriginalMat,
                                                                       plateColor);
                break;

            case CharSplitMethod.指数:
                charInfos = CharSegment_V3.SplitePlateByIndexTransform(plateInfo.OriginalMat, plateColor);
                break;

            case CharSplitMethod.对数:
                charInfos = CharSegment_V3.SplitePlateByLogTransform(plateInfo.OriginalMat, plateColor);
                break;

            case CharSplitMethod.原图:
            default:
                charInfos = CharSegment_V3.SplitePlateByOriginal(plateInfo.OriginalMat,
                                                                 plateInfo.OriginalMat, plateColor);
                break;
            }
            //启动SVM识别字符并将其中的非字符去除
            for (int index = charInfos.Count - 1; index >= 0; index--)
            {
                CharInfo  charInfo  = charInfos[index];
                PlateChar plateChar = PlateChar_SVM.Test(charInfo.OriginalMat);
                if (plateChar == PlateChar.非字符)
                {
                    charInfos.RemoveAt(index);
                }
                charInfo.PlateChar = plateChar;
            }
            result.CharInfos = charInfos;
            //检测
            CheckLeftAndRightToRemove(result);
            CheckPlateColor(result);
            return(result);
        }
예제 #3
0
        //对分割好的字符进行识别,并得到字符数组
        public static List <CharInfo> SpliteCharsInPlateMat(Mat plateMat, List <Rect> rects)
        {
            if (PlateChar_SVM.IsReady == false)
            {
                throw new Exception("字符识别库没有准备好");
            }
            List <CharInfo> result = new List <CharInfo>();

            for (int index = 0; index < rects.Count; index++)
            {
                Rect rect = rects[index];
                rect = Utilities.GetSafeRect(rect, plateMat);
                CharInfo charInfo    = new CharInfo();
                Mat      originalMat = plateMat.SubMat(rect);
                charInfo.OriginalMat  = originalMat;
                charInfo.OriginalRect = rect;

                charInfo.PlateChar = PlateChar_SVM.Test(originalMat);
                result.Add(charInfo);
            }
            result.Sort(new CharInfoLeftComparer());
            return(result);
        }