0
我運行視頻(文件)的運動檢測算法,並遵循代碼示例運動檢測,並試圖找到每個組件和整體運動的角度。我確實得到了一個運動值,並帶有斑點等,但每個組件的運動方向始終爲0度或360度,並且沒有意義。我可能做錯了什麼?請幫忙,謝謝。EmguCV - 移動偵測不返回角度
這是構造
_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";
}