Esempio n. 1
0
 public override string ToString()
 {
     if (Vector == null)
     {
         Vector = new DiffVector(0, 0, 0);
     }
     return($"{Vector.X},{Vector.Y}  {Vector.Diff.ToString("0.00")}");
 }
Esempio n. 2
0
        public static void FindObjectDown(PreVidStream stream, Mat curr, RealTimeTrackLoc prms, BreakDiffDebugReporter reporter)
        {
            const int LookBack = 2;
            int       from     = prms.CurPos - LookBack;
            int       to       = from + prms.LookAfter + LookBack;

            if (to == 0 || to > stream.Total)
            {
                to = stream.Total;
            }
            if (from < 0)
            {
                from = 0;
            }
            var             skipAvgs  = prms.CurPos >= LookBack ? LookBack : LookBack - prms.CurPos;
            List <DiffVect> processed = new List <DiffVect>();

            //double dxT = 0, dyT = 0;
            //int numD = 0;
            for (int pos = from; pos < to; pos++)
            {
                var loc = FindInRage(stream, curr, 1, pos, pos + 1);
                processed.Add(loc);
            }

            if (processed[2].Vector.Diff > 0.5)
            {
                for (var i = 0; i < LookBack; i++)
                {
                    processed.RemoveAt(0);
                }
            }
            //processed.OrderByDescending(x => x.Vector.Diff).Take(3);

            prms.DebugAllLooks = processed;
            var sorted = SortProcessDiffVects(processed).Take(5);
            var curMax = sorted.FirstOrDefault();

            if (curMax == null || curMax.VidPos >= stream.Total - 1)
            {
                Console.WriteLine($"max not found from={from} to={to} total={stream.Total}");
                return;
            }
            //Console.WriteLine($"max at {curMax.Pos} {curMax.diff.ToString("0.00")}");
            prms.NextPos = curMax.VidPos;
            prms.diff    = curMax.Vector.Diff;
            prms.vect    = curMax.Vector;

            stream.Pos = curMax.VidPos;
            var diff = CompDiff(curr, stream.GetCurMat(), reporter);
            //var nextVect = stream.Vectors[curMax.VidPos];  //orig way
            var nextVect = new DiffVector(sorted.Average(x => x.Vector.X), sorted.Average(y => y.Vector.Y), sorted.Average(d => d.Vector.Diff));

            //diff: negative if need to turn left
            //vect: positive if need to turn left
            prms.vect = new DiffVector(nextVect.X + (diff.Vector.X / 10.0), nextVect.Y + diff.Vector.Y, diff.Vector.Diff);

            reporter.InfoReport($"===> {(prms.vect.X>0?"L":"R")} ({prms.vect}) nextX {nextVect.X} diffX {diff.Vector.X} pos {curMax.VidPos}", true);

            prms.diffVect = diff;
            prms.nextVect = nextVect;
        }