OSDN Git Service

[Backup]NyARToolkit for Java
authornyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Wed, 26 Aug 2009 10:40:46 +0000 (10:40 +0000)
committernyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Wed, 26 Aug 2009 10:40:46 +0000 (10:40 +0000)
浮動小数点クラスの最適化対応

sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeDetector.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/SingleQrTest.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSquareDetector_Quad.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/vertexdetect/NyARVertexDetector.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/JavaSimpleLite_X2.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java [deleted file]
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSingleDetectMarker_X2.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSquareDetector_X2.java
sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/VisualTest.java

index ca7e70a..a58acc8 100644 (file)
@@ -6,19 +6,17 @@ import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;
 import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabelStack;\r
 import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabeling_ARToolKit;\r
 import jp.nyatla.nyartoolkit.core.param.NyARCameraDistortionFactor;\r
-import jp.nyatla.nyartoolkit.core.pca2d.*;\r
 import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.ContourPickup;\r
 import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;\r
 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;\r
-import jp.nyatla.nyartoolkit.core.squaredetect.NyARVertexCounter;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.SquareContourDetector;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
-import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;\r
 \r
 public class NyARQrCodeDetector implements INyARSquareDetector\r
 {\r
        private NyARQrCodeSymbolBinder _binder;\r
-       private static final double VERTEX_FACTOR = 2.0;// 線検出のファクタ\r
 \r
        private static final int AR_AREA_MAX = 10000;\r
 \r
@@ -32,9 +30,9 @@ public class NyARQrCodeDetector implements INyARSquareDetector
 \r
        private final NyARLabelingImage _limage;\r
 \r
-       private final NyARCameraDistortionFactor _dist_factor_ref;\r
-       private final double[] _xpos;\r
-       private final double[] _ypos;\r
+       private final SquareContourDetector _sqconvertor;\r
+       private final ContourPickup _cpickup=new ContourPickup();\r
+       \r
        /**\r
         * 最大i_squre_max個のマーカーを検出するクラスを作成する。\r
         * \r
@@ -44,11 +42,10 @@ public class NyARQrCodeDetector implements INyARSquareDetector
        {\r
                this._width = i_size.w;\r
                this._height = i_size.h;\r
-               this._dist_factor_ref = i_dist_factor_ref;\r
                this._labeling = new NyARLabeling_ARToolKit();\r
                this._limage = new NyARLabelingImage(this._width, this._height);\r
-               this._labeling.attachDestination(this._limage);\r
                this._binder=new NyARQrCodeSymbolBinder(i_dist_factor_ref);\r
+               this._sqconvertor=new SquareContourDetector(i_size,i_dist_factor_ref);\r
 \r
                // 輪郭の最大長はMAX_COORD_NUMの2倍に制限\r
                int number_of_coord = MAX_COORD_NUM* 2;\r
@@ -57,8 +54,6 @@ public class NyARQrCodeDetector implements INyARSquareDetector
                this._max_coord = number_of_coord;\r
                this._xcoord = new int[number_of_coord * 2];\r
                this._ycoord = new int[number_of_coord * 2];\r
-               this._xpos=new double[this._width+this._height];//最大辺長はthis._width+this._height\r
-               this._ypos=new double[this._width+this._height];//最大辺長はthis._width+this._height\r
                \r
        }\r
 \r
@@ -68,14 +63,6 @@ public class NyARQrCodeDetector implements INyARSquareDetector
 \r
        private final int[] _ycoord;\r
 \r
-       private void normalizeCoord(int[] i_coord_x, int[] i_coord_y, int i_index, int i_coord_num)\r
-       {\r
-               // vertex1を境界にして、後方に配列を連結\r
-               System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, i_index);\r
-               System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, i_index);\r
-       }\r
-\r
-       private final int[] __detectMarker_mkvertex = new int[5];\r
 \r
        /**\r
         * ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double\r
@@ -89,7 +76,6 @@ public class NyARQrCodeDetector implements INyARSquareDetector
         */\r
        public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException\r
        {\r
-               final NyARLabeling_ARToolKit labeling_proc = this._labeling;\r
                final NyARLabelingImage limage = this._limage;\r
 \r
                // 初期化\r
@@ -98,7 +84,7 @@ public class NyARQrCodeDetector implements INyARSquareDetector
                o_square_stack.clear();\r
 \r
                // ラベリング\r
-               labeling_proc.labeling(i_raster);\r
+               this._labeling.labeling(i_raster,limage);\r
 \r
                // ラベル数が0ならここまで\r
                final int label_num = limage.getLabelStack().getLength();\r
@@ -126,10 +112,9 @@ public class NyARQrCodeDetector implements INyARSquareDetector
                final int[] xcoord = this._xcoord;\r
                final int[] ycoord = this._ycoord;\r
                final int coord_max = this._max_coord;\r
-               final int[] mkvertex = this.__detectMarker_mkvertex;\r
                final int[] buf = (int[]) limage.getBufferReader().getBuffer();\r
                final int[] indextable = limage.getIndexArray();\r
-               int coord_num;\r
+\r
                int label_area;\r
                NyARLabelingLabel label_pt;\r
                NyARSquareStack wk_stack=new NyARSquareStack(10);\r
@@ -153,28 +138,20 @@ public class NyARQrCodeDetector implements INyARSquareDetector
                        if (!hasQrEdgeFeature(buf, indextable, label_pt)) {\r
                                continue;\r
                        }\r
-\r
                        // 輪郭を取得\r
-                       coord_num = limage.getContour(i, coord_max, xcoord, ycoord);\r
+                       final int coord_num = _cpickup.getContour(limage,limage.getTopClipTangentX(label_pt),label_pt.clip_t, coord_max, xcoord, ycoord);\r
                        if (coord_num == coord_max) {\r
                                // 輪郭が大きすぎる。\r
                                continue;\r
                        }\r
-                       // 頂点候補のインデクスを取得\r
-                       final int vertex1 = scanVertex(xcoord, ycoord, coord_num);\r
-\r
-                       // 頂点候補(vertex1)を先頭に並べなおした配列を作成する。\r
-                       normalizeCoord(xcoord, ycoord, vertex1, coord_num);\r
-\r
-                       // 頂点情報を取得\r
-                       if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex)) {\r
-                               continue;\r
-                       }\r
-                       NyARSquare square=(NyARSquare)wk_stack.prePush();\r
-                       //矩形からラインと観察座標を取得\r
-                       if(!getSquareLine(mkvertex,xcoord,ycoord,square.line,square.imvertex)){\r
-                               wk_stack.pop();\r
-                               continue;\r
+                       //輪郭分析用に正規化する。\r
+                       final int vertex1 = SquareContourDetector.normalizeCoord(xcoord, ycoord, coord_num);\r
+\r
+                       //ここから先が輪郭分析\r
+                       NyARSquare square_ptr = o_square_stack.prePush();\r
+                       if(!this._sqconvertor.coordToSquare(xcoord,ycoord,vertex1,coord_num,label_area,square_ptr)){\r
+                               o_square_stack.pop();// 頂点の取得が出来なかったので破棄\r
+                               continue;                               \r
                        }\r
                }\r
                //シンボルの関連付け\r
@@ -215,173 +192,8 @@ public class NyARQrCodeDetector implements INyARSquareDetector
                return;\r
        }\r
        private static int MAX_COORD_NUM=(320+240)*2;//サイズの1/2の長方形の編程度が目安(VGAなら(320+240)*2)\r
