这是我的示例代码:
(...) for (int i = 0; i < counting.total(); i++) {
CvPoint3D32f circle = new CvPoint3D32f(cvGetSeqElem(couting, i));
CvPoint middle = cvPointFrom32f(new CvPoint2D32f(circle.x(), circle.y()));
int radious = Math.round(circle.z())
} (...)
circle.x和circle.y为我提供了计算所需的参数。例如,当我把它放入:
System.out.println(circle.x() +" " +circle.y());
它会给我一个输出(取决于我得到了多少圈):
48 91 (x1,y1)
43 31 (x2,y2)
41 43 (x3,y3)
等
我的问题是:如何告诉我的程序,例如我想计算x1 + x3? 我想我需要将输出放入数组但我不知道如何:(
答案 0 :(得分:1)
使用2d数组
int xy[][]=new int[counting.total()][2];
并在循环内添加
xy[i][0]=circle.x();
xy[i][1]=circle.y();
如果你想计算x1+x3
然后取值。不要忘记数组是基于零索引的
1st[row] 3rd[row]
↓ ↓
int total=xy[0][0]+xy[2][0];
↑ ↑
1st[col] 1st[col]
<小时/> 示例代码。但是使用
counting.total()
的变量来避免重复
int xy[][]=new int[counting.total()][2];
for (int i = 0; i < counting.total(); i++) {
CvPoint3D32f circle = new CvPoint3D32f(cvGetSeqElem(couting, i));
CvPoint middle = cvPointFrom32f(new CvPoint2D32f(circle.x(), circle.y()));
int radious = Math.round(circle.z())
xy[i][0]=circle.x();
xy[i][1]=circle.y();
}
int total=xy[0][0]+xy[2][0];// x1+x3 =[row 1][col 1]+[row 3][col 2] // since arrays are zero index based ,row 1-->x[0] vice visa ...