3.24 图像矩 - Image Moments
使用
moments 函数计算图像所有的矩(最高到3阶)。
使用
contourArea 函数计算轮廓面积。
使用
arcLength 函数计算轮廓或曲线长度。
/** @thresh_callback 函数 */
void thresh_callback(int, void* )
{
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
/// 使用Canndy检测边缘
Canny( src_gray, canny_output, thresh, thresh*2, 3 );
/// 找到轮廓
findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
/// 计算矩
vector<Moments> mu(contours.size() );
for( int i = 0; i < contours.size(); i++ )
{ mu[i] = moments( contours[i], false ); }
/// 计算中心矩:
vector<Point2f> mc( contours.size() );
for( int i = 0; i < contours.size(); i++ )
{ mc[i] = Point2