-       private final INyARPca2d _pca=new NyARPca2d_MatrixPCA_O2();\r
-       private final NyARDoubleMatrix22 __getSquareLine_evec=new NyARDoubleMatrix22();\r
-       private final NyARDoublePoint2d __getSquareLine_mean=new NyARDoublePoint2d();\r
-       private final NyARDoublePoint2d __getSquareLine_ev=new NyARDoublePoint2d();\r
-       /**\r
-        * 頂点インデクスと輪郭配列から、Ideal座標系とLineを作成して変数に返す\r
-        * @param i_cparam\r
-        * @return\r
-        * @throws NyARException\r
-        */\r
-       private boolean getSquareLine(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARLinear[] o_line,NyARIntPoint2d[] o_imvertex) throws NyARException\r
-       {\r
-               final NyARDoubleMatrix22 evec=this.__getSquareLine_evec;\r
-               final NyARDoublePoint2d mean=this.__getSquareLine_mean;\r
-               final NyARDoublePoint2d ev=this.__getSquareLine_ev;\r
-       \r
-               \r
-               for (int i = 0; i < 4; i++) {\r
-                       final double w1 = (double) (i_mkvertex[i + 1] - i_mkvertex[i] + 1) * 0.05 + 0.5;\r
-                       final int st = (int) (i_mkvertex[i] + w1);\r
-                       final int ed = (int) (i_mkvertex[i + 1] - w1);\r
-                       final int n = ed - st + 1;\r
-                       if (n < 2 || n>MAX_COORD_NUM) {\r
-                               // nが2以下、又はMAX_COORD_NUM以上なら主成分分析をしない。\r
-                               return false;\r
-                       }\r
-                       //配列作成\r
-                       this._dist_factor_ref.observ2IdealBatch(i_xcoord, i_ycoord, st, n,this._xpos,this._ypos);\r
-                       \r
-                       //主成分分析する。\r
-                       this._pca.pca(this._xpos,this._ypos,n,evec, ev,mean);\r
-                       final NyARLinear l_line_i = o_line[i];\r
-                       l_line_i.run = evec.m01;// line[i][0] = evec->m[1];\r
-                       l_line_i.rise = -evec.m00;// line[i][1] = -evec->m[0];\r
-                       l_line_i.intercept = -(l_line_i.run * mean.x + l_line_i.rise * mean.y);// line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);\r
-               }\r
-               for (int i = 0; i < 4; i++) {\r
-                       final NyARLinear l_line_i = o_line[i];\r
-                       final NyARLinear l_line_2 = o_line[(i + 3) % 4];\r
-                       final double w1 = l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise;\r
-                       if (w1 == 0.0) {\r
-                               return false;\r
-                       }\r
-                       // 頂点インデクスから頂点座標を得て保存\r
-                       o_imvertex[i].x = i_xcoord[i_mkvertex[i]];\r
-                       o_imvertex[i].y = i_ycoord[i_mkvertex[i]];\r
-               }\r
-               return true;\r
-       }\r
-       /**\r
-        * 辺からの対角線が最長になる点を対角線候補として返す。\r
-        * \r
-        * @param i_xcoord\r
-        * @param i_ycoord\r
-        * @param i_coord_num\r
-        * @return\r
-        */\r
-       private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)\r
-       {\r
-               final int sx = i_xcoord[0];\r
-               final int sy = i_ycoord[0];\r
-               int d = 0;\r
-               int w, x, y;\r
-               int ret = 0;\r
-               for (int i = 1; i < i_coord_num; i++) {\r
-                       x = i_xcoord[i] - sx;\r
-                       y = i_ycoord[i] - sy;\r
-                       w = x * x + y * y;\r
-                       if (w > d) {\r
-                               d = w;\r
-                               ret = i;\r
-                       }\r
-                       // ここでうまく終了条件入れられないかな。\r
-               }\r
-               return ret;\r
-       }\r
-\r
-       private final NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();\r
-       private final NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();\r
 \r
        /**\r
-        * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。\r
-        * \r
-        * @param i_x_coord\r
-        * @param i_y_coord\r
-        * @param i_vertex1_index\r
-        * @param i_coord_num\r
-        * @param i_area\r
-        * @param o_vertex\r
-        * 要素数はint[4]である事\r
-        * @return\r
-        */\r
-       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)\r
-       {\r
-               final NyARVertexCounter wv1 = this.__getSquareVertex_wv1;\r
-               final NyARVertexCounter wv2 = this.__getSquareVertex_wv2;\r
-               final int end_of_coord = i_vertex1_index + i_coord_num - 1;\r
-               final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];\r
-               final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];\r
-               int dmax = 0;\r
-               int v1 = i_vertex1_index;\r
-               for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)\r
-                       // {\r
-                       final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);\r
-                       if (d > dmax) {\r
-                               dmax = d;\r
-                               v1 = i;\r
-                       }\r
-               }\r
-               final double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;\r
-\r
-               o_vertex[0] = i_vertex1_index;\r
-\r
-               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)<\r
-                       // 0 ) {\r
-                       return false;\r
-               }\r
-               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)\r
-                       // < 0) {\r
-                       return false;\r
-               }\r
-\r
-               int v2;\r
-               if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {\r
-                       o_vertex[1] = wv1.vertex[0];\r
-                       o_vertex[2] = v1;\r
-                       o_vertex[3] = wv2.vertex[0];\r
-               } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {\r
-                       // 頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。\r
-                       v2 = (v1 - i_vertex1_index) / 2 + i_vertex1_index;\r
-                       if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh)) {\r
-                               return false;\r
-                       }\r
-                       if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh)) {\r
-                               return false;\r
-                       }\r
-                       if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
-                               o_vertex[1] = wv1.vertex[0];\r
-                               o_vertex[2] = wv2.vertex[0];\r
-                               o_vertex[3] = v1;\r
-                       } else {\r
-                               return false;\r
-                       }\r
-               } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {\r
-                       // v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;\r
-                       v2 = (v1 + end_of_coord) / 2;\r
-\r
-                       if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh)) {\r
-                               return false;\r
-                       }\r
-                       if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh)) {\r
-                               return false;\r
-                       }\r
-                       if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
-                               o_vertex[1] = v1;\r
-                               o_vertex[2] = wv1.vertex[0];\r
-                               o_vertex[3] = wv2.vertex[0];\r
-                       } else {\r
-                               return false;\r
-                       }\r
-               } else {\r
-                       return false;\r
-               }\r
-               o_vertex[4] = end_of_coord;\r
-               return true;\r
-       }\r
-       /**\r
         * QRコードのシンボル特徴を持つラベルであるかを調べる\r
         * @param buf\r
         * @param index_table\r
index 168dbf1..4916760 100644 (file)
@@ -12,11 +12,9 @@ import javax.media.format.*;
 import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.jmf.utils.*;
 
-import jp.nyatla.nyartoolkit.core.*;
 
 import java.awt.*;
 
-import jp.nyatla.nyartoolkit.core.labeling.*;
 import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;
 import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabeling_ARToolKit;
 import jp.nyatla.nyartoolkit.core.param.*;
@@ -100,8 +98,7 @@ public class SingleQrTest extends Frame implements JmfCaptureListener
                        // 画像3
                        NyARLabelingImage limage = new NyARLabelingImage(320, 240);
                        NyARLabeling_ARToolKit labeling = new NyARLabeling_ARToolKit();
-                       labeling.attachDestination(limage);
-                       labeling.labeling(_binraster1);
+                       labeling.labeling(_binraster1,limage);
                        this._bimg.drawImage(this._gsraster1);
 
                        NyARSquareStack stack = new NyARSquareStack(100);
index 0b11b44..bce9c29 100644 (file)
 package jp.nyatla.nyartoolkit.sandbox.quadx2;\r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.labeling.*;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabelStack;\r
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.*;\r
 import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.ContourPickup;\r
 import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;\r
 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;\r
-import jp.nyatla.nyartoolkit.core.squaredetect.NyARVertexCounter;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.SquareContourDetector;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
 \r
-\r
-import jp.nyatla.nyartoolkit.core2.types.NyARI64Linear;\r
-import jp.nyatla.nyartoolkit.core2.types.NyARI64Point2d;\r
-import jp.nyatla.nyartoolkit.core2.types.matrix.NyARI64Matrix22;\r
-import jp.nyatla.nyartoolkit.core.*;\r
 import jp.nyatla.nyartoolkit.sandbox.x2.*;\r
 \r
 \r
@@ -57,21 +51,19 @@ import jp.nyatla.nyartoolkit.sandbox.x2.*;
  */\r
 public class NyARSquareDetector_Quad implements INyARSquareDetector\r
 {\r
-    private static int PCA_LENGTH = 20;\r
-    private static double VERTEX_FACTOR = 1.0;// 線検出のファクタ\r
-\r
     private static int AR_AREA_MAX = 25000;// #define AR_AREA_MAX 100000\r
 \r
     private static int AR_AREA_MIN = 20;// #define AR_AREA_MIN 70\r
     private int _width;\r
     private int _height;\r
 \r
-    private NyARLabeling_ARToolKit_X2 _labeling;\r
+    private NyARLabeling_ARToolKit _labeling;\r
 \r
     private NyARLabelingImage _limage;\r
 \r
-    private OverlapChecker _overlap_checker = new OverlapChecker();\r
-    private NyARFixedFloatObserv2IdealMap _dist_factor;\r
+       private final LabelOverlapChecker<NyARLabelingLabel> _overlap_checker = new LabelOverlapChecker<NyARLabelingLabel>(32,NyARLabelingLabel.class);\r
+       private final SquareContourDetector _sqconvertor;\r
+       private final ContourPickup _cpickup=new ContourPickup();\r
     /**\r
      * 最大i_squre_max個のマーカーを検出するクラスを作成する。\r
      * \r
@@ -81,9 +73,9 @@ public class NyARSquareDetector_Quad implements INyARSquareDetector
     {\r
         this._width = i_size.w / 2;\r
         this._height = i_size.h / 2;\r
-        this._labeling = new NyARLabeling_ARToolKit_X2();\r
+        this._labeling = new NyARLabeling_ARToolKit();\r
         this._limage = new NyARLabelingImage(this._width, this._height);\r
-        this._labeling.attachDestination(this._limage);\r
+        this._sqconvertor=new SquareContourDetector(i_size,i_dist_factor_ref);        \r
 \r
         // 輪郭の最大長は画面に映りうる最大の長方形サイズ。\r
         int number_of_coord = (this._width + this._height) * 2;\r
@@ -97,27 +89,12 @@ public class NyARSquareDetector_Quad implements INyARSquareDetector
         NyARCameraDistortionFactor quadfactor = new NyARCameraDistortionFactor();\r
         quadfactor.copyFrom(i_dist_factor_ref);\r
         quadfactor.changeScale(0.5);\r
-        this._dist_factor = new NyARFixedFloatObserv2IdealMap(quadfactor, i_size);\r
-        //PCA\r
-        this._pca = new NyARFixedFloatPca2d();\r
-        this._xpos = new int[PCA_LENGTH];//最大辺長はthis._width+this._height\r
-        this._ypos = new int[PCA_LENGTH];//最大辺長はthis._width+this._height\r
-\r
     }\r
 \r
     private int _max_coord;\r
     private int[] _xcoord;\r
     private int[] _ycoord;\r
 \r
-    private void normalizeCoord(int[] i_coord_x, int[] i_coord_y, int i_index, int i_coord_num)\r
-    {\r
-        // vertex1を境界にして、後方に配列を連結\r
-        System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, i_index);\r
-        System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, i_index);\r
-    }\r
-\r
-    private int[] __detectMarker_mkvertex = new int[5];\r
-\r
     /**\r
      * arDetectMarker2を基にした関数\r
      * この関数はNyARSquare要素のうち、directionを除くパラメータを取得して返します。\r
@@ -130,7 +107,6 @@ public class NyARSquareDetector_Quad implements INyARSquareDetector
      */\r
     public void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException\r
     {\r
-       NyARLabeling_ARToolKit_X2 labeling_proc = this._labeling;\r
         NyARLabelingImage limage = this._limage;\r
 \r
         // 初期化\r
@@ -139,7 +115,7 @@ public class NyARSquareDetector_Quad implements INyARSquareDetector
         o_square_stack.clear();\r
 \r
         // ラベリング\r
-        labeling_proc.labeling(i_raster);\r
+        this._labeling.labeling(i_raster,limage);\r
 \r
         // ラベル数が0ならここまで\r
         int label_num = limage.getLabelStack().getLength();\r
@@ -171,14 +147,13 @@ public class NyARSquareDetector_Quad implements INyARSquareDetector
         int[] xcoord = this._xcoord;\r
         int[] ycoord = this._ycoord;\r
         int coord_max = this._max_coord;\r
-        int[] mkvertex = this.__detectMarker_mkvertex;\r
-        OverlapChecker overlap = this._overlap_checker;\r
-        int coord_num;\r
+               final LabelOverlapChecker<NyARLabelingLabel> overlap = this._overlap_checker;\r
+\r
         int label_area;\r
         NyARLabelingLabel label_pt;\r
 \r
         //重なりチェッカの最大数を設定\r
-        overlap.reset(label_num);\r
+        overlap.setMaxLabels(label_num);\r
 \r
         for (; i < label_num; i++)\r
         {\r
@@ -204,316 +179,32 @@ public class NyARSquareDetector_Quad implements INyARSquareDetector
                 // 重なっているようだ。\r
                 continue;\r
             }\r
-\r
-            // 輪郭を取得\r
-            coord_num = limage.getContour(i, coord_max, xcoord, ycoord);\r
-            if (coord_num == coord_max)\r
-            {\r
-                // 輪郭が大きすぎる。\r
-                continue;\r
-            }\r
-            //頂点候補のインデクスを取得\r
-            int vertex1 = scanVertex(xcoord, ycoord, coord_num);\r
-\r
-            // 頂点候補(vertex1)を先頭に並べなおした配列を作成する。\r
-            normalizeCoord(xcoord, ycoord, vertex1, coord_num);\r
-\r
-            // 領域を準備する。\r
-            NyARSquare square_ptr = (NyARSquare)o_square_stack.prePush();\r
-\r
-            // 頂点情報を取得\r
-            if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex))\r
-            {\r
-                o_square_stack.pop();// 頂点の取得が出来なかったので破棄\r
-                continue;\r
-            }\r
-            // マーカーを検出\r
-            if (!getSquareLine(mkvertex, xcoord, ycoord, square_ptr))\r
-            {\r
-                // 矩形が成立しなかった。\r
-                o_square_stack.pop();\r
-                continue;\r
-            }\r
+                       // 既に検出された矩形との重なりを確認\r
+                       if (!overlap.check(label_pt)) {\r
+                               // 重なっているようだ。\r
+                               continue;\r
+                       }\r
+                       // 輪郭を取得\r
+                       final int coord_num = _cpickup.getContour(limage,limage.getTopClipTangentX(label_pt),label_pt.clip_t, coord_max, xcoord, ycoord);\r
+                       if (coord_num == coord_max) {\r
+                               // 輪郭が大きすぎる。\r
+                               continue;\r
+                       }\r
+                       //輪郭分析用に正規化する。\r
+                       final int vertex1 = SquareContourDetector.normalizeCoord(xcoord, ycoord, coord_num);\r
+\r
+                       //ここから先が輪郭分析\r
+                       NyARSquare square_ptr = o_square_stack.prePush();\r
+                       if(!this._sqconvertor.coordToSquare(xcoord,ycoord,vertex1,coord_num,label_area,square_ptr)){\r
+                               o_square_stack.pop();// 頂点の取得が出来なかったので破棄\r
+                               continue;                               \r
+                       }\r
+                                   \r
             // 検出済の矩形の属したラベルを重なりチェックに追加する。\r
             overlap.push(label_pt);\r
         }\r
         return;\r
     }\r
