📄 nyarvertexdetector.java
字号:
getLine(vertex[3],vertex[2],o_square.line[2]);
getLine(vertex[0],vertex[3],o_square.line[3]);
return;
}
/**
* 辺からの対角線が最長になる点を対角線候補として返す。
*
* @param i_xcoord
* @param i_ycoord
* @param i_coord_num
* @return
*/
private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)
{
final int sx = i_xcoord[0];
final int sy = i_ycoord[0];
int d = 0;
int w, x, y;
int ret = 0;
for (int i = 1; i < i_coord_num; i++) {
x = i_xcoord[i] - sx;
y = i_ycoord[i] - sy;
w = x * x + y * y;
if (w > d) {
d = w;
ret = i;
}
// ここでうまく終了条件入れられないかな。
}
return ret;
}
private final NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();
private final NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();
/**
* static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。
*
* @param i_x_coord
* @param i_y_coord
* @param i_vertex1_index
* @param i_coord_num
* @param i_area
* @param o_vertex
* 要素数はint[4]である事
* @return
*/
private boolean getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)
{
final NyARVertexCounter wv1 = this.__getSquareVertex_wv1;
final NyARVertexCounter wv2 = this.__getSquareVertex_wv2;
final int end_of_coord = i_vertex1_index + i_coord_num - 1;
final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];
final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];
int dmax = 0;
int v1 = i_vertex1_index;
for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)
// {
final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);
if (d > dmax) {
dmax = d;
v1 = i;
}
}
final double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;
o_vertex[0] = i_vertex1_index;
if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh)) { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<
// 0 ) {
return false;
}
if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh)) {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)
// < 0) {
return false;
}
int v2;
if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {
o_vertex[1] = wv1.vertex[0];
o_vertex[2] = v1;
o_vertex[3] = wv2.vertex[0];
} else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {
//頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
v2 = (v1-i_vertex1_index)/2+i_vertex1_index;
if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh)) {
return false;
}
if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh)) {
return false;
}
if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
o_vertex[1] = wv1.vertex[0];
o_vertex[2] = wv2.vertex[0];
o_vertex[3] = v1;
} else {
return false;
}
} else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {
//v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;
v2 = (v1+ end_of_coord)/2;
if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh)) {
return false;
}
if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh)) {
return false;
}
if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
o_vertex[1] = v1;
o_vertex[2] = wv1.vertex[0];
o_vertex[3] = wv2.vertex[0];
} else {
return false;
}
} else {
return false;
}
o_vertex[4] = end_of_coord;
return true;
}
}
/**
* get_vertex関数を切り離すためのクラス
*
*/
final class NyARVertexCounter
{
public final int[] vertex = new int[10];// 5まで削れる
public int number_of_vertex;
private double thresh;
private int[] x_coord;
private int[] y_coord;
public boolean getVertex(int[] i_x_coord, int[] i_y_coord, int st, int ed, double i_thresh)
{
this.number_of_vertex = 0;
this.thresh = i_thresh;
this.x_coord = i_x_coord;
this.y_coord = i_y_coord;
return get_vertex(st, ed);
}
/**
* static int get_vertex( int x_coord[], int y_coord[], int st, int ed,double thresh, int vertex[], int *vnum) 関数の代替関数
*
* @param x_coord
* @param y_coord
* @param st
* @param ed
* @param thresh
* @return
*/
private boolean get_vertex(int st, int ed)
{
int v1 = 0;
final int[] lx_coord = this.x_coord;
final int[] ly_coord = this.y_coord;
final double a = ly_coord[ed] - ly_coord[st];
final double b = lx_coord[st] - lx_coord[ed];
final double c = lx_coord[ed] * ly_coord[st] - ly_coord[ed] * lx_coord[st];
double dmax = 0;
for (int i = st + 1; i < ed; i++) {
final double d = a * lx_coord[i] + b * ly_coord[i] + c;
if (d * d > dmax) {
dmax = d * d;
v1 = i;
}
}
if (dmax / (a * a + b * b) > thresh) {
if (!get_vertex(st, v1)) {
return false;
}
if (number_of_vertex > 5) {
return false;
}
vertex[number_of_vertex] = v1;// vertex[(*vnum)] = v1;
number_of_vertex++;// (*vnum)++;
if (!get_vertex(v1, ed)) {
return false;
}
}
return true;
}
}
/**
* ラベル同士の重なり(内包関係)を調べるクラスです。 ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。
*/
class OverlapChecker
{
private NyARLabelingLabel[] _labels = new NyARLabelingLabel[32];
private int _length;
/**
* 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする
*
* @param i_max_label
*/
public void reset(int i_max_label)
{
if (i_max_label > this._labels.length) {
this._labels = new NyARLabelingLabel[i_max_label];
}
this._length = 0;
}
/**
* チェック対象のラベルを追加する。
*
* @param i_label_ref
*/
public void push(NyARLabelingLabel i_label_ref)
{
this._labels[this._length] = i_label_ref;
this._length++;
}
/**
* 現在リストにあるラベルと重なっているかを返す。
*
* @param i_label
* @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.
*/
public boolean check(NyARLabelingLabel i_label)
{
// 重なり処理かな?
final NyARLabelingLabel[] label_pt = this._labels;
final int px1 = (int) i_label.pos_x;
final int py1 = (int) i_label.pos_y;
for (int i = this._length - 1; i >= 0; i--) {
final int px2 = (int) label_pt[i].pos_x;
final int py2 = (int) label_pt[i].pos_y;
final int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);
if (d < label_pt[i].area / 4) {
// 対象外
return false;
}
}
// 対象
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -