物体的质心 [英] center of mass of an object

查看:109
本文介绍了物体的质心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



有谁知道如何找到图像中物体的质心?

我正在工作用C#和OpenCV



谢谢!

hello

does anyone know how to find the center of mass of an object in an image?
I''m working with C # and OpenCV

thank you!

推荐答案

这是一个非常简单的任务,我会说,对于中学或其他什么。以下是解决方案:

http://en.wikipedia.org/wiki/Center_of_mass [ ^ ]。



有趣的是,在您的算法中,您首先选择一些任意点(靠近中心以获得更好的准确度),相对于此点进行计算,它会为您提供真正的质心。



此外,还不清楚图像及其质心是什么意思。如果图像是矩形并且所有像素具有相同的权重,则这仅仅是矩形的中心。如果像素按透明度或颜色加权,请使用上面提到的算法。如果这是某种矢量图形,你将需要使用微积分而不是谨慎求和,这在大多数情况下也很容易。



-SA
This is a very simple task, I would say, for the middle school or something. Here is the solution:
http://en.wikipedia.org/wiki/Center_of_mass[^].

Interestingly, in your algorithm you first select some arbitrary point (close to center to get better accuracy), do the calculation relative to this point, and it gives you the real center of mass.

Also, it''s not clear what do you mean by image and its center of mass. If the image is rectangle and all pixels has the same weight, this is simply a center of the rectangle. If pixels are weighted by transparency or colors, use the algorithm mentioned above. If this is some sort of vector graphics, you will need to use calculus instead of discreet summation, which is also pretty easy in most cases.

—SA


我不认为这是一件容易的事情谢尔盖,或许这个问题还不够清楚。对于找到可视对象中心的算法,首先要检测它,我可以建议使用基于投票的方法,如广义的hough变换 http://www.cs.utexas.edu/~dana/HoughT.pdf [ ^ ]或几何哈希 http://graphics.stanford.edu/courses/cs468-01-winter/papers/wr-ghao-97.pdf [ ^ ],每个要素点都应投票给对象中心,特征点可以是由精确边缘检测器或SIFT关键点检测到的边缘上的点,其中一个使用取决于应用。对于简单的图像,使用像素分组的分割甚至可以找到视觉对象的中心。





在这种情况下尝试使用方法cvFindContours和cvBoundingRect,边界矩形的中心将给出近似(如果不是对象的确切中心)。



I don''t think this is an easy task Sergey, perhaps the question is not clear enough. For the algorithm to find the center of a visual object,the first thing is to detect it, I can suggest using voting based methods such as generalized hough transform http://www.cs.utexas.edu/~dana/HoughT.pdf[^] or geometric hashing http://graphics.stanford.edu/courses/cs468-01-winter/papers/wr-ghao-97.pdf[^], each feature point should vote for the object center, the feature point can be a point on an edge detected by canny edge detector or SIFT key points, which one to use depends on the application. For simple images even segmentation using pixel grouping can find the center of the visual object.


In that case try using the methods cvFindContours and cvBoundingRect, the center of the of the bounding rectangle will give the approximate if not the exact center of your objects.

#include <iostream>
#include <vector>
#include <cv.h>
#include <highgui.h>

using namespace std;

int main(int argc, char** argv){


IplImage* img_in = cvLoadImage("your_image.jpg",1);


IplImage* img_working = cvCreateImage(cvGetSize(img_in), 8, 1);
cvCvtColor(img_in, img_working, CV_BGR2GRAY);

CvSeq* seq;

vector<CvRect> boxes;

CvMemStorage* storage = cvCreateMemStorage(0);
cvClearMemStorage(storage);

cvFindContours(img_working, storage, &seq, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE, cvPoint(600,200));

CvRect boundbox ;

for(; seq; seq = seq->h_next) {
 boundbox = cvBoundingRect(seq);
 boxes.push_back(boundbox);
}

cvWaitKey(0);

return 0;

}


假设对象具有均匀的密度,我想你可以选择图像中的任意一点然后全部从该点到落在对象中的所有其他点(构成对象的像素)。然后对这些向量求和并将它们除以向量的数量,质心应该在起点加上得到的向量。



希望这会有所帮助,

Fredrik Bornander
Assuming that the object has uniform density, I think you can pick a any point in the image and then take all the vectors from that point to all other points that fall in the object (the pixels that make up the object essentially). Then sum those vectors and divide them by the number of vectors and the center of mass should be at the start point plus the resulting vector.

Hope this helps,
Fredrik Bornander


这篇关于物体的质心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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