-\r
-    /**\r
-     * 辺からの対角線が最長になる点を対角線候補として返す。\r
-     * \r
-     * @param i_xcoord\r
-     * @param i_ycoord\r
-     * @param i_coord_num\r
-     * @return\r
-     */\r
-    private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)\r
-    {\r
-        int sx = i_xcoord[0];\r
-        int sy = i_ycoord[0];\r
-        int d = 0;\r
-        int w, x, y;\r
-        int ret = 0;\r
-        for (int i = 1; i < i_coord_num; i++)\r
-        {\r
-            x = i_xcoord[i] - sx;\r
-            y = i_ycoord[i] - sy;\r
-            w = x * x + y * y;\r
-            if (w > d)\r
-            {\r
-                d = w;\r
-                ret = i;\r
-            }\r
-            // ここでうまく終了条件入れられないかな。\r
-        }\r
-        return ret;\r
-    }\r
-\r
-    private NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();\r
-\r
-    private NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();\r
-\r
-    /**\r
-     * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。\r
-     * \r
-     * @param i_x_coord\r
-     * @param i_y_coord\r
-     * @param i_vertex1_index\r
-     * @param i_coord_num\r
-     * @param i_area\r
-     * @param o_vertex\r
-     * 要素数はint[4]である事\r
-     * @return\r
-     */\r
-    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)\r
-    {\r
-        NyARVertexCounter wv1 = this.__getSquareVertex_wv1;\r
-        NyARVertexCounter wv2 = this.__getSquareVertex_wv2;\r
-        int end_of_coord = i_vertex1_index + i_coord_num - 1;\r
-        int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];\r
-        int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];\r
-        int dmax = 0;\r
-        int v1 = i_vertex1_index;\r
-        for (int i = 1 + i_vertex1_index; i < end_of_coord; i++)\r
-        {// for(i=1;i<marker_info2->coord_num-1;i++)\r
-            // {\r
-            int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);\r
-            if (d > dmax)\r
-            {\r
-                dmax = d;\r
-                v1 = i;\r
-            }\r
-        }\r
-        double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;\r
-\r
-        o_vertex[0] = i_vertex1_index;\r
-\r
-        if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh))\r
-        { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<\r
-            // 0 ) {\r
-            return false;\r
-        }\r
-        if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh))\r
-        {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)\r
-            // < 0) {\r
-            return false;\r
-        }\r
-\r
-        int v2;\r
-        if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)\r
-        {// if(wvnum1 == 1 && wvnum2== 1) {\r
-            o_vertex[1] = wv1.vertex[0];\r
-            o_vertex[2] = v1;\r
-            o_vertex[3] = wv2.vertex[0];\r
-        }\r
-        else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0)\r
-        {// }else if( wvnum1 > 1 && wvnum2== 0) {\r
-            //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。\r
-            v2 = (v1 - i_vertex1_index) / 2 + i_vertex1_index;\r
-            if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh))\r
-            {\r
-                return false;\r
-            }\r
-            if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh))\r
-            {\r
-                return false;\r
-            }\r
-            if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)\r
-            {\r
-                o_vertex[1] = wv1.vertex[0];\r
-                o_vertex[2] = wv2.vertex[0];\r
-                o_vertex[3] = v1;\r
-            }\r
-            else\r
-            {\r
-                return false;\r
-            }\r
-        }\r
-        else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1)\r
-        {\r
-            //v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;\r
-            v2 = (v1 + end_of_coord) / 2;\r
-\r
-            if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh))\r
-            {\r
-                return false;\r
-            }\r
-            if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh))\r
-            {\r
-                return false;\r
-            }\r
-            if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1)\r
-            {\r
-                o_vertex[1] = v1;\r
-                o_vertex[2] = wv1.vertex[0];\r
-                o_vertex[3] = wv2.vertex[0];\r
-            }\r
-            else\r
-            {\r
-                return false;\r
-            }\r
-        }\r
-        else\r
-        {\r
-            return false;\r
-        }\r
-        o_vertex[4] = end_of_coord;\r
-        return true;\r
-    }\r
-    private int[] _xpos;\r
-    private int[] _ypos;\r
-    private NyARFixedFloatPca2d _pca;\r
-    private NyARI64Matrix22 __getSquareLine_evec = new NyARI64Matrix22();\r
-    private NyARI64Point2d __getSquareLine_mean = new NyARI64Point2d();\r
-    private NyARI64Point2d __getSquareLine_ev = new NyARI64Point2d();\r
-    private NyARI64Linear[] __getSquareLine_i64liner = NyARI64Linear.createArray(4);\r
-    /**\r
-     * arGetLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2]) arGetLine2(int x_coord[], int y_coord[], int\r
-     * coord_num,int vertex[], double line[4][3], double v[4][2], double *dist_factor) の2関数の合成品です。 マーカーのvertex,lineを計算して、結果をo_squareに保管します。\r
-     * Optimize:STEP[424->391]\r
-     * \r
-     * @param i_cparam\r
-     * @return\r
-     * @throws NyARException\r
-     */\r
-    private boolean getSquareLine(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARSquare o_square) throws NyARException\r
-    {\r
-        NyARLinear[] l_line = o_square.line;\r
-        NyARI64Matrix22 evec = this.__getSquareLine_evec;\r
-        NyARI64Point2d mean = this.__getSquareLine_mean;\r
-        NyARI64Point2d ev = this.__getSquareLine_ev;\r
-        NyARI64Linear[] i64liner = this.__getSquareLine_i64liner;\r
-\r
-\r
-        for (int i = 0; i < 4; i++)\r
-        {\r
-            double w1 = (double)(i_mkvertex[i + 1] - i_mkvertex[i] + 1) * 0.05 + 0.5;\r
-            int st = (int)(i_mkvertex[i] + w1);\r
-            int ed = (int)(i_mkvertex[i + 1] - w1);\r
-            int n = ed - st + 1;\r
-            if (n < 2)\r
-            {\r
-                // nが2以下でmatrix.PCAを計算することはできないので、エラー\r
-                return false;\r
-            }\r
-            //配列作成\r
-            n = this._dist_factor.observ2IdealSampling(i_xcoord, i_ycoord, st, n, this._xpos, this._ypos, PCA_LENGTH);\r
-\r
-            //主成分分析する。\r
-            this._pca.pcaF16(this._xpos, this._ypos, n, evec, ev, mean);\r
-            NyARI64Linear l_line_i = i64liner[i];\r
-            l_line_i.run = evec.m01;// line[i][0] = evec->m[1];\r
-            l_line_i.rise = -evec.m00;// line[i][1] = -evec->m[0];\r
-            l_line_i.intercept = -((l_line_i.run * mean.x + l_line_i.rise * mean.y) >> 16);// line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);\r
-        }\r
-\r
-        NyARDoublePoint2d[] l_sqvertex = o_square.sqvertex;\r
-        NyARIntPoint2d[] l_imvertex = o_square.imvertex;\r
-        for (int i = 0; i < 4; i++)\r
-        {\r
-            NyARI64Linear l_line_i = i64liner[i];\r
-            NyARI64Linear l_line_2 = i64liner[(i + 3) % 4];\r
-            long w1 = (l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise) >> 16;\r
-            if (w1 == 0)\r
-            {\r
-                return false;\r
-            }\r
-            l_sqvertex[i].x = (double)((l_line_2.rise * l_line_i.intercept - l_line_i.rise * l_line_2.intercept) / w1) *2/ 65536.0;\r
-            l_sqvertex[i].y = (double)((l_line_i.run * l_line_2.intercept - l_line_2.run * l_line_i.intercept) / w1) *2/ 65536.0;\r
-            // 頂点インデクスから頂点座標を得て保存\r
-            l_imvertex[i].x = i_xcoord[i_mkvertex[i]]*2;\r
-            l_imvertex[i].y = i_ycoord[i_mkvertex[i]]*2;\r
-            l_line[i].run = (double)l_line_i.run / 65536.0;\r
-            l_line[i].rise = (double)l_line_i.rise / 65536.0;\r
-            l_line[i].intercept = (double)l_line_i.intercept*2 / 65536.0;\r
-        }\r
-        return true;\r
-    }\r
-}\r
-\r
-\r
-/**\r
- * ラベル同士の重なり(内包関係)を調べるクラスです。 \r
- * ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。\r
- */\r
-class OverlapChecker\r
-{\r
-    private NyARLabelingLabel[] _labels = new NyARLabelingLabel[32];\r
-\r
-    private int _length;\r
-\r
-    /**\r
-     * 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする\r
-     * \r
-     * @param i_max_label\r
-     */\r
-    public void reset(int i_max_label)\r
-    {\r
-        if (i_max_label > this._labels.length)\r
-        {\r
-            this._labels = new NyARLabelingLabel[i_max_label];\r
-        }\r
-        this._length = 0;\r
-    }\r
-\r
-    /**\r
-     * チェック対象のラベルを追加する。\r
-     * \r
-     * @param i_label_ref\r
-     */\r
-    public void push(NyARLabelingLabel i_label_ref)\r
-    {\r
-        this._labels[this._length] = i_label_ref;\r
-        this._length++;\r
-    }\r
-\r
-    /**\r
-     * 現在リストにあるラベルと重なっているかを返す。\r
-     * \r
-     * @param i_label\r
-     * @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.\r
-     */\r
-    public boolean check(NyARLabelingLabel i_label)\r
-    {\r
-        // 重なり処理かな?\r
-        NyARLabelingLabel[] label_pt = this._labels;\r
-        int px1 = (int)i_label.pos_x;\r
-        int py1 = (int)i_label.pos_y;\r
-        for (int i = this._length - 1; i >= 0; i--)\r
-        {\r
-            int px2 = (int)label_pt[i].pos_x;\r
-            int py2 = (int)label_pt[i].pos_y;\r
-            int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);\r
-            if (d < label_pt[i].area / 4)\r
-            {\r
-                // 対象外\r
-                return false;\r
-            }\r
-        }\r
-        // 対象\r
-        return true;\r
-    }\r
 }\r
 \r
 \r
index 47e31c9..c2f03ba 100644 (file)
 package jp.nyatla.nyartoolkit.sandbox.vertexdetect;\r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.labeling.*;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabelStack;\r
+import jp.nyatla.nyartoolkit.core.labeling.artoolkit.*;\r
 import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;\r
