我针对视频(文件)运行运动检测算法并遵循代码样本运动检测,并尝试找到每个分量的角度和整体运动。我确实得到一个运动值,有blob等,但每个组件的运动方向总是0度或360度,没有任何意义。我能做错什么?请帮助,谢谢。
这是构造函数
_motionHistory = new MotionHistory(
10.0, //in second, the duration of motion history you wants to keep
0.05, //in second, parameter for cvCalcMotionGradient
0.5); //in second, parameter for cvCalcMotionGradient
以下是循环运动组件的代码:
foreach (MCvConnectedComp comp in motionComponents)
{
//reject the components that have small area;
if (comp.area < 1) continue;
// find the angle and motion pixel count of the specific area
double angle, motionPixelCount;
_motionHistory.MotionInfo(comp.rect, out angle, out motionPixelCount);
string motion_direction = GetMotionDescriptor(comp.rect);
Console.writeline (motion_direction);
}
// find and draw the overall motion angle
double overallAngle, overallMotionPixelCount;
_motionHistory.MotionInfo(motionMask.ROI, out overallAngle, out overallMotionPixelCount);
这就是我得到运动描述符角度
的地方private string GetMotionDescriptor(Rectangle motionRegion)
{
float circleRadius = (motionRegion.Width + motionRegion.Height) >> 2;
Point center = new Point(motionRegion.X + motionRegion.Width >> 1, motionRegion.Y + motionRegion.Height >> 1);
int xDirection = (int)(Math.Cos(angle * (Math.PI / 180.0)) * circleRadius);
int yDirection = (int)(Math.Sin(angle * (Math.PI / 180.0)) * circleRadius);
//double movementAngle = Math.Atan(xDirection / yDirection) * 180 / Math.PI;
Point pointOnCircle = new Point(center.X + xDirection, center.Y - yDirection);
double slope = (double)(pointOnCircle.Y - center.Y)/(double)(pointOnCircle.X - center.X);
double ang = Math.Atan(slope) * 180/Math.PI;
return (ang).ToString() + " degrees";
}
答案 0 :(得分:2)
AHA!我想出了原因并在此发布,如果有人遇到同样的问题。
_motionHistory = new MotionHistory(mhi, maxDelta, minDelta);
应调整到帧率和动作。诀窍在于3个参数 (1)要保持的运动历史,(2)最大时间增量,(3)最小时间增量。
需要以某种方式调整它们以反映您想要捕捉的动作。 希望有所帮助。