c# - EmguCV - 运动检测不返回角度

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

最佳答案

啊哈!如果有人遇到同样的问题,我找出原因并在此处发布。这

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

应根据帧速率和运动进行调整。诀窍在于 3 个参数
(1) 要保留的运动历史,(2) 最大时间增量,(3) 最小时间增量。

它们需要以某种方式进行调整,以反射(reflect)您希望捕捉的 Action 。
希望有帮助。

https://stackoverflow.com/questions/7714169/

相关文章:

opencv - 无法使用 OpenCV 从 FireWire cam 捕获图像

visual-c++ - OpenCV Connected Component标签颜色?

c# - 如何申请cvsobel + emgucv

android - 使用opencv在android中抓取连续帧

c# - Windows 7 x32下C#中dllimport的问题

opencv - 使用openCV GMM类进行对象建模

opencv - Linux上的OpenCV编译:如何向其提供特定的zlib lib?

colors - 识别opencv中检测到的圆圈的颜色

python-3.x - 队列的等价arg 'durable'

opencv - 保存IPL_DEPTH_IMAGE供以后处理