-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.*;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 import jp.nyatla.nyartoolkit.core.param.*;\r
-import jp.nyatla.nyartoolkit.core.*;\r
-import jp.nyatla.nyartoolkit.sandbox.x2.*;\r
 /**\r
  * PCAではなく、頂点座標そのものからSquare位置を計算するクラス\r
  *\r
  */\r
 public class NyARVertexDetector implements INyARSquareDetector\r
 {\r
-       private static final double VERTEX_FACTOR = 1.0;// 線検出のファクタ\r
-\r
        private static final int AR_AREA_MAX = 100000;// #define AR_AREA_MAX 100000\r
 \r
        private static final int AR_AREA_MIN = 70;// #define AR_AREA_MIN 70\r
        private final int _width;\r
        private final int _height;\r
 \r
-       private final NyARLabeling_ARToolKit_X2 _labeling;\r
+       private final NyARLabeling_ARToolKit _labeling;\r
 \r
        private final NyARLabelingImage _limage;\r
 \r
-       private final OverlapChecker _overlap_checker = new OverlapChecker();\r
-       private final NyARObserv2IdealMap _dist_factor_ref;\r
+       private final LabelOverlapChecker<NyARLabelingLabel> _overlap_checker = new LabelOverlapChecker<NyARLabelingLabel>(32,NyARLabelingLabel.class);\r
+       private final SquareContourDetector _sqconvertor;\r
+       private final ContourPickup _cpickup=new ContourPickup();\r
 \r
        /**\r
         * 最大i_squre_max個のマーカーを検出するクラスを作成する。\r
         * \r
         * @param i_param\r
         */\r
-       public NyARVertexDetector(NyARObserv2IdealMap i_dist_factor_ref,NyARIntSize i_size) throws NyARException\r
+       public NyARVertexDetector(NyARCameraDistortionFactor i_dist_factor_ref,NyARIntSize i_size) throws NyARException\r
        {\r
                this._width = i_size.w;\r
                this._height = i_size.h;\r
-               this._dist_factor_ref = i_dist_factor_ref;\r
-               this._labeling = new NyARLabeling_ARToolKit_X2();\r
+               this._labeling = new NyARLabeling_ARToolKit();\r
                this._limage = new NyARLabelingImage(this._width, this._height);\r
-               this._labeling.attachDestination(this._limage);\r
+        this._sqconvertor=new SquareContourDetector(i_size,i_dist_factor_ref);        \r
 \r
                // 輪郭の最大長は画面に映りうる最大の長方形サイズ。\r
                int number_of_coord = (this._width + this._height) * 2;\r
@@ -91,15 +83,6 @@ public class NyARVertexDetector implements INyARSquareDetector
        private final int[] _xcoord;\r
        private final int[] _ycoord;\r
 \r
-       private void normalizeCoord(int[] i_coord_x, int[] i_coord_y, int i_index, int i_coord_num)\r
-       {\r
-               // vertex1を境界にして、後方に配列を連結\r
-               System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, i_index);\r
-               System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, i_index);\r
-       }\r
-\r
-       private final int[] __detectMarker_mkvertex = new int[5];\r
-\r
        /**\r
         * ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double\r
         * factor, int *marker_num ) 関数の代替品 ラベリング情報からマーカー一覧を作成してo_marker_listを更新します。 関数はo_marker_listに重なりを除外したマーカーリストを作成します。\r
@@ -112,7 +95,6 @@ public class NyARVertexDetector implements INyARSquareDetector
         */\r
        public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException\r
        {\r
-               final NyARLabeling_ARToolKit_X2 labeling_proc = this._labeling;\r
                final NyARLabelingImage limage = this._limage;\r
 \r
                // 初期化\r
@@ -121,7 +103,7 @@ public class NyARVertexDetector implements INyARSquareDetector
                o_square_stack.clear();\r
 \r
                // ラベリング\r
-               labeling_proc.labeling(i_raster);\r
+               this._labeling.labeling(i_raster,this._limage);\r
 \r
                // ラベル数が0ならここまで\r
                final int label_num = limage.getLabelStack().getLength();\r
@@ -150,14 +132,12 @@ public class NyARVertexDetector implements INyARSquareDetector
                final int[] xcoord = this._xcoord;\r
                final int[] ycoord = this._ycoord;\r
                final int coord_max = this._max_coord;\r
-               final int[] mkvertex = this.__detectMarker_mkvertex;\r
-               final OverlapChecker overlap = this._overlap_checker;\r
-               int coord_num;\r
+               final LabelOverlapChecker<NyARLabelingLabel> overlap = this._overlap_checker;\r
                int label_area;\r
                NyARLabelingLabel label_pt;\r
 \r
                //重なりチェッカの最大数を設定\r
-               overlap.reset(label_num);\r
+               overlap.setMaxLabels(label_num);\r
 \r
                for (; i < label_num; i++) {\r
                        label_pt = labels[i];\r
@@ -178,333 +158,25 @@ public class NyARVertexDetector implements INyARSquareDetector
                                // 重なっているようだ。\r
                                continue;\r
                        }\r
-\r
                        // 輪郭を取得\r
-                       coord_num = limage.getContour(i, coord_max, xcoord, ycoord);\r
+                       final int coord_num = _cpickup.getContour(limage,limage.getTopClipTangentX(label_pt),label_pt.clip_t, coord_max, xcoord, ycoord);\r
                        if (coord_num == coord_max) {\r
                                // 輪郭が大きすぎる。\r
                                continue;\r
                        }\r
-                       //頂点候補のインデクスを取得\r
-                       final int vertex1 = scanVertex(xcoord, ycoord, coord_num);\r
-\r
-                       // 頂点候補(vertex1)を先頭に並べなおした配列を作成する。\r
-                       normalizeCoord(xcoord, ycoord, vertex1, coord_num);\r
+                       //輪郭分析用に正規化する。\r
+                       final int vertex1 = SquareContourDetector.normalizeCoord(xcoord, ycoord, coord_num);\r
 \r
-                       // 領域を準備する。\r
-                       NyARSquare square_ptr = (NyARSquare)o_square_stack.prePush();\r
-\r
-                       // 頂点情報を取得\r
-                       if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex)) {\r
+                       //ここから先が輪郭分析\r
+                       NyARSquare square_ptr = o_square_stack.prePush();\r
+                       if(!this._sqconvertor.coordToSquare(xcoord,ycoord,vertex1,coord_num,label_area,square_ptr)){\r
                                o_square_stack.pop();// 頂点の取得が出来なかったので破棄\r
-                               continue;\r
+                               continue;                               \r
                        }\r
-                       //頂点情報からライン情報を作っちゃう\r
-                       getSquare(mkvertex, xcoord, ycoord, square_ptr);\r
-                       \r
                        // 検出済の矩形の属したラベルを重なりチェックに追加する。\r
                        overlap.push(label_pt);\r
                }       \r
                return;\r
        }\r
-       /**\r
-        * 2つの頂点座標を結ぶ直線から、NyARLinearを計算する。\r
-        * @param i_v1\r
-        * @param i_v2\r
-        * @param o_line\r
-        */\r
-       final private void getLine(NyARDoublePoint2d i_v1,NyARDoublePoint2d i_v2,NyARLinear o_line)\r
-       {\r
-               final double x=i_v1.x-i_v2.x;\r
-               final double y=i_v1.y-i_v2.y;\r
-               final double x2=x*x;\r
-               final double y2=y*y;\r
-               final double rise_=Math.sqrt(x2/(x2+y2));\r
-               o_line.rise=rise_;\r
-               o_line.run=Math.sqrt(y2/(x2+y2));\r
-               if(x<0){\r
-                       if(y<0){\r
-                               o_line.rise=-o_line.rise;\r
-                       }else{\r
-                               o_line.rise=-o_line.rise;\r
-                               o_line.run=-o_line.run;\r
-                       }\r
-               }else{\r
-                       if(y<0){\r
-                               o_line.rise=-o_line.rise;\r
-                               o_line.run=-o_line.run;\r
-                       }else{\r
-                               o_line.rise=-o_line.rise;\r
-                       }                       \r
-               }\r
-               o_line.intercept=(i_v1.y+(o_line.run/o_line.rise)*(i_v1.x))*rise_;\r
-               \r
-       }\r
-\r
-       private void getSquare(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARSquare o_square)\r
-       {\r
-               final NyARObserv2IdealMap dist_factor=this._dist_factor_ref;            \r
-               final NyARDoublePoint2d[] vertex=o_square.sqvertex;\r
-               //歪み補正\r
-               for(int i=0;i<4;i++)\r
-               {\r
-                       final int idx=i_mkvertex[i];\r
-                       o_square.imvertex[i].x=i_xcoord[idx];\r
-               o_square.imvertex[i].y=i_ycoord[idx];\r
-                       dist_factor.observ2Ideal(i_xcoord[idx], i_ycoord[idx],vertex[i]);\r
-               }\r
-               //ライン計算\r
-               getLine(vertex[1],vertex[0],o_square.line[0]);\r
-               getLine(vertex[2],vertex[1],o_square.line[1]);\r
-               getLine(vertex[3],vertex[2],o_square.line[2]);\r
-               getLine(vertex[0],vertex[3],o_square.line[3]);  \r
-               return;\r
-       }\r
-\r
-       /**\r
-        * 辺からの対角線が最長になる点を対角線候補として返す。\r
-        * \r
-        * @param i_xcoord\r
-        * @param i_ycoord\r
-        * @param i_coord_num\r
-        * @return\r
-        */\r
-       private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)\r
-       {\r
-               final int sx = i_xcoord[0];\r
-               final int sy = i_ycoord[0];\r
-               int d = 0;\r
-               int w, x, y;\r
-               int ret = 0;\r
-               for (int i = 1; i < i_coord_num; i++) {\r
-                       x = i_xcoord[i] - sx;\r
-                       y = i_ycoord[i] - sy;\r
-                       w = x * x + y * y;\r
-                       if (w > d) {\r
-                               d = w;\r
-                               ret = i;\r
-                       }\r
-                       // ここでうまく終了条件入れられないかな。\r
-               }\r
-               return ret;\r
-       }\r
-\r
-       private final NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();\r
-\r
-       private final NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();\r
-\r
-       /**\r
-        * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。\r
-        * \r
-        * @param i_x_coord\r
-        * @param i_y_coord\r
-        * @param i_vertex1_index\r
-        * @param i_coord_num\r
-        * @param i_area\r
-        * @param o_vertex\r
-        * 要素数はint[4]である事\r
-        * @return\r
-        */\r
-       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)\r
-       {\r
-               final NyARVertexCounter wv1 = this.__getSquareVertex_wv1;\r
-               final NyARVertexCounter wv2 = this.__getSquareVertex_wv2;\r
-               final int end_of_coord = i_vertex1_index + i_coord_num - 1;\r
-               final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];\r
-               final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];\r
-               int dmax = 0;\r
-               int v1 = i_vertex1_index;\r
-               for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)\r
-                       // {\r
-                       final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);\r
-                       if (d > dmax) {\r
-                               dmax = d;\r
-                               v1 = i;\r
-                       }\r
-               }\r
-               final double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;\r
-\r
-               o_vertex[0] = i_vertex1_index;\r
-\r
-               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)<\r
-                                                                                                                                                                       // 0 ) {\r
-                       return false;\r
-               }\r
-               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)\r
-                       // < 0) {\r
-                       return false;\r
-               }\r
-\r
-               int v2;\r
-               if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {\r
-                       o_vertex[1] = wv1.vertex[0];\r
-                       o_vertex[2] = v1;\r
-                       o_vertex[3] = wv2.vertex[0];\r
-               } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {\r
-                       //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。\r
-                       v2 = (v1-i_vertex1_index)/2+i_vertex1_index;\r
-                       if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh)) {\r
-                               return false;\r
-                       }\r
-                       if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh)) {\r
-                               return false;\r
-                       }\r
-                       if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
-                               o_vertex[1] = wv1.vertex[0];\r
-                               o_vertex[2] = wv2.vertex[0];\r
-                               o_vertex[3] = v1;\r
-                       } else {\r
-                               return false;\r
-                       }\r
-               } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {\r
-                       //v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;\r
-                       v2 = (v1+ end_of_coord)/2;\r
-\r
-                       if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh)) {\r
-                               return false;\r
-                       }\r
-                       if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh)) {\r
-                               return false;\r
-                       }\r
-                       if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
-                               o_vertex[1] = v1;\r
-                               o_vertex[2] = wv1.vertex[0];\r
-                               o_vertex[3] = wv2.vertex[0];\r
-                       } else {\r
-                               return false;\r
-                       }\r
-               } else {\r
-                       return false;\r
-               }\r
-               o_vertex[4] = end_of_coord;\r
-               return true;\r
-       }\r
-}\r
-\r
-/**\r
- * get_vertex関数を切り離すためのクラス\r
- * \r
- */\r
-final class NyARVertexCounter\r
-{\r
-       public final int[] vertex = new int[10];// 5まで削れる\r
-\r
-       public int number_of_vertex;\r
-\r
-       private double thresh;\r
-\r
-       private int[] x_coord;\r
-\r
-       private int[] y_coord;\r
-\r
-       public boolean getVertex(int[] i_x_coord, int[] i_y_coord, int st, int ed, double i_thresh)\r
-       {\r
-               this.number_of_vertex = 0;\r
-               this.thresh = i_thresh;\r
-               this.x_coord = i_x_coord;\r
-               this.y_coord = i_y_coord;\r
-               return get_vertex(st, ed);\r
-       }\r
-\r
-       /**\r
-        * static int get_vertex( int x_coord[], int y_coord[], int st, int ed,double thresh, int vertex[], int *vnum) 関数の代替関数\r
-        * \r
-        * @param x_coord\r
-        * @param y_coord\r
-        * @param st\r
-        * @param ed\r
-        * @param thresh\r
-        * @return\r
-        */\r
-       private boolean get_vertex(int st, int ed)\r
-       {\r
-               int v1 = 0;\r
-               final int[] lx_coord = this.x_coord;\r
-               final int[] ly_coord = this.y_coord;\r
-               final double a = ly_coord[ed] - ly_coord[st];\r
-               final double b = lx_coord[st] - lx_coord[ed];\r
-               final double c = lx_coord[ed] * ly_coord[st] - ly_coord[ed] * lx_coord[st];\r
-               double dmax = 0;\r
-               for (int i = st + 1; i < ed; i++) {\r
-                       final double d = a * lx_coord[i] + b * ly_coord[i] + c;\r
-                       if (d * d > dmax) {\r
-                               dmax = d * d;\r
-                               v1 = i;\r
-                       }\r
-               }\r
-               if (dmax / (a * a + b * b) > thresh) {\r
-                       if (!get_vertex(st, v1)) {\r
-                               return false;\r
-                       }\r
-                       if (number_of_vertex > 5) {\r
-                               return false;\r
-                       }\r
-                       vertex[number_of_vertex] = v1;// vertex[(*vnum)] = v1;\r
-                       number_of_vertex++;// (*vnum)++;\r
-\r
-                       if (!get_vertex(v1, ed)) {\r
-                               return false;\r
-                       }\r
-               }\r
-               return true;\r
-       }\r
-}\r
 \r
-/**\r
- * ラベル同士の重なり(内包関係)を調べるクラスです。 ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。\r
- */\r
-class OverlapChecker\r
-{\r
-       private NyARLabelingLabel[] _labels = new NyARLabelingLabel[32];\r
-\r
-       private int _length;\r
-\r
-       /**\r
-        * 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする\r
-        * \r
-        * @param i_max_label\r
-        */\r
-       public void reset(int i_max_label)\r
-       {\r
-               if (i_max_label > this._labels.length) {\r
-                       this._labels = new NyARLabelingLabel[i_max_label];\r
-               }\r
-               this._length = 0;\r
-       }\r
-\r
-       /**\r
-        * チェック対象のラベルを追加する。\r
-        * \r
-        * @param i_label_ref\r
-        */\r
-       public void push(NyARLabelingLabel i_label_ref)\r
-       {\r
-               this._labels[this._length] = i_label_ref;\r
-               this._length++;\r
-       }\r
-\r
-       /**\r
-        * 現在リストにあるラベルと重なっているかを返す。\r
-        * \r
-        * @param i_label\r
-        * @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.\r
-        */\r
-       public boolean check(NyARLabelingLabel i_label)\r
-       {\r
-               // 重なり処理かな?\r
-               final NyARLabelingLabel[] label_pt = this._labels;\r
-               final int px1 = (int) i_label.pos_x;\r
-               final int py1 = (int) i_label.pos_y;\r
-               for (int i = this._length - 1; i >= 0; i--) {\r
-                       final int px2 = (int) label_pt[i].pos_x;\r
-                       final int py2 = (int) label_pt[i].pos_y;\r
-                       final int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);\r
-                       if (d < label_pt[i].area / 4) {\r
-                               // 対象外\r
-                               return false;\r
-                       }\r
-               }\r
-               // 対象\r
-               return true;\r
-       }\r
 }
\ No newline at end of file
index c984d46..5b50208 100644 (file)
@@ -157,13 +157,13 @@ public class JavaSimpleLite_X2 implements GLEventListener, JmfCaptureListener
                        NyARCode ar_code = new NyARCode(16, 16);\r
                        _ar_param.loadARParamFromFile(PARAM_FILE);\r
                        _ar_param.changeScreenSize(SCREEN_X, SCREEN_Y);\r
-                       _nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。\r
                        ar_code.loadARPattFromFile(CARCODE_FILE);\r
                        //NyARToolkit用の支援クラス\r
                        _glnya = new NyARGLUtil(_gl);\r
                        //GL対応のRGBラスタオブジェクト\r
                        _cap_image = new GLNyARRaster_RGB(_ar_param,_capture.getCaptureFormat());\r
                        _nya = new NyARSingleDetectMarker_X2(_ar_param, ar_code, 80.0,this._cap_image.getBufferReader().getBufferType());\r
