Beispiel #1
0
        public void CamTracking(Mat curImg, VidLoc.RealTimeTrackLoc realTimeTrack, PreVidStream vidProvider, IDriver driver, BreakDiffDebugReporter debugReporter)
        {
            debugReporter.ReportInProcessing(true);
            results       = haar.Detect(curImg);
            result.Width  = 0;
            result.Height = 0;
            if (results != null && results.Length > 0)
            {
                results = results.OrderByDescending(r => r.Width * r.Height).ToArray();
                result  = results[0];
            }
            debugReporter.ReportInProcessing(false);
            realTimeTrack.CurPos = 0;
            DiffVect vect = new DiffVect();

            vect.Vector = realTimeTrack.vect;
            debugReporter.ReportStepChanges(new StepChangeReporter(curImg, results, result), vect);
            if (result.Width == 0)
            {
                //debugReporter.InfoReport($"NA");
                driver.Stop();
            }
            else
            {
                double diff = (curImg.Width / 2) - ((result.X + result.Width) / 2);
                //debugReporter.InfoReport($"{(diff > 0? "L":"R") } diff {diff.ToString("0.0")} imw ${((result.X + result.Width) / 2)}");
                realTimeTrack.vect = new DiffVector(diff, 0, 0);
                driver.Track(realTimeTrack);
            }
        }
Beispiel #2
0
        public Mat ShowAllStepChange(DiffVect diffs)
        {
            var compareToImage = compareTo.Clone();

            {
                ShowStepChange(diffs, compareToImage);
            }
            return(compareToImage);
        }
Beispiel #3
0
 public Mat ShowAllStepChange(DiffVect vect)
 {
     foreach (var rect in results)
     {
         CvInvoke.Rectangle(input, rect, new MCvScalar(100));
     }
     if (result.Width != 0)
     {
         CvInvoke.Rectangle(input, result, new MCvScalar(200));
     }
     return(input);
 }
Beispiel #4
0
        public static DiffVect FindInRage(PreVidStream stream, Mat curr, int steping = 1, int from = 0, int to = 0)
        {
            if (to == 0 || to > stream.Total)
            {
                to = stream.Total;
            }
            if (from < 0)
            {
                from = 0;
            }
            DiffVect curMax = null;

            for (int pos = from; pos < to; pos += steping)
            {
                stream.Pos = pos;
                var processor = new ShiftVecProcessor(curr, stream.GetCurMat());
                var all       = processor.GetAllDiffVect();
                all.VidPos = pos;
                var maxGood = all.Vector.Diff;
                if (curMax == null)
                {
                    curMax = all;
                }
                else
                {
                    if (maxGood > curMax.Vector.Diff)
                    {
                        curMax = all;
                    }
                }
            }
            //Console.WriteLine($"max at {curMax.Pos} {curMax.diff.ToString("0.00")}");
            if (steping == 1)
            {
                return(curMax);
            }
            return(FindInRage(stream, curr, 1, curMax.VidPos - steping, curMax.VidPos + steping));
        }
Beispiel #5
0
        public Mat ShowStepChange(DiffVect diffVect, Mat compareToImage)
        {
            var x = diffVect.Location.X;
            int y = diffVect.Location.Y;

            using (var corped = new Mat(input, diffVect.SrcRect))
            {
                if (compareToImage == null)
                {
                    compareToImage = compareTo.Clone();
                }
                //CvInvoke.Rectangle(compareToImage, new Rectangle(x, y, CutSize, CutSize), new MCvScalar(0));

                var toRect = new Rectangle(x + (int)diffVect.Vector.X, y + (int)diffVect.Vector.Y, diffVect.SrcRect.Width, diffVect.SrcRect.Height);
                corped.CopyTo(new Mat(compareToImage, toRect));
                //CvInvoke.Rectangle(compareToImage, new Rectangle(x, y, CutSize, CutSize), new MCvScalar(200));
                CvInvoke.Rectangle(compareToImage, toRect, new MCvScalar(100));
                CvInvoke.Line(compareToImage, new Point(x, y), toRect.Location, new MCvScalar(150));
                CvInvoke.PutText(compareToImage, diffVect.Vector.Diff.ToString("0.00"), ClonePointWithYOff(toRect.Location, 10), FontFace.HersheyPlain, 1, new MCvScalar(10));
                CvInvoke.PutText(compareToImage, diffVect.Vector.X.ToString("0.00"), ClonePointWithYOff(toRect.Location, 20), FontFace.HersheyPlain, 1, new MCvScalar(10));
                return(compareToImage);
            }
        }
Beispiel #6
0
 public DiffVect CalculateDiffVectDbg(Rectangle srcRect, Action <DiffDebug> dbgAct)
 {
     using (var corped = new Mat(input, srcRect))
     {
         //var cmpToRect = ShiftVecDector.getExtCropRect(compareTo, x, y, CutSize, CmpExtend);
         //using (var cmpToCorp = new Mat(compareTo, cmpToRect))
         var cmpToCorp = compareTo;
         {
             //corped.Save(@"d:\temp\test\" + x + "_" + y + ".jpg");
             using (var matched = cmpToCorp.ToImage <Gray, Byte>().MatchTemplate(corped.ToImage <Gray, Byte>(), TemplateMatchingType.CcoeffNormed))
             {
                 double[] minValues, maxValues;
                 Point[]  minLocs, maxLocs;
                 matched.MinMax(out minValues, out maxValues, out minLocs, out maxLocs);
                 Point  maxLoc   = maxLocs[0];
                 double maxVal   = maxValues[0];
                 var    diffVect = new DiffVect {
                     Location = srcRect.Location, SrcRect = srcRect, Vector = new DiffVector(maxLoc.X - srcRect.X, maxLoc.Y - srcRect.Y, maxVal)
                 };
                 //Console.WriteLine(" got  " + diffVect);
                 if (dbgAct != null)
                 {
                     dbgAct(new DiffDebug
                     {
                         Vect    = diffVect,
                         orig    = corped,
                         area    = cmpToCorp,
                         diffMap = matched,
                         SrcRect = srcRect,
                         //CompareToRect = cmpToRect,
                     });
                 }
                 return(diffVect);
             }
         }
     }
 }