维基百科关于 Moment (mathematics) 的介绍:
In mathematics, a moment is a specific quantitative measure, used in both mechanics and statistics, of the shape of a set of points. If the points represent mass, then the zeroth moment is the total mass, the first moment divided by the total mass is the center of mass, and the second moment is the rotational inertia. If the points represent probability density, then the zeroth moment is the total probability (i.e. one), the first moment is the mean, the second central moment is the variance, the third moment is the skewness, and the fourth moment (with normalization and shift) is the kurtosis. The mathematical concept is closely related to the concept of moment in physics.For a bounded distribution of mass or probability, the collection of all the moments (of all orders, from 0 to ∞) uniquely determines the distribution.
设 X 和 Y 是随机变量,c 为常数,k 为正整数,
如果 E(|X−c|k) E ( | X − c | k ) 存在,则称 E(|X−c|k) E ( | X − c | k ) 为 X 关于点 c 的 k 阶矩。
如果 E(|X−c1|p⋅|Y−c2|q) E ( | X − c 1 | p ⋅ | Y − c 2 | q ) 存在,则称其为 X,Y 关于 c 点 p+q 阶矩。
fastAtan2()为opencv的函数,输入向量,返回一个0-360的角度。
这里修改一下,我之前在看二阶矩求物体形状方向的时候,有公式是这么写的:
Mat image = imread(imagename, 0);//读入灰度图
Mat binary;
//二值,椭圆是黑色的,所以反色下
threshold(image, binary, 200, 255, CV_THRESH_BINARY_INV);
Moments m = moments(binary, true);//moments()函数计算出三阶及一下的矩
Point2d center(m.m10 / m.m00, m.m01 / m.m00);//此为重心
//计算方向
double a = m.m20 / m.m00 - center.x*center.x;
double b = m.m11 / m.m00 - center.x*center.y;
double c = m.m02 / m.m00 - center.y*center.y;
double theta = fastAtan2(2*b,(a - c))/2;//此为形状的方向
图片测试:
从上图可以发现,这样算出来的方向是以x轴正方向为 0 0 ,第四象限为 0−π/2 0 − π / 2 ,第三象限为 π/2−π π / 2 − π 的范围内。
图像的矩通常描述了该图像的全局特征,并提供了大量的关于该图像不同类型的几何特性信息,比如大小,位置,方向及形状等。在模式识别,目标分类,目标识别等有着广泛的应用。