+                       _nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。\r
                        //キャプチャ開始\r
                        _capture.start();\r
                } catch (Exception e) {\r
diff --git a/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java b/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java
deleted file mode 100644 (file)
index dc7e614..0000000
+++ /dev/null
@@ -1,387 +0,0 @@
-/* \r
- * PROJECT: NyARToolkit\r
- * --------------------------------------------------------------------------------\r
- * This work is based on the original ARToolKit developed by\r
- *   Hirokazu Kato\r
- *   Mark Billinghurst\r
- *   HITLab, University of Washington, Seattle\r
- * http://www.hitl.washington.edu/artoolkit/\r
- *\r
- * The NyARToolkit is Java version ARToolkit class library.\r
- * Copyright (C)2008 R.Iizuka\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU General Public License\r
- * along with this framework; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- * \r
- * For further information please contact.\r
- *     http://nyatla.jp/nyatoolkit/\r
- *     <airmail(at)ebony.plala.or.jp>\r
- * \r
- */\r
-package jp.nyatla.nyartoolkit.sandbox.x2;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.types.*;\r
-import jp.nyatla.nyartoolkit.core.labeling.*;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabelStack;\r
-\r
-/**\r
- * 計算部から浮動小数点計算を除外したNyARLabeling_ARToolKit\r
- * NyARLabeling_ARToolKitと同じ処理をするけど、エリア計算にintを使う。 \r
- * 画面サイズが1600x1600を超えると挙動が怪しくなる。\r
- * \r
- */\r
-public class NyARLabeling_ARToolKit_X2\r
-{\r
-       private static final int WORK_SIZE = 1024 * 32;// #define WORK_SIZE 1024*32\r
-\r
-       private final NyARWorkHolder work_holder = new NyARWorkHolder(WORK_SIZE);\r
-\r
-       private NyARIntSize _dest_size;\r
-\r
-       private NyARLabelingImage _out_image;\r
-\r
-       public void attachDestination(NyARLabelingImage i_destination_image) throws NyARException\r
-       {\r
-               // サイズチェック\r
-               NyARIntSize size = i_destination_image.getSize();\r
-               this._out_image = i_destination_image;\r
-\r
-               // NyLabelingImageのイメージ初期化(枠書き)\r
-               int[] img = (int[])i_destination_image.getBufferReader().getBuffer();\r
-               int bottom_ptr=(size.h - 1)*size.w;\r
-               for (int i = 0; i < size.w; i++) {\r
-                       img[i] = 0;\r
-                       img[bottom_ptr+i] = 0;\r
-               }\r
-               for (int i = 0; i < size.h; i++) {\r
-                       img[i*size.w] = 0;\r
-                       img[(i+1)*size.w - 1] = 0;\r
-               }\r
-\r
-               // サイズ(参照値)を保存\r
-               this._dest_size = size;\r
-               return;\r
-       }\r
-\r
-       public NyARLabelingImage getAttachedDestination()\r
-       {\r
-               return this._out_image;\r
-       }\r
-\r
-       /**\r
-        * static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR ) 関数の代替品\r
-        * ラスタimageをラベリングして、結果を保存します。 Optimize:STEP[1514->1493]\r
-        * \r
-        * @param i_raster\r
-        * @throws NyARException\r
-        */\r
-       public void labeling(NyARBinRaster i_raster) throws NyARException\r
-       {\r
-               int m, n; /* work */\r
-               int i, j, k;\r
-               NyARLabelingImage out_image = this._out_image;\r
-\r
-               // サイズチェック\r
-               NyARIntSize in_size = i_raster.getSize();\r
-               this._dest_size.isEqualSize(in_size);\r
-\r
-               final int lxsize = in_size.w;// lxsize = arUtil_c.arImXsize;\r
-               final int lysize = in_size.h;// lysize = arUtil_c.arImYsize;\r
-               int[] label_img = (int[])out_image.getBufferReader().getBuffer();\r
-\r
-               // 枠作成はインスタンスを作った直後にやってしまう。\r
-               \r
-               //ラベリング情報のリセット(ラベリングインデックスを使用)\r
-               out_image.reset(true);\r
-               \r
-               int[] label_idxtbl=out_image.getIndexArray();\r
-\r
-               int[] work2_pt;\r
-               int wk_max = 0;\r
-\r
-               int label_pixel;\r
-               int[] raster_buf=(int[])i_raster.getBufferReader().getBuffer();\r
-               int line_ptr;\r
-               int[][] work2 = this.work_holder.work2;\r
-               int label_img_ptr0, label_img_ptr1;\r
-               for (j = 1; j < lysize - 1; j++) {// for (int j = 1; j < lysize - 1;j++, pnt += poff*2, pnt2 += 2) {\r
-                       line_ptr=j*lxsize;\r
-                       label_img_ptr0=j*lxsize;//label_img_pt0 = label_img[j];\r
-                       label_img_ptr1=label_img_ptr0-lxsize;//label_img_pt1 = label_img[j - 1];\r
-                       for (i = 1; i < lxsize - 1; i++) {// for(int i = 1; i < lxsize-1;i++, pnt+=poff, pnt2++) {\r
-                               // RGBの合計値が閾値より小さいかな?\r
-                               if (raster_buf[line_ptr+i]==0) {\r
-                                       // pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 =&(pnt2[-lxsize]);\r
-                                       if (label_img[label_img_ptr1+i] > 0) {//if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) {\r
-                                               label_pixel = label_img[label_img_ptr1+i];//label_pixel = label_img_pt1[i];// *pnt2 = *pnt1;\r
-\r
-                                               work2_pt = work2[label_pixel - 1];\r
-                                               work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;\r
-                                               work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;\r
-                                               work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;\r
-                                               work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;\r
-                                       } else if (label_img[label_img_ptr1+i + 1] > 0) {//} else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) {\r
-                                               if (label_img[label_img_ptr1+i - 1] > 0) {//if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) {\r
-                                                       m = label_idxtbl[label_img[label_img_ptr1+i + 1] - 1];//m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];\r
-                                                       n = label_idxtbl[label_img[label_img_ptr1+i - 1] - 1];//n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1];\r
-                                                       if (m > n) {\r
-                                                               label_pixel = n;// *pnt2 = n;\r
-                                                               // wk=IntPointer.wrap(work, 0);//wk =\r
-                                                               // &(work[0]);\r
-                                                               for (k = 0; k < wk_max; k++) {\r
-                                                                       if (label_idxtbl[k] == m) {// if( *wk == m )\r
-                                                                               label_idxtbl[k] = n;// *wk = n;\r
-                                                                       }\r
-                                                               }\r
-                                                       } else if (m < n) {\r
-                                                               label_pixel = m;// *pnt2 = m;\r
-                                                               // wk=IntPointer.wrap(work,0);//wk = &(work[0]);\r
-                                                               for (k = 0; k < wk_max; k++) {\r
-                                                                       if (label_idxtbl[k] == n) {// if( *wk == n ){\r
-                                                                               label_idxtbl[k] = m;// *wk = m;\r
-                                                                       }\r
-                                                               }\r
-                                                       } else {\r
-                                                               label_pixel = m;// *pnt2 = m;\r
-                                                       }\r
-                                                       work2_pt = work2[label_pixel - 1];\r
-                                                       work2_pt[0]++;\r
-                                                       work2_pt[1] += i;\r
-                                                       work2_pt[2] += j;\r
-                                                       work2_pt[6] = j;\r
-                                               } else if ((label_img[label_img_ptr0+i - 1]) > 0) {//} else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) {\r
-                                                       m = label_idxtbl[label_img[label_img_ptr1+i + 1] - 1];//m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1];\r
-                                                       n = label_idxtbl[label_img[label_img_ptr0+i - 1] - 1];//n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1];\r
-                                                       if (m > n) {\r
-\r
-                                                               label_pixel = n;// *pnt2 = n;\r
-                                                               for (k = 0; k < wk_max; k++) {\r
-                                                                       if (label_idxtbl[k] == m) {// if( *wk == m ){\r
-                                                                               label_idxtbl[k] = n;// *wk = n;\r
-                                                                       }\r
-                                                               }\r
-                                                       } else if (m < n) {\r
-                                                               label_pixel = m;// *pnt2 = m;\r
-                                                               for (k = 0; k < wk_max; k++) {\r
-                                                                       if (label_idxtbl[k] == n) {// if( *wk == n ){\r
-                                                                               label_idxtbl[k] = m;// *wk = m;\r
-                                                                       }\r
-                                                               }\r
-                                                       } else {\r
-                                                               label_pixel = m;// *pnt2 = m;\r
-                                                       }\r
-                                                       work2_pt = work2[label_pixel - 1];\r
-                                                       work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;\r
-                                                       work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;\r
-                                                       work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;\r
-                                               } else {\r
-\r
-                                                       label_pixel = label_img[label_img_ptr1+i + 1];//label_pixel = label_img_pt1[i + 1];// *pnt2 =\r
-                                                                                                                               // *(pnt1+1);\r
-\r
-                                                       work2_pt = work2[label_pixel - 1];\r
-                                                       work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;\r
-                                                       work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;\r
-                                                       work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;\r
-                                                       if (work2_pt[3] > i) {// if(\r
-                                                                                                       // work2[((*pnt2)-1)*7+3] >\r
-                                                                                                       // i ){\r
-                                                               work2_pt[3] = i;// work2[((*pnt2)-1)*7+3] = i;\r
-                                                       }\r
-                                                       work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;\r
-                                               }\r
-                                       } else if ((label_img[label_img_ptr1+i - 1]) > 0) {//} else if ((label_img_pt1[i - 1]) > 0) {// }else if(\r
-                                                                                                                       // *(pnt1-1) > 0 ) {\r
-                                               label_pixel = label_img[label_img_ptr1+i - 1];//label_pixel = label_img_pt1[i - 1];// *pnt2 =\r
-                                                                                                                       // *(pnt1-1);\r
-\r
-                                               work2_pt = work2[label_pixel - 1];\r
-                                               work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;\r
-                                               work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;\r
-                                               work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;\r
-                                               if (work2_pt[4] < i) {// if( work2[((*pnt2)-1)*7+4] <i ){\r
-                                                       work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;\r
-                                               }\r
-                                               work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j;\r
-                                       } else if (label_img[label_img_ptr0+i - 1] > 0) {//} else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) {\r
-                                               label_pixel = label_img[label_img_ptr0+i - 1];//label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1);\r
-\r
-                                               work2_pt = work2[label_pixel - 1];\r
-                                               work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++;\r
-                                               work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i;\r
-                                               work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j;\r
-                                               if (work2_pt[4] < i) {// if( work2[((*pnt2)-1)*7+4] <i ){\r
-                                                       work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i;\r
-                                               }\r
-                                       } else {\r
-                                               // 現在地までの領域を予約\r
-                                               this.work_holder.reserv(wk_max);\r
-                                               wk_max++;\r
-                                               label_idxtbl[wk_max - 1] = wk_max;\r
-                                               label_pixel = wk_max;// work[wk_max-1] = *pnt2 = wk_max;\r
-                                               work2_pt = work2[wk_max - 1];\r
-                                               work2_pt[0] = 1;\r
-                                               work2_pt[1] = i;\r
-                                               work2_pt[2] = j;\r
-                                               work2_pt[3] = i;\r
-                                               work2_pt[4] = i;\r
-                                               work2_pt[5] = j;\r
-                                               work2_pt[6] = j;\r
-                                       }\r
-                                       label_img[label_img_ptr0+i] = label_pixel;//label_img_pt0[i] = label_pixel;\r
-                               } else {\r
-                                       label_img[label_img_ptr0+i] = 0;//label_img_pt0[i] = 0;// *pnt2 = 0;\r
-                               }\r
-                       }\r
-               }\r
-               // インデックステーブルとラベル数の計算\r
-               int wlabel_num = 1;// *label_num = *wlabel_num = j - 1;\r
-\r
-               for (i = 0; i < wk_max; i++) {// for(int i = 1; i <= wk_max; i++,wk++) {\r
-                       label_idxtbl[i] = (label_idxtbl[i] == i + 1) ? wlabel_num++ : label_idxtbl[label_idxtbl[i] - 1];// *wk=(*wk==i)?j++:work[(*wk)-1];\r
-               }\r
-               wlabel_num -= 1;// *label_num = *wlabel_num = j - 1;\r
-               if (wlabel_num == 0) {// if( *label_num == 0 ) {\r
-                       // 発見数0\r
-                       out_image.getLabelStack().clear();\r
-                       return;\r
-               }\r
-               // ラベルの整理\r
-               updateLabelStackLarge(out_image.getLabelStack(), label_idxtbl, in_size, work2, wk_max, wlabel_num);\r
-\r
-               return;\r
-       }\r
-       private int[][] __updateLabelStackLarge_temp=new int[64][7];/*area,x,y,l,r,t,b*/\r
-\r
-       /* 構造が変わるから、ハイスピード版実装するときに使う。 */\r
-       private void updateLabelStackLarge(NyARLabelingLabelStack i_stack, int[] i_lindex, NyARIntSize i_size, int[][] i_work, int i_work_max, int i_number_of_label) throws NyARException\r
-       {\r
-               //計算用のワークを確保\r
-               int[][] temp=this.__updateLabelStackLarge_temp;\r
-               if(temp.length<i_number_of_label){\r
-                       temp=new int[i_number_of_label+64][7];\r
-                       this.__updateLabelStackLarge_temp=temp;\r
-               }\r
-               \r
-               // ラベルバッファを予約\r
-               i_stack.reserv(i_number_of_label);\r
-               // エリアと重心、クリップ領域を計算\r
-               final NyARLabelingLabel[] labels = i_stack.getArray();\r
-               for (int i = 0; i < i_number_of_label; i++) {\r
-                       final int[] temp_ptr = temp[i];\r
-                       temp_ptr[0]=0;//area\r
-                       temp_ptr[1]=0;//x\r
-                       temp_ptr[2]=0;//y\r
-                       temp_ptr[3]=i_size.w;//l\r
-                       temp_ptr[4]=0;//r\r
-                       temp_ptr[5]=i_size.h;//t\r
-                       temp_ptr[6]=0;//b\r
-               }\r
-               //計算!\r
-\r
-               for (int i = 0; i < i_work_max; i++) {\r
-                       final int temp_ptr[] = temp[i_lindex[i] - 1];\r
-                       final int[] work2_pt = i_work[i];\r
-                       temp_ptr[0] += work2_pt[0];\r
-                       temp_ptr[1] += work2_pt[1];\r
-                       temp_ptr[2] += work2_pt[2];\r
-                       if (temp_ptr[3] > work2_pt[3]) {\r
-                               temp_ptr[3] = work2_pt[3];\r
-                       }\r
-                       if (temp_ptr[4] < work2_pt[4]) {\r
-                               temp_ptr[4] = work2_pt[4];\r
-                       }\r
-                       if (temp_ptr[5] > work2_pt[5]) {\r
-                               temp_ptr[5] = work2_pt[5];\r
-                       }\r
-                       if (temp_ptr[6] < work2_pt[6]) {\r
-                               temp_ptr[6] = work2_pt[6];\r
-                       }\r
-               }\r
-               //ストア\r
-               for (int i = 0; i < i_number_of_label; i++) {// for(int i = 0; i < *label_num; i++ ) {\r
-                       final NyARLabelingLabel label_pt = labels[i];\r
-                       final int temp_ptr[] = temp[i];\r
-                       label_pt.id=i+1;\r
-                       label_pt.area=temp_ptr[0];                      \r
-                       label_pt.pos_x= (double)temp_ptr[1]/label_pt.area;\r
-                       label_pt.pos_y= (double)temp_ptr[2]/label_pt.area;\r
-                       label_pt.clip_l= temp_ptr[3];\r
-                       label_pt.clip_r= temp_ptr[4];\r
-                       label_pt.clip_t= temp_ptr[5];\r
-                       label_pt.clip_b= temp_ptr[6];\r
-               }\r
-               return;\r
-       }\r
-}\r
-\r
-/**\r
- * NyARLabeling_O2のworkとwork2を可変長にするためのクラス\r
- * \r
- * \r
- */\r
-final class NyARWorkHolder\r
-{\r
-       private final static int ARRAY_APPEND_STEP = 256;\r
-\r
-       public final int[] work;\r
-\r
-       public final int[][] work2;\r
-\r
-       private int allocate_size;\r
-\r
-       /**\r
-        * 最大i_holder_size個の動的割り当てバッファを準備する。\r
-        * \r
-        * @param i_holder_size\r
-        */\r
-       public NyARWorkHolder(int i_holder_size)\r
-       {\r
-               // ポインタだけははじめに確保しておく\r
-               this.work = new int[i_holder_size];\r
-               this.work2 = new int[i_holder_size][];\r
-               this.allocate_size = 0;\r
-       }\r
-\r
-       /**\r
-        * i_indexで指定した番号までのバッファを準備する。\r
-        * \r
-        * @param i_index\r
-        */\r
-       public final void reserv(int i_index) throws NyARException\r
-       {\r
-               // アロケート済みなら即リターン\r
-               if (this.allocate_size > i_index) {\r
-                       return;\r
-               }\r
-               // 要求されたインデクスは範囲外\r
-               if (i_index >= this.work.length) {\r
-                       throw new NyARException();\r
-               }\r
-               // 追加アロケート範囲を計算\r
-               int range = i_index + ARRAY_APPEND_STEP;\r
-               if (range >= this.work.length) {\r
-                       range = this.work.length;\r
-               }\r
-               // アロケート\r
-               for (int i = this.allocate_size; i < range; i++) {\r
-                       this.work2[i] = new int[8];\r
-               }\r
-               this.allocate_size = range;\r
-       }\r
-}\r
index 6795899..89dcc82 100644 (file)
@@ -87,10 +87,8 @@ public class NyARSingleDetectMarker_X2
        public NyARSingleDetectMarker_X2(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_raster_type) throws NyARException\r
        {\r
                final NyARIntSize scr_size=i_param.getScreenSize();     \r
-        final NyARFixedFloatObserv2IdealMap dist_map = new NyARFixedFloatObserv2IdealMap(i_param.getDistortionFactor(), scr_size);\r
-               \r
                // 解析オブジェクトを作る\r
-               this._square_detect = new NyARSquareDetector_X2(dist_map,scr_size);\r
+               this._square_detect = new NyARSquareDetector_X2(i_param.getDistortionFactor(),scr_size);\r
                this._transmat = new NyARTransMat_X2(i_param);\r
                this._marker_width = i_marker_width;\r
         int cw=i_code.getWidth();\r
index e949f72..00948d7 100644 (file)
 package jp.nyatla.nyartoolkit.sandbox.x2;\r
 import jp.nyatla.nyartoolkit.NyARException;\r
 import jp.nyatla.nyartoolkit.core.labeling.*;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;\r
-import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabelStack;\r
+import jp.nyatla.nyartoolkit.core.labeling.rlelabeling.*;\r
 import jp.nyatla.nyartoolkit.core.raster.*;\r
-import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;\r
-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
-import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.*;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
-import jp.nyatla.nyartoolkit.core2.types.*;\r
-import jp.nyatla.nyartoolkit.core2.types.matrix.NyARI64Matrix22;\r
-import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.core.param.*;\r
 \r
 \r
 \r
@@ -59,29 +53,27 @@ public class NyARSquareDetector_X2 implements INyARSquareDetector
        private final int _width;\r
        private final int _height;\r
 \r
-       private final NyARLabeling_ARToolKit_X2 _labeling;\r
-\r
-       private final NyARLabelingImage _limage;\r
-\r
-       private final OverlapChecker _overlap_checker = new OverlapChecker();\r
-       private final NyARFixedFloatObserv2IdealMap _dist_factor_ref;\r
-//     private final NyARFixFloatCameraDistortionFactorMap _dist_factor_ref;\r
-       private final NyARFixedFloatPca2d _pca;\r
-//     private final INyARPca2d _pca;\r
+       private final LabelOverlapChecker<RleLabelFragmentInfoStack.RleLabelFragmentInfo> _overlap_checker = new LabelOverlapChecker<RleLabelFragmentInfoStack.RleLabelFragmentInfo>(32,RleLabelFragmentInfoStack.RleLabelFragmentInfo.class);\r
+       private final SquareContourDetector_X2 _sqconvertor;\r
+       private final ContourPickup _cpickup=new ContourPickup();\r
+       private final RleLabelFragmentInfoStack _stack;\r
 \r
+       \r
+       \r
+       private final NyARLabeling_Rle _labeling;\r
        /**\r
         * 最大i_squre_max個のマーカーを検出するクラスを作成する。\r
         * \r
         * @param i_param\r
         */\r
-       public NyARSquareDetector_X2(NyARFixedFloatObserv2IdealMap i_dist_factor_ref,NyARIntSize i_size) throws NyARException\r
+       public NyARSquareDetector_X2(NyARCameraDistortionFactor i_dist_factor_ref,NyARIntSize i_size) throws NyARException\r
        {\r
                this._width = i_size.w;\r
                this._height = i_size.h;\r
-               this._dist_factor_ref = i_dist_factor_ref;\r
-               this._labeling = new NyARLabeling_ARToolKit_X2();\r
-               this._limage = new NyARLabelingImage(this._width, this._height);\r
-               this._labeling.attachDestination(this._limage);\r
+               this._labeling = new NyARLabeling_Rle(this._width);\r
+               this._sqconvertor=new SquareContourDetector_X2(i_size,i_dist_factor_ref);\r
+               this._stack=new RleLabelFragmentInfoStack(i_size.w*i_size.h*2048/(320*240)+32);//検出可能な最大ラベル数\r
+               \r
 \r
                // 輪郭の最大長は画面に映りうる最大の長方形サイズ。\r
                int number_of_coord = (this._width + this._height) * 2;\r
@@ -90,26 +82,11 @@ public class NyARSquareDetector_X2 implements INyARSquareDetector
                this._max_coord = number_of_coord;\r
                this._xcoord = new int[number_of_coord * 2];\r
                this._ycoord = new int[number_of_coord * 2];\r
-               //PCA\r
-\r
-               this._pca=new NyARFixedFloatPca2d();\r
        }\r
-       private final int PCA_LENGTH=20;\r
-\r
        private final int _max_coord;\r
        private final int[] _xcoord;\r
        private final int[] _ycoord;\r
-       private final int[] _xpos=new int[PCA_LENGTH];\r
-       private final int[] _ypos=new int[PCA_LENGTH];\r
-       \r
-       private void normalizeCoord(int[] i_coord_x, int[] i_coord_y, int i_index, int i_coord_num)\r
-       {\r
-               // vertex1を境界にして、後方に配列を連結\r
-               System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, i_index);\r
-               System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, i_index);\r
-       }\r
 \r
