EmguCV -运动检测不返回角度

本文关键字:返回 运动检测 EmguCV | 更新日期: 2023-09-27 18:10:55

我正在运行针对视频(文件)的运动检测算法,并遵循代码样本运动检测,并试图找到每个组件和整体运动的角度。我确实得到了一个运动值,带有斑点等,但每个组件的运动方向总是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";
        }

EmguCV -运动检测不返回角度

啊哈!我找出了原因,并张贴在这里,如果有人遇到同样的问题。

_motionHistory = new MotionHistory(mhi, maxDelta, minDelta); 

应该调整到帧率和运动。诀窍在于这3个参数(1)保持运动历史,(2)最大时间增量,(3)最小时间增量。

它们需要以某种方式进行调整以反映您希望捕获的运动。