private void onDebug(bool debug, int minSize, ObjectPoints points) { if (debug) { if ((points.Rect.Height >= minSize) && (points.Rect.Width >= minSize)) { MyPic debPic = new MyPic(points); int area = points.Rect.Width * points.Rect.Height; string hash = points.CalcHashString(); string fileName = String.Format("debPic_{0}_{1}_{2}_w{3}_h{4}_{5}", points.XLeft, points.YTop, area, points.Rect.Width, points.Rect.Height, onDebugCount++); debPic.ToFile(fileName); System.IO.File.WriteAllText(fileName + "hash.txt", hash); debPic = null; } } }
public static char RecogniseChar(MyPic pic) { pic.ToFileIfConfigured("TextRecognitionLibrary.TextCourierNew10.SaveInput"); Size pSize = pic.getDimenion(); if (pic.getDimenion().Height != 10) { throw new ArgumentException("TextCourierNew10"); } doInitialisation_CourierNew10(); string unqIs2 = pic.ToUniqueString(); if (Dict.ContainsKey(unqIs2)) { char r = (char)Dict[unqIs2]; if (r == 99) { return('?'); } r += '0'; return(r); } else { // not there, so dump the file so it can be added to the configration if (unqIs2.Length < 110) { pic.ToFile(unqIs2); } } MyPic picBlack = pic.Threshold_AlmostBlack(); string unqIs = picBlack.ToUniqueString(); //string unqIs2 = pic.ToUniqueString(); return('?'); }
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); }
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); } }
public static SpecificResult_SearchGlas DetectSearchGlas(MyPic mPic, bool debug = false, int minSize = 0) { List <ObjData> SearchGlases = new List <ObjData>(); SearchGlases.Add(new ObjData() { Width = 12, Height = 13, Hash = "000111000000110001000010000001000100000001001000000010000000000100100000001001000000110001000011000001111101000000000001000000000001" }); SearchGlases.Add(new ObjData() { Width = 14, Height = 14, Hash = "0001111000000001111111000001100000110001100000011000110000000100011000000010001100000011000010000001100001110011100000011111101100000000000111000000000001110000000000011" }); SearchGlases.Add(new ObjData() { Width = 14, Height = 14, Hash = "0001111100000001111111000001100001110001100000011000110000000100011000000010001100000011000111000001100001110011110000011111111100000000000111000000000001110000000000011" }); SearchGlases.Add(new ObjData() { Width = 14, Height = 14, Hash = "0001111100000011111111000001100001110001100000011000110000001110011000000011001100000011000111000001100001111011110000011111111100000001000111000000000001110000000000011" }); List <ObjData> Backs = new List <ObjData>(); Backs.Add(new ObjData() { Width = 16, Height = 16, Hash = "000000011000000000000111000000000001111000000000011110000000000111100000000001111000000000011110000000000111111111111111111111111111111011110000000000001111000000000000111100000000000011110000000000001111000000000000111000000" }); List <ObjData> Xes = new List <ObjData>(); Xes.Add(new ObjData() { Width = 9, Height = 10, Hash = "100000001100000101100011001101100001110000011100001101100110001111000001" }); Xes.Add(new ObjData() { Width = 10, Height = 10, Hash = "110000001111000011011100111001111110000111100000111100001111110011100111111000011" }); Xes.Add(new ObjData() { Width = 10, Height = 10, Hash = "110000000011000001001100011000110110000011100000011100000110110001100011011000001" }); SpecificResult_SearchGlas r = new SpecificResult_SearchGlas(); r.SearchGlasPos = new Point(); r.XPos = new Point(); MyPic mClone = (MyPic)mPic.getClone(); mClone.Threshold_AlmostBlack(); mClone.ToFile("DetectSearchGlas"); ObjectDetection od = new ObjectDetection(mClone, true, true); od.DoDetection(new dOnDetectObject(delegate(ObjectPoints points, IPicAccess originalPic) { // test s //if (points.Rect.Height > 9) //{ // if (i == 37) // { // string s37 = points.CalcHashString(); // } // ObjectDetection.ObjectToPic_RegionOfInterest(points, originalPic).ToFile("SearchGlas_" + i++.ToString()); //} //if (points.XLeft != 0) //mg to find new objects //{ // if ((points.Rect.Height > 3) && (points.Rect.Width > 3)) // { // MyPic debug = new MyPic(points); // int area = points.Rect.Width * points.Rect.Height; // string hash = points.CalcHashString(); // string fileName = String.Format("DetectSearchGlasSub_{0}_{1}_{2}_w{3}_h{4}", points.XLeft, points.YTop, area, points.Rect.Width, points.Rect.Height); // debug.ToFile(fileName); // System.IO.File.WriteAllText(fileName + "hash.txt", hash); // debug = null; // } //} // test e if (Contains(SearchGlases, points)) { // found it r.SearchGlasPos = points.Rect.Location; r.SearchGlasPos.Offset(points.Rect.Width / 2, points.Rect.Height / 2); } if (Contains(Backs, points)) { r.SearchGlasPos = points.Rect.Location; r.SearchGlasPos.Offset(points.Rect.Width / 2, points.Rect.Height / 2); r.SearchGlasInFactIsABack = true; } if (Contains(Xes, points)) { r.XPos = points.Rect.Location; r.XPos.Offset(points.Rect.Width / 2, points.Rect.Height / 2); } if ((!r.SearchGlasPos.IsEmpty) || (!r.XPos.IsEmpty)) { return(false); } return(true); }), debug, minSize); // cals common return(r); }