-       private final int[] __detectMarker_mkvertex = new int[5];\r
 \r
        /**\r
         * arDetectMarker2を基にした関数\r
@@ -123,29 +100,21 @@ public class NyARSquareDetector_X2 implements INyARSquareDetector
         */\r
        public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException\r
        {\r
-               final NyARLabeling_ARToolKit_X2 labeling_proc = this._labeling;\r
-               final NyARLabelingImage limage = this._limage;\r
+               final RleLabelFragmentInfoStack flagment=this._stack;\r
+               final LabelOverlapChecker<RleLabelFragmentInfoStack.RleLabelFragmentInfo> overlap = this._overlap_checker;\r
 \r
                // 初期化\r
 \r
                // マーカーホルダをリセット\r
                o_square_stack.clear();\r
 \r
-               // ラベリング\r
-               labeling_proc.labeling(i_raster);\r
-\r
-               // ラベル数が0ならここまで\r
-               final int label_num = limage.getLabelStack().getLength();\r
+               // ラベル数が0ならここまで(Labeling内部でソートするようにした。)\r
+               final int label_num=this._labeling.labeling(i_raster, 0, i_raster.getHeight(), flagment);\r
                if (label_num < 1) {\r
                        return;\r
                }\r
 \r
-               final NyARLabelingLabelStack stack = limage.getLabelStack();\r
-               final NyARLabelingLabel[] labels = stack.getArray();\r
-               \r
-               \r
-               // ラベルを大きい順に整列\r
-               stack.sortByArea();\r
+               RleLabelFragmentInfoStack.RleLabelFragmentInfo[] labels=flagment.getArray();\r
 \r
                // デカいラベルを読み飛ばし\r
                int i;\r
@@ -161,27 +130,23 @@ public class NyARSquareDetector_X2 implements INyARSquareDetector
                final int[] xcoord = this._xcoord;\r
                final int[] ycoord = this._ycoord;\r
                final int coord_max = this._max_coord;\r
-               final int[] mkvertex = this.__detectMarker_mkvertex;\r
-               final OverlapChecker overlap = this._overlap_checker;\r
-               int coord_num;\r
-               int label_area;\r
-               NyARLabelingLabel label_pt;\r
 \r
                //重なりチェッカの最大数を設定\r
-               overlap.reset(label_num);\r
+               overlap.setMaxLabels(label_num);\r
 \r
                for (; i < label_num; i++) {\r
-                       label_pt = labels[i];\r
-                       label_area = label_pt.area;\r
+                       final RleLabelFragmentInfoStack.RleLabelFragmentInfo label_pt=labels[i];\r
+                       final int label_area = label_pt.area;\r
                        // 検査対象サイズよりも小さくなったら終了\r
-                       if (label_area < AR_AREA_MIN) {\r
+                       if (label_pt.area < AR_AREA_MIN) {\r
                                break;\r
                        }\r
+               \r
                        // クリップ領域が画面の枠に接していれば除外\r
-                       if (label_pt.clip_l == 1 || label_pt.clip_r == xsize - 2) {// if(wclip[i*4+0] == 1 || wclip[i*4+1] ==xsize-2){\r
+                       if (label_pt.clip_l == 0 || label_pt.clip_r == xsize-1){\r
                                continue;\r
                        }\r
-                       if (label_pt.clip_t == 1 || label_pt.clip_b == ysize - 2) {// if( wclip[i*4+2] == 1 || wclip[i*4+3] ==ysize-2){\r
+                       if (label_pt.clip_t == 0 || label_pt.clip_b == ysize-1){\r
                                continue;\r
                        }\r
                        // 既に検出された矩形との重なりを確認\r
@@ -189,280 +154,27 @@ public class NyARSquareDetector_X2 implements INyARSquareDetector
                                // 重なっているようだ。\r
                                continue;\r
                        }\r
-\r
+                       \r
                        // 輪郭を取得\r
-                       coord_num = limage.getContour(i, coord_max, xcoord, ycoord);\r
+                       final int coord_num = _cpickup.getContour(i_raster,label_pt.entry_x,label_pt.clip_t, coord_max, xcoord, ycoord);\r
                        if (coord_num == coord_max) {\r
                                // 輪郭が大きすぎる。\r
                                continue;\r
                        }\r
-                       //頂点候補のインデクスを取得\r
-                       final int vertex1 = scanVertex(xcoord, ycoord, coord_num);\r
+                       //輪郭分析用に正規化する。\r
+                       final int vertex1 = SquareContourDetector_X2.normalizeCoord(xcoord, ycoord, coord_num);\r
 \r
-                       // 頂点候補(vertex1)を先頭に並べなおした配列を作成する。\r
-                       normalizeCoord(xcoord, ycoord, vertex1, coord_num);\r
-\r
-                       // 領域を準備する。\r
-                       NyARSquare square_ptr = (NyARSquare)o_square_stack.prePush();\r
-\r
-                       // 頂点情報を取得\r
-                       if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex)) {\r
+                       //ここから先が輪郭分析\r
+                       NyARSquare square_ptr = o_square_stack.prePush();\r
+                       if(!this._sqconvertor.coordToSquare(xcoord,ycoord,vertex1,coord_num,label_area,square_ptr)){\r
                                o_square_stack.pop();// 頂点の取得が出来なかったので破棄\r
-                               continue;\r
-                       }\r
-                       // マーカーを検出\r
-                       if (!getSquareLine(mkvertex, xcoord, ycoord, square_ptr)) {\r
-                               // 矩形が成立しなかった。\r
-                               o_square_stack.pop();\r
-                               continue;\r
+                               continue;                               \r
                        }\r
                        // 検出済の矩形の属したラベルを重なりチェックに追加する。\r
                        overlap.push(label_pt);\r
-               }       \r
-               return;\r
-       }\r
-\r
-       /**\r
-        * 辺からの対角線が最長になる点を対角線候補として返す。\r
-        * \r
-        * @param i_xcoord\r
-        * @param i_ycoord\r
-        * @param i_coord_num\r
-        * @return\r
-        */\r
-       private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)\r
-       {\r
-               final int sx = i_xcoord[0];\r
-               final int sy = i_ycoord[0];\r
-               int d = 0;\r
-               int w, x, y;\r
-               int ret = 0;\r
-               for (int i = 1; i < i_coord_num; i++) {\r
-                       x = i_xcoord[i] - sx;\r
-                       y = i_ycoord[i] - sy;\r
-                       w = x * x + y * y;\r
-                       if (w > d) {\r
-                               d = w;\r
-                               ret = i;\r
-                       }\r
-                       // ここでうまく終了条件入れられないかな。\r
                }\r
-               return ret;\r
-       }\r
-\r
-       private final NyARFixedFloatVertexCounter __getSquareVertex_wv1 = new NyARFixedFloatVertexCounter();\r
-\r
-       private final NyARFixedFloatVertexCounter __getSquareVertex_wv2 = new NyARFixedFloatVertexCounter();\r
-\r
-       /**\r
-        * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。\r
-        * \r
-        * @param i_x_coord\r
-        * @param i_y_coord\r
-        * @param i_vertex1_index\r
-        * @param i_coord_num\r
-        * @param i_area\r
-        * @param o_vertex\r
-        * 要素数はint[4]である事\r
-        * @return\r
-        */\r
-       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)\r
-       {\r
-               final NyARFixedFloatVertexCounter wv1 = this.__getSquareVertex_wv1;\r
-               final NyARFixedFloatVertexCounter wv2 = this.__getSquareVertex_wv2;\r
-               final int end_of_coord = i_vertex1_index + i_coord_num - 1;\r
-               final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];\r
-               final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];\r
-               int dmax = 0;\r
-               int v1 = i_vertex1_index;\r
-               for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)\r
-                       // {\r
-                       final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);\r
-                       if (d > dmax) {\r
-                               dmax = d;\r
-                               v1 = i;\r
-                       }\r
-               }\r
-               //final double thresh = (i_area / 0.75) * 0.01;\r
-               final long thresh_f16 =(i_area<<16)/75;\r
-\r
-               o_vertex[0] = i_vertex1_index;\r
-\r
-               if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh_f16)) { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<\r
-                                                                                                                                                                       // 0 ) {\r
-                       return false;\r
-               }\r
-               if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh_f16)) {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)\r
-                       // < 0) {\r
-                       return false;\r
-               }\r
-\r
-               int v2;\r
-               if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {\r
-                       o_vertex[1] = wv1.vertex[0];\r
-                       o_vertex[2] = v1;\r
-                       o_vertex[3] = wv2.vertex[0];\r
-               } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {\r
-                       //頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。\r
-                       v2 = (v1-i_vertex1_index)/2+i_vertex1_index;\r
-                       if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh_f16)) {\r
-                               return false;\r
-                       }\r
-                       if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh_f16)) {\r
-                               return false;\r
-                       }\r
-                       if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
-                               o_vertex[1] = wv1.vertex[0];\r
-                               o_vertex[2] = wv2.vertex[0];\r
-                               o_vertex[3] = v1;\r
-                       } else {\r
-                               return false;\r
-                       }\r
-               } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {\r
-                       //v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;\r
-                       v2 = (v1+ end_of_coord)/2;\r
-\r
-                       if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh_f16)) {\r
-                               return false;\r
-                       }\r
-                       if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh_f16)) {\r
-                               return false;\r
-                       }\r
-                       if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {\r
-                               o_vertex[1] = v1;\r
-                               o_vertex[2] = wv1.vertex[0];\r
-                               o_vertex[3] = wv2.vertex[0];\r
-                       } else {\r
-                               return false;\r
-                       }\r
-               } else {\r
-                       return false;\r
-               }\r
-               o_vertex[4] = end_of_coord;\r
-               return true;\r
-       }\r
-\r
-       private final NyARI64Matrix22 __getSquareLine_evec=new NyARI64Matrix22();\r
-       private final NyARI64Point2d __getSquareLine_mean=new NyARI64Point2d();\r
-       private final NyARI64Point2d __getSquareLine_ev=new NyARI64Point2d();\r
-       private final NyARI64Linear[] __getSquareLine_i64liner=NyARI64Linear.createArray(4);\r
-\r
-       /**\r
-        * arGetLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2]) arGetLine2(int x_coord[], int y_coord[], int\r
-        * coord_num,int vertex[], double line[4][3], double v[4][2], double *dist_factor) の2関数の合成品です。 マーカーのvertex,lineを計算して、結果をo_squareに保管します。\r
-        * Optimize:STEP[424->391]\r
-        * \r
-        * @param i_cparam\r
-        * @return\r
-        * @throws NyARException\r
-        */\r
-       private boolean getSquareLine(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARSquare o_square) throws NyARException\r
-       {\r
-               final NyARLinear[] l_line = o_square.line;\r
-               final NyARI64Matrix22 evec=this.__getSquareLine_evec;\r
-               final NyARI64Point2d mean=this.__getSquareLine_mean;\r
-               final NyARI64Point2d ev=this.__getSquareLine_ev;\r
-               final NyARI64Linear[] i64liner=this.__getSquareLine_i64liner;\r
-       \r
-               for (int i = 0; i < 4; i++) {\r
-//                     final double w1 = (double) (i_mkvertex[i + 1] - i_mkvertex[i] + 1) * 0.05 + 0.5;\r
-                       final int w1 = ((((i_mkvertex[i + 1] - i_mkvertex[i] + 1)<<8)*13)>>8) + (1<<7);\r
-                       final int st = i_mkvertex[i] + (w1>>8);\r
-                       final int ed = i_mkvertex[i + 1] - (w1>>8);\r
-                       int n = ed - st + 1;\r
-                       if (n < 2) {\r
-                               // nが2以下でmatrix.PCAを計算することはできないので、エラー\r
-                               return false;\r
-                       }\r
-                       //配列作成\r
-                       n=this._dist_factor_ref.observ2IdealSampling(i_xcoord, i_ycoord, st, n,this._xpos,this._ypos,PCA_LENGTH);\r
-                       //主成分分析する。\r
-                       this._pca.pcaF16(this._xpos,this._ypos, n,evec, ev,mean);\r
-                       final NyARI64Linear l_line_i = i64liner[i];\r
-                       l_line_i.run = evec.m01;// line[i][0] = evec->m[1];\r
-                       l_line_i.rise = -evec.m00;// line[i][1] = -evec->m[0];\r
-                       l_line_i.intercept = -((l_line_i.run * mean.x + l_line_i.rise * mean.y)>>16);// line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);\r
-               }\r
-\r
-               final NyARDoublePoint2d[] l_sqvertex = o_square.sqvertex;\r
-               final NyARIntPoint2d[] l_imvertex = o_square.imvertex;\r
-               for (int i = 0; i < 4; i++) {\r
-                       final NyARI64Linear l_line_i = i64liner[i];\r
-                       final NyARI64Linear l_line_2 = i64liner[(i + 3) % 4];\r
-                       final long w1 =(l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise)>>16;\r
-                       if (w1 == 0) {\r
-                               return false;\r
-                       }\r
-                       l_sqvertex[i].x = (double)((l_line_2.rise * l_line_i.intercept - l_line_i.rise * l_line_2.intercept) / w1)/65536.0;\r
-                       l_sqvertex[i].y = (double)((l_line_i.run * l_line_2.intercept - l_line_2.run * l_line_i.intercept) / w1)/65536.0;\r
-                       // 頂点インデクスから頂点座標を得て保存\r
-                       l_imvertex[i].x = i_xcoord[i_mkvertex[i]];\r
-                       l_imvertex[i].y = i_ycoord[i_mkvertex[i]];\r
-                       l_line[i].run=(double)l_line_i.run/65536.0;\r
-                       l_line[i].rise=(double)l_line_i.rise/65536.0;\r
-                       l_line[i].intercept=(double)l_line_i.intercept/65536.0;\r
-               }\r
-               return true;\r
+               return;         \r
        }\r
 }\r
 \r
 \r
