X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fjp%2Fnyatla%2Fnyartoolkit%2Fcore%2Fsquaredetect%2FNyARVertexCounter.java;h=8aa1833e8d46681e11ce959431a3c8156ff7e02f;hb=a513010fa26fa8ca6cff622b472d2938aad3521f;hp=b82940fd40276423c9029851f513640c1a311440;hpb=13762930a4e4862fcdf7781a54d77b742711431b;p=nyartoolkit-and%2Fnyartoolkit-and.git diff --git a/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARVertexCounter.java b/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARVertexCounter.java index b82940f..8aa1833 100644 --- a/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARVertexCounter.java +++ b/src/jp/nyatla/nyartoolkit/core/squaredetect/NyARVertexCounter.java @@ -46,13 +46,13 @@ final public class NyARVertexCounter private int[] y_coord; - public boolean getVertex(int[] i_x_coord, int[] i_y_coord, int st, int ed, double i_thresh) + public boolean getVertex(int[] i_x_coord, int[] i_y_coord,int i_coord_len,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); + return get_vertex(st, ed,i_coord_len); } /** @@ -65,7 +65,7 @@ final public class NyARVertexCounter * @param thresh * @return */ - private boolean get_vertex(int st, int ed) + private boolean get_vertex(int st, int ed,int i_coord_len) { //メモ:座標値は65536を超えなければint32で扱って大丈夫なので変更。 //dmaxは4乗なのでやるとしてもint64じゃないとマズイ @@ -76,15 +76,36 @@ final public class NyARVertexCounter final int b = lx_coord[st] - lx_coord[ed]; final int 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(st dmax) { + dmax = d * d; + v1 = i; + } + } + }else{ + //stとedが2区間 + for (int i = st + 1; i < i_coord_len; i++) { + final double d = a * lx_coord[i] + b * ly_coord[i] + c; + if (d * d > dmax) { + dmax = d * d; + v1 = i; + } + } + for (int i = 0; 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 / (double)(a * a + b * b) > thresh) { - if (!get_vertex(st, v1)) { + if (!get_vertex(st, v1,i_coord_len)) { return false; } if (number_of_vertex > 5) { @@ -93,7 +114,7 @@ final public class NyARVertexCounter vertex[number_of_vertex] = v1;// vertex[(*vnum)] = v1; number_of_vertex++;// (*vnum)++; - if (!get_vertex(v1, ed)) { + if (!get_vertex(v1, ed,i_coord_len)) { return false; } }