在这段视频中,当球进入画面时,我很难捕捉到
http://www.youtube.com/watch?v=x1V6_OHrXIo
我也不知道要设置什么参数,而且尝试随机值似乎根本没有帮助,我看不到模式来知道数字有什么影响。这就是我正在尝试的。
背景减法或颜色检测不起作用,因为它们很容易改变。我需要一个更通用的解决方案。
var laneSixBedRect = new Rectangle(new Point(240, 185), new Size(240, 150));
var laneSixBed = imgSource.GetSubRect(laneSixBedRect);
TrackShot(laneSixBed);
private static void TrackShot(Image<Bgr, byte> laneBed)
{
var laneBedGray = laneBed.Convert<Gray, byte>();
var circles = laneBedGray.HoughCircles(
new Gray(150), //cannyThreshold
new Gray(75), //circleAccumulatorThreshold
2.0, //Resolution of the accumulator used to detect centers of the circles
20.0, //min distance
5, //min radius
50 //max radius
)[0]; //Get the circles from the first channel
foreach (CircleF circle in circles)
laneBed.Draw(circle, new Bgr(Color.Brown), 2);
}
编辑:这是我的 currentTrackShot 方法,它的准确率大约为 70%,仍然有一些误报,还有一些漏报。
private static void TrackShot(Rectangle laneRect, Image<Bgr, byte> prevImage, Image<Bgr, byte> currImage, Image<Bgr, byte> background)
{
var laneBedBack = background.GetSubRect(laneRect);
var laneBedPrev = prevImage.GetSubRect(laneRect);
var laneBedCurr = currImage.GetSubRect(laneRect);
var laneBedBackGray = laneBedBack.Convert<Gray, byte>();
//TODO: Should these be Smoothed?
var laneBedPrevGray = laneBedPrev.Convert<Gray, byte>().SmoothGaussian(5);
var laneBedCurrGray = laneBedCurr.Convert<Gray, byte>().SmoothGaussian(5);
//TODO: Uncomment to see difference between frames, nearly black when no motion
//var diff = laneBedPrevGray.AbsDiff(laneBedCurrGray);
//diff.Convert<Bgr, byte>().CopyTo(laneBedCurr);
//TODO: Improve these values
var prevFeatures = laneBedPrevGray.GoodFeaturesToTrack(100, .01, .1, 3)[0];
var returnFeatures = new PointF[1];
byte[] status;
float[] trackError;
OpticalFlow.PyrLK(laneBedPrevGray, laneBedCurrGray, prevFeatures, new Size(15, 15), 5, new MCvTermCriteria(5), out returnFeatures, out status, out trackError);
//TODO: Now how do I refine this???
for (var i = 0; i < returnFeatures.Length; i++)
{
var prevPoint = prevFeatures[i];
var currPoint = returnFeatures[i];
var state = status[i];
var error = trackError[i];
var line = new LineSegment2D(new Point((int)prevPoint.X, (int)prevPoint.Y), new Point((int)currPoint.X, (int)currPoint.Y));
if (state == 1 && line.Length > 15 && error < 10)
{
laneBedCurr.Draw(line, new Bgr(Color.Green), 3);
Console.WriteLine("E: {0}", error);
Console.WriteLine("L: {0}", line.Length);
}
}
viewerModified.Image = currImage;
}
EDIT2:我的终极目标是能够沿着球的轨迹画一条线,并以某种可以与其他方式进行比较的方式存储该轨迹。