-/**\r
- * ラベル同士の重なり(内包関係)を調べるクラスです。 \r
- * ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。\r
- */\r
-class OverlapChecker\r
-{\r
-       private NyARLabelingLabel[] _labels = new NyARLabelingLabel[32];\r
-\r
-       private int _length;\r
-\r
-       /**\r
-        * 最大i_max_label個のラベルを蓄積できるようにオブジェクトをリセットする\r
-        * \r
-        * @param i_max_label\r
-        */\r
-       public void reset(int i_max_label)\r
-       {\r
-               if (i_max_label > this._labels.length) {\r
-                       this._labels = new NyARLabelingLabel[i_max_label];\r
-               }\r
-               this._length = 0;\r
-       }\r
-\r
-       /**\r
-        * チェック対象のラベルを追加する。\r
-        * \r
-        * @param i_label_ref\r
-        */\r
-       public void push(NyARLabelingLabel i_label_ref)\r
-       {\r
-               this._labels[this._length] = i_label_ref;\r
-               this._length++;\r
-       }\r
-\r
-       /**\r
-        * 現在リストにあるラベルと重なっているかを返す。\r
-        * \r
-        * @param i_label\r
-        * @return 何れかのラベルの内側にあるならばfalse,独立したラベルである可能性が高ければtrueです.\r
-        */\r
-       public boolean check(NyARLabelingLabel i_label)\r
-       {\r
-               // 重なり処理かな?\r
-               final NyARLabelingLabel[] label_pt = this._labels;\r
-               final int px1 = (int) i_label.pos_x;\r
-               final int py1 = (int) i_label.pos_y;\r
-               for (int i = this._length - 1; i >= 0; i--) {\r
-                       final int px2 = (int) label_pt[i].pos_x;\r
-                       final int py2 = (int) label_pt[i].pos_y;\r
-                       final int d = (px1 - px2) * (px1 - px2) + (py1 - py2) * (py1 - py2);\r
-                       if (d < label_pt[i].area / 4) {\r
-                               // 対象外\r
-                               return false;\r
-                       }\r
-               }\r
-               // 対象\r
-               return true;\r
-       }\r
-}
\ No newline at end of file
index 24683b2..4ce3a47 100644 (file)
@@ -100,8 +100,7 @@ public class VisualTest extends Frame implements JmfCaptureListener
                        // 画像3
                        NyARLabelingImage limage = new NyARLabelingImage(320, 240);
                        NyARLabeling_ARToolKit labeling = new NyARLabeling_ARToolKit();
-                       labeling.attachDestination(limage);
-                       labeling.labeling(_binraster1);
+                       labeling.labeling(_binraster1,limage);
                        this._bimg.drawImage(this._gsraster1);
 
                        NyARSquareStack stack = new NyARSquareStack(100);