Exemple #1
0
        public static void DumpDetectedObjects(MyPic mPic, bool callAlmostBlack, bool debug = false, int minSize = 0)
        {
            MyPic mClone = (MyPic)mPic.getClone();

            if (callAlmostBlack)
            {
                mClone.Threshold_AlmostBlack();
            }

            ObjectDetection od = new ObjectDetection(mClone, true, true);
            int             i  = 0;

            od.DoDetection(new dOnDetectObject(delegate(ObjectPoints points, IPicAccess originalPic)
            {
                if (points.Rect.Height > 9)
                {
                    if (i == 4)
                    {
                        string s4 = points.CalcHashString();
                        System.Diagnostics.Trace.WriteLine(s4);
                    }
                    ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic).ToFile("DumpDetectedObjects_" + i++.ToString());
                }
                return(true);
            }), debug, minSize);
        }
Exemple #2
0
        public static specificResult_SmileAndMic SpecificResult_SmileAndMic(MyPic mPic, bool debug = false, int minSize = 0)
        {
            List <HashWithSize> SmileList = new List <HashWithSize>()
            {
                new HashWithSize("0000011111111000000011111111111000001111111111111100111111111111111001111111111111111111110011110011111111100111100111111111001111001111111111111111111111111111111111111111100011111100011111011111111110111111001111111011101110000000000111011111000000111110011111111111111000011111111111100", 18, 18),
                new HashWithSize("0000001111110000000001111111111000001111111111111000011111111111111001111111111111111011110001110001111111000011000011111111000111000111111110011110011111111111111111111111100000000000011111000000000000111110000000000001101110000000000111001110000000011100011111000011111000001111111111000", 18, 18),
                new HashWithSize("0000011111110000000001111111111000001111111111111000011111111111111001111111111111111111110011110011111111100011100011111111000111000111111111011111011111111111111111111111100000000000011111000000000000111111000000000001101110000000000111011110000000011110011111100111111000011111111111100", 18, 18),
                new HashWithSize("0000000111110000000000001111111111000000011111111111110000011111111111111100001111111111111111001111100111100111110111100001110001111111110000110000111111111000111100011111111110011111011111111111111111111111111100000000000000111110000000000000011011100000000000011101110000000000001110011100000000001110001111100000011111000011111111111111000000011111111110000", 20, 20),
                new HashWithSize("0000000111110000000000001111111111000000001111111111110000001111111111111100001111111111111111001111100111100011110111100001110001111011110000110000111111111000011100011111111110011110011111111111111111111111111100000000000000111110000000000000011011100000000000011101110000000000001110011100000000001110000111100000011110000001111111111110000000011111111110000", 20, 20)
            };
            List <HashWithSize> MicList = new List <HashWithSize>()
            {
                new HashWithSize("01111111111111111111111111111111111111111111111111111111111111111", 6, 14),
                new HashWithSize("0111110111111111111111111111111111111111111111111111111111111111111111111111111111110111111", 8, 14),
                new HashWithSize("01000000000000011110000000000001011000000000001101100000000000110111000000000111001111000000111000011111111111000000011111111000000000011100000000000001110000000000000111000000", 17, 12),
                new HashWithSize("111000000000000111100000000000111110000000000011011100000000001101111000000001110011110000011110000111111111110000001111111110000000000111000000000000011100000000000001110000000000000111000000", 17, 13),
                new HashWithSize("110000000000000111100000000000111110000000000011011100000000001101110000000001110011110000011110000111111111110000001111111110000000000111000000000000011100000000000001110000000000000111000000", 17, 13)
            };

            specificResult_SmileAndMic r = new specificResult_SmileAndMic();

            MyPic mClone = (MyPic)mPic.getClone();

            mClone.Threshold_AlmostBlack();
            mClone.ToFile("Smile");

            ObjectDetection od = new ObjectDetection(mClone, true, true);
            int             i  = 0;
            bool            test_DumpAllObjects = false; // mg needs to be false

            od.DoDetection(new dOnDetectObject(delegate(ObjectPoints points, IPicAccess originalPic)
            {
                #region test
                if (test_DumpAllObjects)
                {
                    if (points.Rect.Height < 100)
                    {
                        i++;
                        string path = "smile_object" + i.ToString();

                        System.IO.File.WriteAllText(path + ".txt",
                                                    points.CalcHashString() + "\r\n" + points.Rect.ToString());
                        ObjectDetection
                        .ObjectToPic_RegionOfInterest(points, originalPic)
                        .ToFile(path);
                    }
                }
                // test s
                //if (points.Rect.Height > 9)
                //{
                //    if (i == 46)
                //    {
                //        string mic = points.CalcHashString();

                //    }
                //    if (i == 47)
                //    {
                //        string smil = points.CalcHashString();

                //    }
                //    ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic).ToFile("smile_" + i++.ToString());
                //}
                // test e
                #endregion

                int start = 1;

                foreach (var smile1 in SmileList)
                {
                    if ((smile1.Size == points.Rect.Size) && (smile1.Hash == points.CalcHashString()))
                    {
                        r.SmilePos = points.Rect.Location;
                        r.SmilePos.Offset(points.Rect.Width / 2, points.Rect.Height / 2);
                    }
                }
                foreach (var mic1 in MicList)
                {
                    if ((mic1.Size == points.Rect.Size) && (mic1.Hash == points.CalcHashString()))
                    {
                        r.MicPos = points.Rect.Location;
                        r.MicPos.Offset(points.Rect.Width / 2, points.Rect.Height / 2);
                    }
                }

                //if (
                //    ((points.Rect.Size == refSmileSize1) && (refSmileHash1 == points.CalcHashString())) ||
                //    ((points.Rect.Size == refSmileSize2) && (refSmileHash2 == points.CalcHashString())) ||
                //    ((points.Rect.Size == refSmileSize3) && (refSmileHash3 == points.CalcHashString())) ||
                //    ((points.Rect.Size == refSmileSize4) && (refSmileHash4 == points.CalcHashString()))
                //    )
                //{
                //    r.SmilePos = points.Rect.Location;
                //    r.SmilePos.Offset(points.Rect.Width / 2, points.Rect.Height / 2);
                //}
                //if (
                //    ((points.Rect.Size == refMicSize1) && (points.CalcHashString() == refMicHash1)) ||
                //    ((points.Rect.Size == refMicSize2) && (points.CalcHashString() == refMicHash2)) ||
                //    ((points.Rect.Size == refMicSize3) && (points.CalcHashString() == refMicHash3))
                //    )
                //{
                //    r.MicPos = points.Rect.Location;
                //    r.MicPos.Offset(points.Rect.Width / 2, points.Rect.Height / 2);
                //}

                if ((r.MicPos.IsEmpty) || (r.SmilePos.IsEmpty))
                {
                    return(true);
                }
                return(false);
            }), debug, minSize);
            return(r);
        }
