public void TestLKFlow() { var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "Resources", "LKFlow"); var im1 = Bitmap.FromFile(Path.Combine(path, "1.bmp")).ToImage <Gray, float>(); var im2 = Bitmap.FromFile(Path.Combine(path, "2.bmp")).ToImage <Gray, float>(); var pts = new List <PointF>(); pts.Add(new PointF(272, 82)); //-> 277,83 PointF[] currFeatures; float[] error; KLTFeatureStatus[] featureStatus; /*LKOpticalFlow<Gray>.EstimateFlow(lkStorage, pts.ToArray(), * out currFeatures, out featureStatus, out error);*/ PyrLKOpticalFlow <Gray> .EstimateFlow(im1, im2, pts.ToArray(), out currFeatures, out featureStatus, out error, 15, 15, 0.1f, 0.05f, 0.1f, 0); var debug = im2.Convert <Bgr, byte>(); debug[(int)currFeatures.First().Y, (int)currFeatures.First().X] = Bgr8.Red; debug.Save("bla.bmp"); }
public void TestLKFlow() { var im1 = new Gray <float> [480, 640]; im1.SetValue <Gray <float> >(System.Byte.MaxValue, new Rectangle(272, 82, 116, 64)); var im2 = new Gray <float> [480, 640]; im2.SetValue <Gray <float> >(System.Byte.MaxValue, new Rectangle(277, 83, 116, 64)); var pts = new List <PointF>(); pts.Add(new PointF(272, 82)); //-> 277,83 PointF[] currFeatures; KLTFeatureStatus[] featureStatus; /*LKOpticalFlow<Gray<float>>.EstimateFlow(lkStorage, pts.ToArray(), * out currFeatures, out featureStatus);*/ PyrLKOpticalFlow <Gray <float> > .EstimateFlow(im1, im2, pts.ToArray(), out currFeatures, out featureStatus); Assert.IsTrue(featureStatus[0] == KLTFeatureStatus.Success); Assert.IsTrue(Math.Round(currFeatures[0].X) == 277 && Math.Round(currFeatures[0].Y) == 83); }
private void processImage(Image <FlowColor, float> prevIm, Image <FlowColor, float> currIm, List <PointF> oldPositions, out List <PointF> newPositions) { lkStorage.Process(prevIm, currIm); PointF[] currFeatures; float[] error; KLTFeatureStatus[] featureStatus; /*LKOpticalFlow<FlowColor>.EstimateFlow(lkStorage, oldPositions.ToArray(), * out currFeatures, out featureStatus, out error, * winSize);*/ PyrLKOpticalFlow <FlowColor> .EstimateFlow(lkStorage, oldPositions.ToArray(), out currFeatures, out featureStatus, out error, winSize); newPositions = new List <PointF>(); for (int i = 0; i < currFeatures.Length; i++) { if (featureStatus[i] == KLTFeatureStatus.Success) { newPositions.Add(currFeatures[i]); } Console.WriteLine(featureStatus[i]); } }
private void processImage(Gray <float>[,] prevIm, Gray <float>[,] currIm, List <PointF> oldPositions, out List <PointF> newPositions) { lkStorage.Process(prevIm, currIm); PointF[] currFeatures; KLTFeatureStatus[] featureStatus; PyrLKOpticalFlow <Gray <float> > .EstimateFlow(lkStorage, oldPositions.ToArray(), out currFeatures, out featureStatus, winSize); newPositions = new List <PointF>(); for (int i = 0; i < currFeatures.Length; i++) { if (featureStatus[i] == KLTFeatureStatus.Success) { newPositions.Add(currFeatures[i]); } Console.WriteLine(featureStatus[i]); } }