如何得到一个轮廓的质心? Android的OpenCV的 [英] How to get the mass center of a contour ? Android opencv
本文介绍了如何得到一个轮廓的质心? Android的OpenCV的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是C ++ code。
This is the c++ code.
vector<Moments> mu(contours.size() );
for( int i = 0; i < contours.size(); i++ ){
mu[i] = moments( contours[i], false );
}
//Mass center
vector<Point2f> mc( contours.size() );
for( int i = 0; i < contours.size(); i++ ){
mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 );
}
这是我的code迄今在Android的。我不能转换的质量中心到Android。
This is my code so far in android. I can't convert the mass center to android.
//moments
List<Moments> mu = new ArrayList<Moments>(contours.size());
for (int i = 0; i < contours.size(); i++) {
mu.add(i, Imgproc.moments(contours.get(i), false));
}
//mass center
List<MatOfPoint2f> mc = new ArrayList<MatOfPoint2f>(contours.size());
for( int i = 0; i < contours.size(); i++ ){
mc.add((mu.get(i).get_m10() / mu.get(i).get_m00() , mu.get(i).get_m01()/mu.get(i).get_m00()));
}
在这一行错误:
mc.add((mu.get(i).get_m10() / mu.get(i).get_m00() , mu.get(i).get_m01()/mu.get(i).get_m00()));
在此先感谢。
Thanks in advance.
推荐答案
这code会发现所有的轮廓的位置。
This code will find the position of all contours.
List<Moments> mu = new ArrayList<Moments>(Contours.size());
for (int i = 0; i < Contours.size(); i++) {
mu.add(i, Imgproc.moments(Contours.get(i), false));
Moments p = mu.get(i);
int x = (int) (p.get_m10() / p.get_m00());
int y = (int) (p.get_m01() / p.get_m00());
Core.circle(rgbaImage, new Point(x, y), 4, new Scalar(255,49,0,255));
}
这篇关于如何得到一个轮廓的质心? Android的OpenCV的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文