Exemple #3
0
        public static SpecificResult_Text DetectText(MyPic mPic, bool debug = false, int minSize = 0)
        {
            SpecificResult_Text r  = new SpecificResult_Text();
            StringBuilder       sb = new StringBuilder();

            try
            {
                DebLog(debug, "New");
                MyPic mClone = (MyPic)mPic.getClone();
                mClone.Threshold_AlmostBlack();
                bool first = true;
                mClone.ToFileIfConfigured("TextRecognitionLibrary.DetectText.SaveInput");

                ObjectDetection od = new ObjectDetection(mClone, true, true);
                int             id = 0;
                od.DoDetection(new dOnDetectObject(delegate(ObjectPoints points, IPicAccess originalPic)
                {
                    id++;
                    string cnfDumpAll = ConfigurationManager.AppSettings["TextRecognitionLibrary.DetectText.DumpAll"];
                    if ((cnfDumpAll != null) && (Boolean.Parse(cnfDumpAll)))
                    {
                        MyPic picDumpAll = (MyPic)ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic);
                        picDumpAll.ToFile(id.ToString());
                    }

                    DebLog(debug, $"id{id} {points.Rect.Height}x{points.Rect.Width} soFar{sb}");

                    if (points.Rect.Height == 10)
                    {
                        MyPic pic10 = (MyPic)ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic);
                        char c      = TextCourierNew10.RecogniseChar(pic10);
                        sb.Append(c);
                        if (first)
                        {
                            first     = false;
                            r.TextPos = points.Points[0];
                        }
                    }
                    else if (points.Rect.Height == 11)
                    {
                        MyPic pic11 = (MyPic)ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic);
                        char c      = TextCourierNew11.RecogniseChar(pic11);
                        sb.Append(c);
                        if (first)
                        {
                            first     = false;
                            r.TextPos = points.Points[0];
                        }
                    }
                    else if (points.Rect.Height == 12)
                    {
                        ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic).ToFile("a12");
                        if ((points.Rect.Width == 4) || (points.Rect.Width == 5) || (points.Rect.Width == 7))
                        {
                            IPicAccess pchar = ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic);
                            IPicAccess pbu   = pchar.getClone();
                            char c           = TextRecognition.RecogniseChar(pchar);
                            sb.Append(c);
                            if (first)
                            {
                                first     = false;
                                r.TextPos = points.Points[0];
                            }
                        }
                        else if (points.Rect.Width == 8)
                        {
                            IPicAccess pchar =
                                ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic)
                                .getSubPic(1, 0, 7, 12);
                            IPicAccess pbu = pchar.getClone();
                            char c         = TextRecognition.RecogniseChar(pchar);
                            sb.Append(c);
                            if (first)
                            {
                                first     = false;
                                r.TextPos = points.Points[0];
                            }
                        }
                        else
                        {
                            // could this be 2 or more chars together?
                            ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic).ToFile("subAll");
                            int x = 0;
                            while (x < points.Rect.Width)
                            {
                                IPicAccess sub = mPic.getSubPic(points.Rect.X + x, points.Rect.Y, 7, 12);
                                sub.ToFile("subtogether");
                                char c = TextRecognition.RecogniseChar(sub.getClone());
                                if (c == '?')
                                {
                                    // not recognised
                                    x = points.Rect.Width;
                                }
                                else
                                {
                                    x += 9;
                                    sb.Append(c);
                                    if (first)
                                    {
                                        first     = false;
                                        r.TextPos = points.Points[0];
                                    }
                                }
                            }
                        }
                    }
                    return(true);
                }), debug, minSize);
                r.Text = sb.ToString();
                return(r);
            }
            catch (Exception ex)
            {
                DebLog(debug, "Exception");
                DebLog(debug, ex.Message);
                if (sb.ToString().Length > 0)
                {
                    r.Text = sb.ToString();
                    return(r);
                }
                var err = new SpecificResult_Text();
                err.Text    = "Exception: " + ex.Message;
                err.TextPos = new Point(0, 0);
                return(err);
            }
        }