找到一个图像轮廓重心 [英] Finding an Images Contours Centroid

查看:596
本文介绍了找到一个图像轮廓重心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图来计算,像这样的图像质心:

I am trying to calculate an image centroid like so:

// Calculate centroid
    double signedArea = 0.0;
    sskp_point centroid;
    for(int i=0;i<numPoints;i++)
    {
        double a = (points[i].x*points[(i+1)%numPoints].y)-(points[(i+1)%numPoints].x*points[i].y);
        signedArea += a;
        centroid.x += (points[i].x*points[(i+1)%numPoints].x)*a;
        centroid.y += (points[i].y*points[(i+1)%numPoints].y)*a;
        printf("points[%d] = { %f, %f }\n",i,points[i].x,points[i].y);
    }
    signedArea /= 2.0;
    centroid.x /= (6*signedArea);
    centroid.y /= (6*signedArea);
    printf("centroid = { %f, %f }\n",centroid.x,centroid.y);

我从这里算法适应这一点,但是它给我错了结果的,谁能告诉我什么是错与此相适应?

I have adapted this from the algorithm here, however it is giving me the wrong results, can anyone tell me what is wrong with this adaptation?

推荐答案

您已经写了 centroid.x + =(分[I] .X *点[(I + 1)%为NumPoints]。 X)* A;
相反,它应该是 centroid.x + =(分[I] .X +点[(I + 1)%为NumPoints] .X)* A;
必须更换 * + 在这里。

这篇关于找到一个图像轮廓重心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