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

标签 c# opencv 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 。
希望有帮助。

关于c# - EmguCV - 运动检测不返回角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7714169/

相关文章:

c# - 使用 emgucv 2.1.0.0 加载视频文件

ubuntu - 一个 USB 集线器上的两个网络摄像头 - 带宽问题

c# - 将OpenCV C++重写为EmguCV C#-如何使用指针?

c# - 帮忙解析我自己的表达式树,C#

c# - ASP.NET、HttpWebRequest 和 "Could not create SSL/TLS secure channel"

opencv - 查找 cv::Mat 的字节大小

python - 使用 Conda 安装 OpenCV

c# - 使用EMGU的两个图像之间的相关性

c# - jQuery 多重自动完成与 c#

c# - 使用 MonoTouch 访问 WebScriptObject