OSDN Git Service

[バックアップ]NyARToolkit
authornyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Sat, 27 Sep 2008 07:14:12 +0000 (07:14 +0000)
committernyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Sat, 27 Sep 2008 07:14:12 +0000 (07:14 +0000)
29 files changed:
sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java
sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java
sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARQrCodeDetector.java [new file with mode: 0644]
sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARQrCodeSymbolBinder.java [new file with mode: 0644]
sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARRasterFilter_QrAreaAverage.java [new file with mode: 0644]
sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARSingleQrDetector.java [new file with mode: 0644]
sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/SingleQrSample.java [new file with mode: 0644]
sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/SingleQrTest.java [new file with mode: 0644]
sample/toys/jp/nyatla/nyartoolkit/toys/vertexdetect/NyARVertexDetector.java [moved from sample/toys/jp/nyatla/nyartoolkit/toys/vertexdetect/NyARQrCodeDetector.java with 96% similarity]
sample/toys/jp/nyatla/nyartoolkit/toys/x2/GLNyARSingleDetectMarker_X2.java
sample/toys/jp/nyatla/nyartoolkit/toys/x2/JavaSimpleLite_X2.java
sample/toys/jp/nyatla/nyartoolkit/toys/x2/RawFileTest_X2.java
src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARDetectMarker.java [deleted file]
src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java [deleted file]
src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java [deleted file]
src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/NyARGLUtil.java
src/jp/nyatla/nyartoolkit/core/NyARSquare.java
src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java
src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java [moved from src/jp/nyatla/nyartoolkit/core/raster/NyARGlayscaleRaster.java with 91% similarity]
src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter_GsToBin.java
src/jp/nyatla/nyartoolkit/core/rasterfilter/INyARRasterFilter_RgbToGs.java
src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_AreaAverage.java
src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_Threshold.java
src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbAve.java
src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbMul.java
src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbOr.java
src/jp/nyatla/utils/j2se/LabelingBufferdImage.java
test/jp/nyatla/nyartoolkit/dev/CopyOfLabelingCamera.java [deleted file]
test/jp/nyatla/nyartoolkit/dev/LabelingCamera.java

index 970c0ec..c56c5f7 100644 (file)
  */\r
 package jp.nyatla.nyartoolkit.jogl.sample;\r
 \r
-import java.awt.event.WindowAdapter;\r
-import java.awt.event.WindowEvent;\r
+import java.awt.event.*;\r
 import java.awt.*;\r
-\r
 import javax.media.Buffer;\r
-\r
-import javax.media.opengl.GL;\r
-import javax.media.opengl.GLAutoDrawable;\r
-import javax.media.opengl.GLEventListener;\r
-import javax.media.opengl.GLCanvas;\r
-\r
-import com.sun.opengl.util.Animator;\r
-\r
-import jp.nyatla.nyartoolkit.core.NyARCode;\r
-\r
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;\r
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;\r
+import javax.media.opengl.*;\r
+import com.sun.opengl.util.*;\r
+import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.core.param.*;\r
+import jp.nyatla.nyartoolkit.core.transmat.*;\r
+import jp.nyatla.nyartoolkit.detector.*;\r
+import jp.nyatla.nyartoolkit.jmf.utils.*;\r
 import jp.nyatla.nyartoolkit.jogl.utils.*;\r
 /**\r
  * simpleLiteと同じようなテストプログラム\r
@@ -67,14 +60,14 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener
        private JmfCameraCapture _capture;\r
 \r
        private GL _gl;\r
-\r
        private NyARGLUtil _glnya;\r
 \r
        //NyARToolkit関係\r
-       private GLNyARSingleDetectMarker _nya;\r
-\r
-       private GLNyARParam _ar_param;\r
+       private NyARSingleDetectMarker _nya;\r
+       private NyARParam _ar_param;\r
 \r
+       private double[] _camera_projection=new double[16];\r
+       \r
        /**\r
         * 立方体を書く\r
         *\r
@@ -150,11 +143,11 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener
                        _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);\r
                        _capture.setCaptureListener(this);\r
                        //NyARToolkitの準備\r
-                       _ar_param = new GLNyARParam();\r
+                       _ar_param = new NyARParam();\r
                        NyARCode ar_code = new NyARCode(16, 16);\r
                        _ar_param.loadARParamFromFile(PARAM_FILE);\r
                        _ar_param.changeScreenSize(SCREEN_X, SCREEN_Y);\r
-                       _nya = new GLNyARSingleDetectMarker(_ar_param, ar_code, 80.0);\r
+                       _nya = new NyARSingleDetectMarker(_ar_param, ar_code, 80.0);\r
                        _nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。\r
                        ar_code.loadARPattFromFile(CARCODE_FILE);\r
                        //NyARToolkit用の支援クラス\r
@@ -166,10 +159,12 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener
                } catch (Exception e) {\r
                        e.printStackTrace();\r
                }\r
-               _animator = new Animator(drawable);\r
+               //カメラパラメータの計算\r
+               _glnya.toCameraFrustumRH(_ar_param,_camera_projection);\r
 \r
+               _animator = new Animator(drawable);\r
                _animator.start();\r
-\r
+               return;\r
        }\r
 \r
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)\r
@@ -184,10 +179,12 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener
                _gl.glMatrixMode(GL.GL_MODELVIEW);\r
                _gl.glLoadIdentity();\r
        }\r
-\r
+       private NyARTransMatResult __display_transmat_result=new NyARTransMatResult();\r
+       private double[] __display_wk=new double[16];\r
+       \r
        public void display(GLAutoDrawable drawable)\r
        {\r
-\r
+               NyARTransMatResult transmat_result=__display_transmat_result;\r
                try {\r
                        if (!_cap_image.hasData()) {\r
                                return;\r
@@ -200,16 +197,20 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener
                                //背景を書く\r
                                _glnya.drawBackGround(_cap_image, 1.0);\r
                        }\r
-                       //ã\81\82ã\81£ã\81\9fã\82\89ç«\8bæ\96¹ä½\93ã\82\92æ\9b¸ã\81\8f\r
+                       //ã\83\9eã\83¼ã\82«ã\83¼ã\81\8cã\81\82ã\82\8cã\81°ã\80\81ç«\8bæ\96¹ä½\93ã\82\92æ\8f\8fç\94»\r
                        if (is_marker_exist) {\r
                                //マーカーの一致度を調査するならば、ここでnya.getConfidence()で一致度を調べて下さい。\r
                                // Projection transformation.\r
                                _gl.glMatrixMode(GL.GL_PROJECTION);\r
-                               _gl.glLoadMatrixd(_ar_param.getCameraFrustumRH(), 0);\r
+                               _gl.glLoadMatrixd(_camera_projection, 0);\r
                                _gl.glMatrixMode(GL.GL_MODELVIEW);\r
                                // Viewing transformation.\r
                                _gl.glLoadIdentity();\r
-                               _gl.glLoadMatrixd(_nya.getCameraViewRH(), 0);\r
+                               //変換行列を取得\r
+                               _nya.getTransmationMatrix(transmat_result);\r
+                               //変換行列をOpenGL形式に変換\r
+                               _glnya.toCameraViewRH(transmat_result, __display_wk);\r
+                               _gl.glLoadMatrixd(__display_wk, 0);\r
 \r
                                // All other lighting and geometry goes here.\r
                                drawCube();\r
index 8748b45..9f65915 100644 (file)
 \r
 package jp.nyatla.nyartoolkit.jogl.sample;\r
 \r
-import java.awt.event.WindowAdapter;\r
-import java.awt.event.WindowEvent;\r
+import java.awt.event.*;\r
 import java.awt.*;\r
-\r
-import javax.media.Buffer;\r
-\r
-import javax.media.opengl.GL;\r
-import javax.media.opengl.GLAutoDrawable;\r
-import javax.media.opengl.GLEventListener;\r
-import javax.media.opengl.GLCanvas;\r
-\r
+import javax.media.*;\r
+import javax.media.opengl.*;\r
 import com.sun.opengl.util.Animator;\r
-\r
-import jp.nyatla.nyartoolkit.core.NyARCode;\r
-\r
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture;\r
-import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener;\r
+import jp.nyatla.nyartoolkit.core.param.*;\r
+import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
+import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.detector.*;\r
+import jp.nyatla.nyartoolkit.jmf.utils.*;\r
 import jp.nyatla.nyartoolkit.jogl.utils.*;\r
 /**\r
  * simpleLiteの複数マーカー同時認識バージョン\r
@@ -73,10 +66,10 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
        private NyARGLUtil _glnya;\r
 \r
        //NyARToolkit関係\r
-       private GLNyARDetectMarker _nya;\r
-\r
-       private GLNyARParam _ar_param;\r
+       private NyARDetectMarker _nya;\r
 \r
+       private NyARParam _ar_param;\r
+       private double[] _camera_projection=new double[16];\r
        /**\r
         * 立方体を書く\r
         *\r
@@ -152,7 +145,7 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
                        _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);\r
                        _capture.setCaptureListener(this);\r
                        //NyARToolkitの準備\r
-                       _ar_param = new GLNyARParam();\r
+                       _ar_param = new NyARParam();\r
                        _ar_param.loadARParamFromFile(PARAM_FILE);\r
                        _ar_param.changeScreenSize(SCREEN_X, SCREEN_Y);\r
 \r
@@ -163,7 +156,7 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
                        ar_codes[0].loadARPattFromFile(CARCODE_FILE1);\r
                        ar_codes[1] = new NyARCode(16, 16);\r
                        ar_codes[1].loadARPattFromFile(CARCODE_FILE2);\r
-                       _nya = new GLNyARDetectMarker(_ar_param, ar_codes, width, 2);\r
+                       _nya = new NyARDetectMarker(_ar_param, ar_codes, width, 2);\r
                        _nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。\r
                        //NyARToolkit用の支援クラス\r
                        _glnya = new NyARGLUtil(_gl);\r
@@ -174,8 +167,10 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
                } catch (Exception e) {\r
                        e.printStackTrace();\r
                }\r
+               //カメラパラメータの計算\r
+               _glnya.toCameraFrustumRH(_ar_param,_camera_projection);\r
+               \r
                _animator = new Animator(drawable);\r
-\r
                _animator.start();\r
 \r
        }\r
@@ -192,9 +187,12 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
                _gl.glMatrixMode(GL.GL_MODELVIEW);\r
                _gl.glLoadIdentity();\r
        }\r
-\r
+       private NyARTransMatResult __display_transmat_result=new NyARTransMatResult();\r
+       private double[] __display_wk=new double[16];\r
+       \r
        public void display(GLAutoDrawable drawable)\r
        {\r
+               NyARTransMatResult transmat_result=__display_transmat_result;\r
 \r
                try {\r
                        if (!_cap_image.hasData()) {\r
@@ -209,7 +207,6 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
                                _glnya.drawBackGround(_cap_image, 1.0);\r
                        }\r
                        //あったら立方体を書く\r
-                       double[] matrix = new double[16];\r
                        for (int i = 0; i < found_markers; i++) {\r
                                //1番のマーカーでなければ表示しない。\r
                                if (_nya.getARCodeIndex(i) != 0) {\r
@@ -218,12 +215,15 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
                                //マーカーの一致度を調査するならば、ここでnya.getConfidence()で一致度を調べて下さい。\r
                                // Projection transformation.\r
                                _gl.glMatrixMode(GL.GL_PROJECTION);\r
-                               _gl.glLoadMatrixd(_ar_param.getCameraFrustumRH(), 0);\r
+                               _gl.glLoadMatrixd(_camera_projection, 0);\r
                                _gl.glMatrixMode(GL.GL_MODELVIEW);\r
                                // Viewing transformation.\r
                                _gl.glLoadIdentity();\r
-                               _nya.getCameraViewRH(i, matrix);\r
-                               _gl.glLoadMatrixd(matrix, 0);\r
+                               //変換行列を取得\r
+                               _nya.getTransmationMatrix(i,transmat_result);\r
+                               //変換行列をOpenGL形式に変換\r
+                               _glnya.toCameraViewRH(transmat_result, __display_wk);\r
+                               _gl.glLoadMatrixd(__display_wk, 0);\r
 \r
                                // All other lighting and geometry goes here.\r
                                drawCube();\r
@@ -232,6 +232,7 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener
                } catch (Exception e) {\r
                        e.printStackTrace();\r
                }\r
+               return;\r
        }\r
 \r
        public void onUpdateBuffer(Buffer i_buffer)\r
diff --git a/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARQrCodeDetector.java b/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARQrCodeDetector.java
new file mode 100644 (file)
index 0000000..694a35c
--- /dev/null
@@ -0,0 +1,489 @@
+package jp.nyatla.nyartoolkit.toys.qrcode;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.INyARSquareDetector;\r
+import jp.nyatla.nyartoolkit.core.NyARSquare;\r
+import jp.nyatla.nyartoolkit.core.NyARSquareStack;\r
+import jp.nyatla.nyartoolkit.core.NyARVertexCounter;\r
+import jp.nyatla.nyartoolkit.core.labeling.INyARLabeling;\r
+import jp.nyatla.nyartoolkit.core.labeling.NyARLabelingImage;\r
+import jp.nyatla.nyartoolkit.core.labeling.NyARLabelingLabel;\r
+import jp.nyatla.nyartoolkit.core.labeling.NyARLabelingLabelStack;\r
+import jp.nyatla.nyartoolkit.core.labeling.NyARLabeling_ARToolKit;\r
+import jp.nyatla.nyartoolkit.core.param.NyARCameraDistortionFactor;\r
+import jp.nyatla.nyartoolkit.core.pca2d.INyARPca2d;\r
+import jp.nyatla.nyartoolkit.core.pca2d.NyARPca2d_MatrixPCA_O2;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;\r
+import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntPoint;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
+import jp.nyatla.nyartoolkit.core.types.NyARLinear;\r
+import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;\r
+import jp.nyatla.utils.j2se.LabelingBufferdImage;\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
+       private static final int AR_AREA_MIN = 50;\r
+\r
+       private final int _width;\r
+\r
+       private final int _height;\r
+\r
+       private final NyARLabeling_ARToolKit _labeling;\r
+\r
+       private final NyARLabelingImage _limage;\r
+\r
+       private final NyARCameraDistortionFactor _dist_factor_ref;\r
+\r
+       /**\r
+        * 最大i_squre_max個のマーカーを検出するクラスを作成する。\r
+        * \r
+        * @param i_param\r
+        */\r
+       public NyARQrCodeDetector(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();\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
+\r
+               // 輪郭の最大長はMAX_COORD_NUMの2倍に制限\r
+               int number_of_coord = MAX_COORD_NUM* 2;\r
+\r
+               // 輪郭バッファはnumber_of_coordの2倍\r
+               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
+       }\r
+\r
+       private final int _max_coord;\r
+\r
+       private final int[] _xcoord;\r
+\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
+        * \r
+        * @param i_raster\r
+        * 解析する2値ラスタイメージを指定します。\r
+        * @param o_square_stack\r
+        * 抽出した正方形候補を格納するリスト\r
+        * @throws NyARException\r
+        */\r
+       public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException\r
+       {\r
+               final INyARLabeling labeling_proc = this._labeling;\r
+               final NyARLabelingImage limage = this._limage;\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
+               if (label_num < 1) {\r
+                       return;\r
+               }\r
+\r
+               final NyARLabelingLabelStack stack = limage.getLabelStack();\r
+               final NyARLabelingLabel[] labels = (NyARLabelingLabel[]) stack.getArray();\r
+\r
+               // ラベルを大きい順に整列\r
+               stack.sortByArea();\r
+\r
+               // デカいラベルを読み飛ばし\r
+               int i;\r
+               for (i = 0; i < label_num; i++) {\r
+                       // 検査対象内のラベルサイズになるまで無視\r
+                       if (labels[i].area <= AR_AREA_MAX) {\r
+                               break;\r
+                       }\r
+               }\r
+               \r
+               final int xsize = this._width;\r
+               final int ysize = this._height;\r
+               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
+               int label_area;\r
+               NyARLabelingLabel label_pt;\r
+               NyARSquareStack wk_stack=new NyARSquareStack(100);\r
+               wk_stack.clear();\r
+\r
+               for (; i < label_num; i++) {\r
+                       label_pt = labels[i];\r
+                       label_area = label_pt.area;\r
+                       // 検査対象サイズよりも小さくなったら終了\r
+                       if (label_area < AR_AREA_MIN) {\r
+                               break;\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
+                               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
+                               continue;\r
+                       }\r
+                       // 特徴点候補であるかを確認する。\r
+                       if (!hasQrEdgeFeature(buf, indextable, label_pt)) {\r
+                               continue;\r
+                       }\r
+\r
+                       // 輪郭を取得\r
+                       coord_num = limage.getContour(i, 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
+               }\r
+               //シンボルの関連付け\r
+               bindQrcodeEdge(wk_stack,o_square_stack);\r
+               //エッジ同士の相関関係をしらべる。\r
+\r
+               return;\r
+       }\r
+\r
+       /**\r
+        * QRコードのエッジペアを作る\r
+        * @param i_square_stack\r
+        */\r
+       public void bindQrcodeEdge(NyARSquareStack i_square_stack,NyARSquareStack o_square_stack) throws NyARException\r
+       {\r
+               NyARSquare[] group=new NyARSquare[3];\r
+               int number_of_edge=i_square_stack.getLength();\r
+               if(number_of_edge<3){\r
+                       return;\r
+               }\r
+               NyARSquare[] sa=(NyARSquare[])i_square_stack.getArray();\r
+               for(int i=0;i<number_of_edge-2;i++)\r
+               {       \r
+                       group[0]=sa[i];\r
+                       for(int i2=i+1;i2<number_of_edge-1;i2++)\r
+                       {\r
+                               group[1]=sa[i2];\r
+                               for(int i3=i2+1;i3<number_of_edge;i3++){\r
+                                       group[2]=sa[i3];\r
+                                       //3個のエッジの関連性を確認する。\r
+                                       NyARSquare new_square=(NyARSquare)o_square_stack.prePush();\r
+                                       if(!this._binder.composeSquare(group,new_square)){\r
+                                               o_square_stack.pop();\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               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(MAX_COORD_NUM);\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,NyARIntPoint[] o_imvertex) throws NyARException\r
+       {\r
+               final NyARCameraDistortionFactor dist_factor=this._dist_factor_ref;  \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._pca.pcaWithDistortionFactor(i_xcoord, i_ycoord, st, n,dist_factor, 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
+        * @param i_label\r
+        * @return\r
+        */\r
+       private boolean hasQrEdgeFeature(int buf[][], int[] index_table, NyARLabelingLabel i_label)\r
+       {\r
+               int tx, bx;\r
+               int w;\r
+               int i_label_id = i_label.id;\r
+               int[] limage_j;\r
+               final int clip_l = i_label.clip_l;\r
+               final int clip_b = i_label.clip_b;\r
+               final int clip_r = i_label.clip_r;\r
+               final int clip_t = i_label.clip_t;\r
+\r
+               tx = bx = 0;\r
+               // 上接点(→)\r
+               limage_j = buf[clip_t];\r
+               for (int i = clip_l; i <= clip_r; i++) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) {\r
+                       w = limage_j[i];\r
+                       if (w > 0 && index_table[w - 1] == i_label_id) {\r
+                               tx = i;\r
+                               break;\r
+                       }\r
+               }\r
+               // 下接点(←)\r
+               limage_j = buf[clip_b];\r
+               for (int i = clip_r; i >= clip_l; i--) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) {\r
+                       w = limage_j[i];\r
+                       if (w > 0 && index_table[w - 1] == i_label_id) {\r
+                               bx = i;\r
+                               break;\r
+                       }\r
+               }\r
+               final int cx = (clip_l + clip_r) / 2;\r
+               final int cy = (clip_t + clip_b) / 2;\r
+               // 横断チェック(中心から線を引いて、010になるかしらべる)\r
+               if (!checkDiagonalLine(buf, cx, cy, bx, clip_b)) {\r
+                       return false;\r
+               }\r
+               if (!checkDiagonalLine(buf, tx, clip_t, cx, cy)) {\r
+                       return false;\r
+               }\r
+               return true;\r
+       }\r
+\r
+       /**\r
+        * シンボルのパターン特徴を調べる関数\r
+        * 対角線の一部が010になってるか調べる。\r
+        * \r
+        * @param buf\r
+        * @param i_px1\r
+        * @param i_py1\r
+        * @param i_px2\r
+        * @param i_py2\r
+        * @return\r
+        */\r
+       private boolean checkDiagonalLine(int[][] buf, int i_px1, int i_py1, int i_px2, int i_py2)\r
+       {\r
+               int sub_y = i_py2 - i_py1;\r
+               int sub_x = i_px2 - i_px1;\r
+               // 黒\r
+               int i = 0;\r
+               for (; i < sub_y; i++) {\r
+                       int yp = i_py1 + i;\r
+                       int xp = i_px1 + i * sub_x / sub_y;\r
+                       if (buf[yp][xp] == 0 && buf[yp][xp-1] == 0 && buf[yp][xp+1] == 0) {\r
+                               break;\r
+                       }\r
+\r
+               }\r
+               if (i == sub_y) {\r
+                       return false;\r
+               }\r
+               // 白\r
+               for (; i < sub_y; i++) {\r
+                       int yp = i_py1 + i;\r
+                       int xp = i_px1 + i * sub_x / sub_y;\r
+                       if (buf[yp][xp] != 0 && buf[yp][xp-1] != 0 && buf[yp][xp+1] != 0) {\r
+                               break;\r
+                       }\r
+\r
+               }\r
+               if (i == sub_y) {\r
+                       return false;\r
+               }\r
+               // 黒\r
+               for (; i < sub_y; i++) {\r
+                       int yp = i_py1 + i;\r
+                       int xp = i_px1 + i * sub_x / sub_y;\r
+                       if (buf[yp][xp] == 0 && buf[yp][xp-1] == 0 && buf[yp][xp+1] == 0) {\r
+                               break;\r
+                       }\r
+\r
+               }\r
+               if (i != sub_y) {\r
+                       return false;\r
+               }\r
+               // 端まで到達したらOK\r
+               return true;\r
+       }\r
+\r
+}\r
diff --git a/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARQrCodeSymbolBinder.java b/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARQrCodeSymbolBinder.java
new file mode 100644 (file)
index 0000000..6102210
--- /dev/null
@@ -0,0 +1,298 @@
+package jp.nyatla.nyartoolkit.toys.qrcode;\r
+\r
+import java.awt.Color;\r
+import java.awt.Graphics;\r
+\r
+import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.core.types.*;\r
+import jp.nyatla.utils.j2se.*;\r
+import jp.nyatla.nyartoolkit.core.param.*;\r
+/**\r
+ * QRコードのシンボルを結びつける偉いクラス\r
+ * アルゴリズムはこんな感じ。\r
+ * 1.3シンボルの位置関係から中間のシンボルを探す。\r
+ * 2.中間シンボルの内角点を探す\r
+ * 3.残りの2シンボル間の最短距離の頂点セットを見つけて、それぞれの内角点を探す\r
+ * 4.3個の内角点が決まったら、各シンボルごとに外角点(反対側の頂点)を特定する。\r
+ * 5.対角のシンボルの外角頂点から伸びる線分を合成して、矩形を決める。\r
+ * 6.矩形が決まったら、方程式を解いて交点を出して、頂点にする。\r
+ * 7.交点と中央のシンボルの位置関係から、正しい計算が行われたかを判定(まだ実装してない)\r
+ * \r
+ * \r
+ * この方法は浅い角度でシンボル集合を見たときに、1や3の手順が高い確率で失敗する。\r
+ * その場合計算が途中で破綻するのでわかる(はず)\r
+ * 他の方法もあるけど、それはまた今度。\r
+ */\r
+public class NyARQrCodeSymbolBinder\r
+{\r
+       private NyARCameraDistortionFactor _distfactor;\r
+\r
+       public NyARQrCodeSymbolBinder(NyARCameraDistortionFactor i_ref_distortion)\r
+       {\r
+               this._distfactor=i_ref_distortion;\r
+               return;\r
+       }\r
+       /**\r
+        * 最小の三角形を構成する頂点セットを得る\r
+        * @param i_s0\r
+        * @param i_s1\r
+        * @param i_s2\r
+        * @param o_vertex\r
+        */\r
+       private static void getMinimumTriangleVertex(NyARSquare[] i_sqare,int[] o_vertex_id)\r
+       {\r
+               //辺の長さが最小になる頂点の組合せを探す\r
+               int d;\r
+               int x,y;\r
+               int dmax=0x7fffffff;\r
+               final NyARIntPoint[] vertex0=i_sqare[0].imvertex;\r
+               final NyARIntPoint[] vertex1=i_sqare[1].imvertex;\r
+               final NyARIntPoint[] vertex2=i_sqare[2].imvertex;\r
+               for(int i=0;i<4;i++)\r
+               {\r
+                       for(int i2=0;i2<4;i2++)\r
+                       {\r
+                               for(int i3=0;i3<4;i3++){\r
+                                       x=vertex0[i].x-vertex2[i3].x;\r
+                                       y=vertex0[i].y-vertex2[i3].y;\r
+                                       d=x*x+y*y;\r
+                                       x=vertex1[i2].x-vertex2[i3].x;\r
+                                       y=vertex1[i2].y-vertex2[i3].y;\r
+                                       d+=x*x+y*y;\r
+                                       x=vertex1[i2].x-vertex0[i].x;\r
+                                       y=vertex1[i2].y-vertex0[i].y;\r
+                                       d+=x*x+y*y;\r
+                                       if(d<dmax){\r
+                                               dmax=d;\r
+                                               o_vertex_id[0]=i;                                       \r
+                                               o_vertex_id[1]=i2;\r
+                                               o_vertex_id[2]=i3;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               return;\r
+       }\r
+       /**\r
+        * 2矩形の頂点距離が最低の組合せを探す\r
+        * @param i_sqare\r
+        * @param o_vertex_id\r
+        */\r
+       private static void getMinimumLineVertex(NyARIntPoint[] i_sqare0,NyARIntPoint[] i_sqare1,int[] o_vertex_id)\r
+       {\r
+               //辺の長さが最小になる頂点の組合せを探す\r
+               int d;\r
+               int x,y;\r
+               int dmax=0x7fffffff;\r
+               for(int i=0;i<4;i++)\r
+               {\r
+                       for(int i2=0;i2<4;i2++)\r
+                       {\r
+                               x=i_sqare1[i2].x-i_sqare0[i].x;\r
+                               y=i_sqare1[i2].y-i_sqare0[i].y;\r
+                               d=x*x+y*y;\r
+                               if(d<dmax){\r
+                                       dmax=d;\r
+                                       o_vertex_id[0]=i;                                       \r
+                                       o_vertex_id[1]=i2;\r
+                               }\r
+                       }\r
+               }\r
+               return;\r
+       }\r
+       /**\r
+        * シンボルグループの重心を計算する\r
+        * @param i_sqare\r
+        * @param i_center\r
+        */\r
+       private void getSymbolGroupCenter(NyARSquare[] i_sqare,NyARIntPoint i_center)\r
+       {\r
+               //シンボルグループの重心を計算\r
+               int cx,cy;\r
+               cx=cy=0;\r
+               for(int i=0;i<3;i++)\r
+               {\r
+                       final NyARIntPoint[] sq_ptr=i_sqare[i].imvertex;\r
+                       cx+=sq_ptr[0].x;                        \r
+                       cx+=sq_ptr[1].x;                        \r
+                       cx+=sq_ptr[2].x;                        \r
+                       cx+=sq_ptr[3].x;                        \r
+                       cy+=sq_ptr[0].y;                        \r
+                       cy+=sq_ptr[1].y;                        \r
+                       cy+=sq_ptr[2].y;                        \r
+                       cy+=sq_ptr[3].y;                        \r
+               }\r
+               i_center.x=cx/12;\r
+               i_center.y=cy/12;       \r
+               return;\r
+       }\r
+       /**\r
+        * キーシンボルのインデックスを得る\r
+        * @param i_sqare\r
+        * @param i_vertex_id\r
+        * 最小三角形の頂点IDセット\r
+        * @return\r
+        */\r
+       private static int getKeySymble(NyARSquare[] i_sqare,NyARIntPoint i_center,int[] i_vertex_id)\r
+       {\r
+               //シンボルグループの重心を計算\r
+               final int cx=i_center.x;\r
+               final int cy=i_center.y;        \r
+               //前段で探した頂点候補のうち、最も重心に近いものが中心シンボルの内対角点\r
+               int key_symble_idx=0;\r
+               int x=i_sqare[0].imvertex[i_vertex_id[0]].x-cx;\r
+               int y=i_sqare[0].imvertex[i_vertex_id[0]].y-cy;\r
+               int dmax=x*x+y*y;\r
+               for(int i=1;i<3;i++){\r
+                       x=i_sqare[i].imvertex[i_vertex_id[i]].x-cx;\r
+                       y=i_sqare[i].imvertex[i_vertex_id[i]].y-cy;\r
+                       final int d=x*x+y*y;\r
+                       if(d<dmax){\r
+                               dmax=d;\r
+                               key_symble_idx=i;\r
+                       }\r
+               }\r
+               return key_symble_idx;\r
+       }\r
+       private NyARDoublePoint2d __bindSquare_ideal_vertex=new NyARDoublePoint2d();\r
+       /**\r
+        * 2つの対角にある矩形から、それらを対角とする矩形を作る。\r
+        * @param i_sq1\r
+        * @param i_lv1\r
+        * @param i_sq2\r
+        * @param i_lv2\r
+        */\r
+       private void bindSquare(NyARSquare i_sq1,int i_lv1,NyARSquare i_sq2,int i_lv2,NyARSquare o_qr_square)\r
+       {\r
+               //4辺の式を計算\r
+               o_qr_square.line[0].copyFrom(i_sq1.line[(i_lv1+3)%4]);\r
+               o_qr_square.line[1].copyFrom(i_sq1.line[(i_lv1+0)%4]);\r
+               o_qr_square.line[2].copyFrom(i_sq2.line[(i_lv2+3)%4]);\r
+               o_qr_square.line[3].copyFrom(i_sq2.line[(i_lv2+0)%4]);\r
+               //歪み無しの座標系を計算\r
+               final NyARDoublePoint2d[] l_sqvertex = o_qr_square.sqvertex;\r
+               final NyARIntPoint[] imvertex_ptr = o_qr_square.imvertex;\r
+\r
+               final NyARLinear[] l_line = o_qr_square.line;\r
+               final NyARDoublePoint2d ideal_vertex=this.__bindSquare_ideal_vertex;\r
+               for (int i = 0; i < 4; i++) {\r
+                       final NyARLinear l_line_i = l_line[i];\r
+                       final NyARLinear l_line_2 = l_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;\r
+                       }\r
+                       l_sqvertex[i].x = (l_line_2.rise * l_line_i.intercept - l_line_i.rise * l_line_2.intercept) / w1;\r
+                       l_sqvertex[i].y = (l_line_i.run * l_line_2.intercept - l_line_2.run * l_line_i.intercept) / w1;\r
+                       _distfactor.ideal2Observ(l_sqvertex[i], ideal_vertex);\r
+                       //Ideal→observに変換して、画面上の座標とする。\r
+                       imvertex_ptr[i].x=(int)l_sqvertex[i].x;\r
+                       imvertex_ptr[i].y=(int)l_sqvertex[i].y;\r
+               }       \r
+//             Graphics g=this.bimg.getGraphics();\r
+//             g.setColor(Color.red);\r
+//             int[] x=new int[4];\r
+//             int[] y=new int[4];\r
+//             for(int i=0;i<4;i++){\r
+//                     x[i]=(int)l_sqvertex[i].x;\r
+//                     y[i]=(int)l_sqvertex[i].y;\r
+//             }\r
+//             g.drawPolygon(x,y,4);\r
+               return;\r
+               //基準点はVertexをそのまま採用\r
+               //2個の想定点は座標を逆変換して設定\r
+       }\r
+       /**\r
+        * directionはキーシンボルのインデックスでARToolKitの頂点座標じゃないので注意すること。\r
+        * @param i_sq\r
+        * @param o_sq\r
+        * @return\r
+        */\r
+       public boolean composeSquare(NyARSquare[] i_sq,NyARSquare o_sq)\r
+       {\r
+               int[] minimum_triangle_vertex=new int[3];\r
+               int[] minimum_line_vertex=new int[2];\r
+               \r
+               NyARIntPoint center=new NyARIntPoint();\r
+\r
+               //辺の長さが最小になる頂点の組合せを探す\r
+               getMinimumTriangleVertex(i_sq,minimum_triangle_vertex);\r
+               \r
+               //中心位置を計算する。\r
+               getSymbolGroupCenter(i_sq,center);\r
+               \r
+               //キーシンボルのインデクス番号を得る\r
+               int key_simble_idx=getKeySymble(i_sq,center,minimum_triangle_vertex);\r
+               \r
+               //対角シンボルのインデックス番号を決める\r
+               int symbol_e1_idx=(key_simble_idx+1)%3;\r
+               int symbol_e2_idx=(key_simble_idx+2)%3;\r
+               \r
+               //対角シンボル間で最短距離を取る頂点ペアを取る\r
+               //(角度を低くするとエラーが出やすい。対角線との類似性を確認する方法のほうがいい。多分)\r
+               getMinimumLineVertex(i_sq[symbol_e1_idx].imvertex,i_sq[symbol_e2_idx].imvertex,minimum_line_vertex);\r
+               \r
+               //内対角を外対角に変換\r
+               int lv1=(minimum_line_vertex[0]+2)%4;\r
+               int lv2=(minimum_line_vertex[1]+2)%4;\r
+               int kv =(minimum_triangle_vertex[key_simble_idx]+2)%4;\r
+               //矩形の合成\r
+               bindSquare(i_sq[symbol_e1_idx],lv1,i_sq[symbol_e2_idx],lv2,o_sq);\r
+               \r
+               //方位判定\r
+               //基点(中央シンボルを0として時計回りにインクリメント.基点の座標1か3\r
+               \r
+               int direction=getDirection(o_sq,i_sq[key_simble_idx].imvertex[kv],center);\r
+               if(direction==-1){\r
+                       return false;\r
+               }\r
+               o_sq.direction=direction;\r
+               System.out.println(o_sq.direction);\r
+               \r
+               return true;\r
+       }       \r
+       /**\r
+        * この関数はあんまり頂点ズレがひどいと失敗する\r
+        * @param i_square\r
+        * @param i_vertex\r
+        * @param i_center\r
+        * @return\r
+        */\r
+       private int getDirection(NyARSquare i_square,NyARIntPoint i_vertex,NyARIntPoint i_center)\r
+       {\r
+               //開始点(中央シンボル)までの頂点のシフト数を決める\r
+               int x,y;\r
+               x=i_square.imvertex[0].x-i_vertex.x;\r
+               y=i_square.imvertex[0].y-i_vertex.y;\r
+               int v1=x*x+y*y;\r
+               x=i_square.imvertex[2].x-i_vertex.x;\r
+               y=i_square.imvertex[2].y-i_vertex.y;\r
+               int v2=x*x+y*y;\r
+               int shift;\r
+               int v;\r
+               if(v1<v2){\r
+                       shift=0;\r
+                       v=v1;\r
+               }else{\r
+                       shift=2;\r
+                       v=v2;\r
+               }\r
+               //小さい方の対角線が64(8x8)より大きくずれてたら認識ミスとみなす\r
+               if(v>64){\r
+                       return -1;\r
+               }\r
+               //シンボルがどの象限にあるか確認する\r
+               x=i_vertex.x=i_center.x;\r
+               y=i_vertex.y=i_center.y;\r
+               int dir;\r
+               if(x<0){\r
+                       dir=2;//dir=y<0?1:2;\r
+               }else{\r
+                       dir=4;//dir=y<0?3:4;\r
+               }\r
+               return (dir+shift)%4;\r
+       }\r
+       \r
+       \r
+       \r
+}
\ No newline at end of file
diff --git a/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARRasterFilter_QrAreaAverage.java b/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARRasterFilter_QrAreaAverage.java
new file mode 100644 (file)
index 0000000..2202f70
--- /dev/null
@@ -0,0 +1,89 @@
+/* \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.toys.qrcode;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter_GsToBin;\r
+import jp.nyatla.nyartoolkit.core.types.*;\r
+\r
+/**\r
+ * 平均移動法を使った2値化フィルタ\r
+ * \r
+ */\r
+public class NyARRasterFilter_QrAreaAverage implements INyARRasterFilter_GsToBin\r
+{\r
+       private int _area = 8;\r
+\r
+       public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
+       {\r
+               final NyARIntSize size = i_output.getSize();\r
+               final int[][] out_buf = (int[][]) i_output.getBufferReader().getBuffer();\r
+               final int[][] in_buf = (int[][]) i_input.getBufferReader().getBuffer();\r
+               assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
+               assert (size.h % 8 == 0 && size.w % 8 == 0);//暫定実装なので。\r
+\r
+               final int area = this._area;\r
+               int y1 = area;\r
+               int x1 = area;\r
+               int y2 = size.h - area;\r
+               int x2 = size.w - area;\r
+\r
+               for (int y = y1; y < y2; y++) {\r
+                       int sum, nn;\r
+                       sum = nn = 0;\r
+                       for (int yy = y - area; yy < y + area + 1; yy++) {\r
+                               for (int xx = x1 - area; xx < x1 + area; xx++) {\r
+                                       sum += in_buf[yy][xx];\r
+                                       nn++;\r
+                               }\r
+                       }\r
+                       int th;\r
+                       boolean first = true;\r
+                       th=0;\r
+                       for (int x = area; x < x2; x++) {\r
+                               if (!first) {\r
+                                       for (int yy = y - area; yy < y + area; yy++) {\r
+                                               sum += in_buf[yy][x + area];\r
+                                               sum -= in_buf[yy][x - area];\r
+                                       }\r
+                               }\r
+                               first = false;\r
+                               th = (sum / nn);\r
+                               int g = in_buf[y][x];\r
+                               out_buf[y][x] = th < g ? 1 : 0;\r
+                       }\r
+               }\r
+               return;\r
+       }\r
+\r
+}\r
diff --git a/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARSingleQrDetector.java b/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/NyARSingleQrDetector.java
new file mode 100644 (file)
index 0000000..2d7bf72
--- /dev/null
@@ -0,0 +1,159 @@
+/* \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.toys.qrcode;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.core.match.*;\r
+import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
+import jp.nyatla.nyartoolkit.core.pickup.*;\r
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.*;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.core.transmat.*;\r
+import jp.nyatla.nyartoolkit.core.types.*;\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;\r
+import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.*;\r
+import jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin.*;\r
+/**\r
+ * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。\r
+ * \r
+ */\r
+public class NyARSingleQrDetector\r
+{\r
+       private static final int AR_SQUARE_MAX = 100;\r
+\r
+       private boolean _is_continue = false;\r
+       private INyARSquareDetector _square_detect;\r
+\r
+       private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX);\r
+\r
+       protected INyARTransMat _transmat;\r
+\r
+       private double _marker_width;\r
+\r
+       // 検出結果の保存用\r
+       private NyARSquare _detected_square;\r
+\r
+\r
+       /**\r
+        * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。\r
+        * \r
+        * @param i_param\r
+        * カメラパラメータを指定します。\r
+        * @param i_marker_width\r
+        * ARコードの物理サイズを、ミリメートルで指定します。\r
+        * @throws NyARException\r
+        */\r
+       public NyARSingleQrDetector(NyARParam i_param, double i_marker_width) throws NyARException\r
+       {\r
+               final NyARIntSize scr_size=i_param.getScreenSize();             \r
+               // 解析オブジェクトを作る\r
+               this._square_detect = new NyARQrCodeDetector(i_param.getDistortionFactor(),scr_size);\r
+               this._transmat = new NyARTransMat(i_param);\r
+               this._marker_width = i_marker_width;\r
+               //2値画像バッファを作る\r
+               this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);\r
+               //中間のグレースケール画像のバッファを作る\r
+               this._gs_raster=new NyARGrayscaleRaster(scr_size.w,scr_size.h);\r
+       }\r
+       private NyARBinRaster _bin_raster;\r
+       private NyARGrayscaleRaster _gs_raster;\r
+       //画処理フィルター\r
+       private INyARRasterFilter_RgbToGs _rgb2gs_filter=new NyARRasterFilter_RgbAve();\r
+       private INyARRasterFilter_GsToBin _gstobin_filter=new NyARRasterFilter_QrAreaAverage();\r
+\r
+       /**\r
+        * i_imageにマーカー検出処理を実行し、結果を記録します。\r
+        * \r
+        * @param i_raster\r
+        * マーカーを検出するイメージを指定します。イメージサイズは、カメラパラメータ\r
+        * と一致していなければなりません。\r
+        * @return マーカーが検出できたかを真偽値で返します。\r
+        * @throws NyARException\r
+        */\r
+       public boolean detectMarkerLite(INyARRgbRaster i_raster,int i_threshold) throws NyARException\r
+       {\r
+               //サイズチェック\r
+               if(!this._bin_raster.getSize().isEqualSize(i_raster.getSize())){\r
+                       throw new NyARException();\r
+               }\r
+               //グレースケールに変換\r
+               this._rgb2gs_filter.doFilter(i_raster, this._gs_raster);\r
+               //2値イメージに変換\r
+               this._gstobin_filter.doFilter(this._gs_raster, this._bin_raster);               \r
+               \r
+               this._detected_square = null;\r
+               NyARSquareStack l_square_list = this._square_list;\r
+               // スクエアコードを探す\r
+               this._square_detect.detectMarker(this._bin_raster, l_square_list);\r
+               //変換する\r
+\r
+\r
+               int number_of_square = l_square_list.getLength();\r
+               // コードは見つかった?\r
+               if (number_of_square < 1) {\r
+                       return false;\r
+               }\r
+               this._detected_square=(NyARSquare)l_square_list.getItem(0);\r
+               return true;\r
+       }\r
+\r
+       /**\r
+        * 検出したマーカーの変換行列を計算して、o_resultへ値を返します。\r
+        * 直前に実行したdetectMarkerLiteが成功していないと使えません。\r
+        * \r
+        * @param o_result\r
+        * 変換行列を受け取るオブジェクトを指定します。\r
+        * @throws NyARException\r
+        */\r
+       public void getTransmationMatrix(NyARTransMatResult o_result) throws NyARException\r
+       {\r
+               // 一番一致したマーカーの位置とかその辺を計算\r
+               if (this._is_continue) {\r
+                       this._transmat.transMatContinue(this._detected_square,this._detected_square.direction,this._marker_width, o_result);\r
+               } else {\r
+                       this._transmat.transMat(this._detected_square,this._detected_square.direction,this._marker_width, o_result);\r
+               }\r
+               return;\r
+       }\r
+       /**\r
+        * getTransmationMatrixの計算モードを設定します。 初期値はTRUEです。\r
+        * \r
+        * @param i_is_continue\r
+        * TRUEなら、transMatCont互換の計算をします。 FALSEなら、transMat互換の計算をします。\r
+        */\r
+       public void setContinueMode(boolean i_is_continue)\r
+       {\r
+               this._is_continue = i_is_continue;\r
+       }\r
+}\r
diff --git a/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/SingleQrSample.java b/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/SingleQrSample.java
new file mode 100644 (file)
index 0000000..8d488e2
--- /dev/null
@@ -0,0 +1,242 @@
+/* \r
+ * PROJECT: NyARToolkit JOGL sample program.\r
+ * --------------------------------------------------------------------------------\r
+ * The MIT License\r
+ * Copyright (c) 2008 nyatla\r
+ * airmail(at)ebony.plala.or.jp\r
+ * http://nyatla.jp/nyartoolkit/\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a copy\r
+ * of this software and associated documentation files (the "Software"), to deal\r
+ * in the Software without restriction, including without limitation the rights\r
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+ * copies of the Software, and to permit persons to whom the Software is\r
+ * furnished to do so, subject to the following conditions:\r
+ * The above copyright notice and this permission notice shall be included in\r
+ * all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+ * THE SOFTWARE.\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.toys.qrcode;\r
+\r
+import java.awt.event.*;\r
+import java.awt.*;\r
+import javax.media.Buffer;\r
+import javax.media.opengl.*;\r
+import com.sun.opengl.util.*;\r
+import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.core.param.*;\r
+import jp.nyatla.nyartoolkit.core.transmat.*;\r
+import jp.nyatla.nyartoolkit.jmf.utils.*;\r
+import jp.nyatla.nyartoolkit.jogl.utils.*;\r
+/**\r
+ * simpleLiteと同じようなテストプログラム\r
+ * 出来る限りARToolKitのサンプルと似せて作ってあります。\r
+ * 最も一致する"Hiro"マーカーを一つ選択して、その上に立方体を表示します。\r
+ * \r
+ */\r
+public class SingleQrSample implements GLEventListener, JmfCaptureListener\r
+{\r
+       private final String CARCODE_FILE = "../../Data/patt.hiro";\r
+\r
+       private final String PARAM_FILE = "../../Data/camera_para.dat";\r
+\r
+       private final static int SCREEN_X = 320;\r
+\r
+       private final static int SCREEN_Y = 240;\r
+\r
+       private Animator _animator;\r
+\r
+       private GLNyARRaster_RGB _cap_image;\r
+\r
+       private JmfCameraCapture _capture;\r
+\r
+       private GL _gl;\r
+       private NyARGLUtil _glnya;\r
+\r
+       //NyARToolkit関係\r
+       private NyARSingleQrDetector _nya;\r
+       private NyARParam _ar_param;\r
+\r
+       private double[] _camera_projection=new double[16];\r
+       \r
+       /**\r
+        * 立方体を書く\r
+        *\r
+        */\r
+       void drawCube()\r
+       {\r
+               // Colour cube data.\r
+               int polyList = 0;\r
+               float fSize = 0.5f;//マーカーサイズに対して0.5倍なので、4cmの立方体\r
+               int f, i;\r
+               float[][] cube_vertices = new float[][] { { 1.0f, 1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, { -1.0f, -1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, { -1.0f, -1.0f, -1.0f }, { -1.0f, 1.0f, -1.0f } };\r
+               float[][] cube_vertex_colors = new float[][] { { 1.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } };\r
+               int cube_num_faces = 6;\r
+               short[][] cube_faces = new short[][] { { 3, 2, 1, 0 }, { 2, 3, 7, 6 }, { 0, 1, 5, 4 }, { 3, 0, 4, 7 }, { 1, 2, 6, 5 }, { 4, 5, 6, 7 } };\r
+\r
+               if (polyList == 0) {\r
+                       polyList = _gl.glGenLists(1);\r
+                       _gl.glNewList(polyList, GL.GL_COMPILE);\r
+                       _gl.glBegin(GL.GL_QUADS);\r
+                       for (f = 0; f < cube_num_faces; f++)\r
+                               for (i = 0; i < 4; i++) {\r
+                                       _gl.glColor3f(cube_vertex_colors[cube_faces[f][i]][0], cube_vertex_colors[cube_faces[f][i]][1], cube_vertex_colors[cube_faces[f][i]][2]);\r
+                                       _gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
+                               }\r
+                       _gl.glEnd();\r
+                       _gl.glColor3f(0.0f, 0.0f, 0.0f);\r
+                       for (f = 0; f < cube_num_faces; f++) {\r
+                               _gl.glBegin(GL.GL_LINE_LOOP);\r
+                               for (i = 0; i < 4; i++)\r
+                                       _gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
+                               _gl.glEnd();\r
+                       }\r
+                       _gl.glEndList();\r
+               }\r
+\r
+               _gl.glPushMatrix(); // Save world coordinate system.\r
+               _gl.glTranslatef(0.0f, 0.0f, 0.5f); // Place base of cube on marker surface.\r
+               _gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f); // Rotate about z axis.\r
+               _gl.glDisable(GL.GL_LIGHTING); // Just use colours.\r
+               _gl.glCallList(polyList); // Draw the cube.\r
+               _gl.glPopMatrix(); // Restore world coordinate system.\r
+\r
+       }\r
+\r
+       public SingleQrSample()\r
+       {\r
+               Frame frame = new Frame("Java simpleLite with NyARToolkit");\r
+\r
+               // 3Dを描画するコンポーネント\r
+               GLCanvas canvas = new GLCanvas();\r
+               frame.add(canvas);\r
+               canvas.addGLEventListener(this);\r
+               frame.addWindowListener(new WindowAdapter() {\r
+                       public void windowClosing(WindowEvent e)\r
+                       {\r
+                               System.exit(0);\r
+                       }\r
+               });\r
+\r
+               frame.setVisible(true);\r
+               Insets ins = frame.getInsets();\r
+               frame.setSize(SCREEN_X + ins.left + ins.right, SCREEN_Y + ins.top + ins.bottom);\r
+               canvas.setBounds(ins.left, ins.top, SCREEN_X, SCREEN_Y);\r
+       }\r
+\r
+       public void init(GLAutoDrawable drawable)\r
+       {\r
+               _gl = drawable.getGL();\r
+               _gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);\r
+               //NyARToolkitの準備\r
+               try {\r
+                       //キャプチャの準備\r
+                       _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB);\r
+                       _capture.setCaptureListener(this);\r
+                       //NyARToolkitの準備\r
+                       _ar_param = new NyARParam();\r
+                       NyARCode ar_code = new NyARCode(16, 16);\r
+                       _ar_param.loadARParamFromFile(PARAM_FILE);\r
+                       _ar_param.changeScreenSize(SCREEN_X, SCREEN_Y);\r
+                       _nya = new NyARSingleQrDetector(_ar_param,80);\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);\r
+                       //キャプチャ開始\r
+                       _capture.start();\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+               //カメラパラメータの計算\r
+               _glnya.toCameraFrustumRH(_ar_param,_camera_projection);\r
+\r
+               _animator = new Animator(drawable);\r
+               _animator.start();\r
+               return;\r
+       }\r
+\r
+       public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)\r
+       {\r
+               _gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);\r
+               _gl.glViewport(0, 0, width, height);\r
+\r
+               //視体積の設定\r
+               _gl.glMatrixMode(GL.GL_PROJECTION);\r
+               _gl.glLoadIdentity();\r
+               //見る位置\r
+               _gl.glMatrixMode(GL.GL_MODELVIEW);\r
+               _gl.glLoadIdentity();\r
+       }\r
+       private NyARTransMatResult __display_transmat_result=new NyARTransMatResult();\r
+       private double[] __display_wk=new double[16];\r
+       \r
+       public void display(GLAutoDrawable drawable)\r
+       {\r
+               NyARTransMatResult transmat_result=__display_transmat_result;\r
+               try {\r
+                       if (!_cap_image.hasData()) {\r
+                               return;\r
+                       }\r
+                       _gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.          \r
+                       //画像チェックしてマーカー探して、背景を書く\r
+                       boolean is_marker_exist;\r
+                       synchronized (_cap_image) {\r
+                               is_marker_exist = _nya.detectMarkerLite(_cap_image, 0);\r
+                               //背景を書く\r
+                               _glnya.drawBackGround(_cap_image, 1.0);\r
+                       }\r
+                       //マーカーがあれば、立方体を描画\r
+                       if (is_marker_exist) {\r
+                               //マーカーの一致度を調査するならば、ここでnya.getConfidence()で一致度を調べて下さい。\r
+                               // Projection transformation.\r
+                               _gl.glMatrixMode(GL.GL_PROJECTION);\r
+                               _gl.glLoadMatrixd(_camera_projection, 0);\r
+                               _gl.glMatrixMode(GL.GL_MODELVIEW);\r
+                               // Viewing transformation.\r
+                               _gl.glLoadIdentity();\r
+                               //変換行列を取得\r
+                               _nya.getTransmationMatrix(transmat_result);\r
+                               //変換行列をOpenGL形式に変換\r
+                               _glnya.toCameraViewRH(transmat_result, __display_wk);\r
+                               _gl.glLoadMatrixd(__display_wk, 0);\r
+\r
+                               // All other lighting and geometry goes here.\r
+                               drawCube();\r
+                       }\r
+                       Thread.sleep(1);//タスク実行権限を一旦渡す\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+\r
+       }\r
+       public void onUpdateBuffer(Buffer i_buffer)\r
+       {\r
+               try {\r
+                       synchronized (_cap_image) {\r
+                               _cap_image.setBuffer(i_buffer, true);\r
+                       }\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+\r
+       public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged)\r
+       {\r
+       }\r
+\r
+       public static void main(String[] args)\r
+       {\r
+               new SingleQrSample();\r
+       }\r
+}\r
diff --git a/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/SingleQrTest.java b/sample/toys/jp/nyatla/nyartoolkit/toys/qrcode/SingleQrTest.java
new file mode 100644 (file)
index 0000000..6b98d06
--- /dev/null
@@ -0,0 +1,189 @@
+/* このソースは実験用のソースです。
+ * 動いたり動かなかったりします。
+ * 
+ */
+package jp.nyatla.nyartoolkit.toys.qrcode;
+
+import javax.media.*;
+
+import javax.media.util.BufferToImage;
+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.param.*;
+import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.rasterfilter.*;
+import jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin.*;
+import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.*;
+import jp.nyatla.utils.j2se.LabelingBufferdImage;
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
+import jp.nyatla.nyartoolkit.core.types.*;
+
+
+
+
+public class SingleQrTest extends Frame implements JmfCaptureListener
+{
+       private final String camera_file = "../../Data/camera_para.dat";
+
+       private JmfNyARRaster_RGB _raster;
+
+       private JmfCameraCapture capture;
+       private NyARParam ap;
+       public SingleQrTest() throws NyARException, NyARException
+       {
+               setBounds(0, 0, 640 + 64, 720 + 64);
+               // キャプチャの準備
+               capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB);
+               capture.setCaptureListener(this);
+
+               // キャプチャイメージ用のラスタを準備
+               this._raster = new JmfNyARRaster_RGB(320, 240);
+               
+               // AR用カメラパラメタファイルをロード
+               ap = new NyARParam();
+               ap.loadARParamFromFile(camera_file);
+               ap.changeScreenSize(320, 240);          
+               
+               
+       }
+
+       // そのラベルが特徴点候補か返す。
+
+       private NyARBinRaster _binraster1 = new NyARBinRaster(320, 240);
+
+       private NyARGrayscaleRaster _gsraster1 = new NyARGrayscaleRaster(320, 240);
+
+
+       private LabelingBufferdImage _bimg = new LabelingBufferdImage(320, 240);
+
+
+       public void onUpdateBuffer(Buffer i_buffer)
+       {
+               NyARRasterFilter_QrAreaAverage gs2bin=new NyARRasterFilter_QrAreaAverage();
+
+               try {
+                       // キャプチャしたバッファをラスタにセット
+                       _raster.setBuffer(i_buffer);
+
+                       Graphics g = getGraphics();
+                       // キャプチャ画像
+                       BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat());
+                       Image img = b2i.createImage(i_buffer);
+                       this.getGraphics().drawImage(img, 32, 32, this);
+
+                       // 画像1
+                       INyARRasterFilter_RgbToGs filter_rgb2gs = new NyARRasterFilter_RgbAve();
+//                     INyARRasterFilter_RgbToGs filter_rgb2gs = new NyARRasterFilter_RgbMul();
+                       
+                       filter_rgb2gs.doFilter(_raster, _gsraster1);
+                       this._bimg.drawImage(this._gsraster1);
+                       this.getGraphics().drawImage(this._bimg, 32 + 320, 32, 320 + 320 + 32, 240 + 32, 0, 240, 320, 0, this);
+                       
+
+                       // 画像2
+                       gs2bin.doFilter(_gsraster1, _binraster1);
+                       this._bimg.drawImage(_binraster1);
+                       this.getGraphics().drawImage(this._bimg, 32, 32 + 240, 320 + 32, 240 + 32 + 240, 0, 240, 320, 0, this);
+
+                       // 画像3
+                       NyARLabelingImage limage = new NyARLabelingImage(320, 240);
+                       NyARLabeling_ARToolKit labeling = new NyARLabeling_ARToolKit();
+                       labeling.attachDestination(limage);
+                       labeling.labeling(_binraster1);
+                       this._bimg.drawImage(this._gsraster1);
+
+                       NyARSquareStack stack = new NyARSquareStack(100);
+                       NyARQrCodeDetector detect = new NyARQrCodeDetector(ap.getDistortionFactor(), new NyARIntSize(320,240));
+//                     detect.bimg=this._bimg;
+
+                       detect.detectMarker(_binraster1, stack);
+                       for (int i = 0; i < stack.getLength(); i++) {
+                               NyARSquare[] square_ptr = (NyARSquare[]) stack.getArray();
+                               int d=square_ptr[i].direction;
+                               int[] xp=new int[4]; 
+                               int[] yp=new int[4]; 
+                               for(int i2=0;i2<4;i2++){
+                                       xp[i2]=square_ptr[i].imvertex[(i2+d)%4].x;
+                                       yp[i2]=square_ptr[i].imvertex[(i2+d)%4].y;
+                               }
+                               Graphics g2=this._bimg.getGraphics();
+                               g2.setColor(Color.RED);
+                               g2.drawPolygon(xp, yp,3);
+                               g2.setColor(Color.CYAN);
+                               g2.drawRect(square_ptr[i].imvertex[d].x, square_ptr[i].imvertex[d].y,5,5);                              
+                       }
+                       this.getGraphics().drawImage(this._bimg, 32 + 320, 32 + 240, 320 + 32 + 320, 240 + 32 + 240, 0, 240, 320, 0, this);
+
+                       // 画像3
+                       // threshold.debugDrawHistgramMap(_workraster, _workraster2);
+                       // this._bimg2.setImage(this._workraster2);
+                       // this.getGraphics().drawImage(this._bimg2, 32+320, 32+240,320+32+320,240+32+240,0,240,320,0, this);
+
+                       // 画像4
+                       // NyARRasterThresholdAnalyzer_SlidePTile threshold=new NyARRasterThresholdAnalyzer_SlidePTile(15);
+                       // threshold.analyzeRaster(_gsraster1);
+                       // filter_gs2bin=new NyARRasterFilter_AreaAverage();
+                       // filter_gs2bin.doFilter(_gsraster1, _binraster1);
+                       // this._bimg.drawImage(_binraster1);
+
+                       // NyARRasterDetector_QrCodeEdge detector=new NyARRasterDetector_QrCodeEdge(10000);
+                       // detector.analyzeRaster(_binraster1);
+
+                       // this._bimg.overlayData(detector.geResult());
+
+                       // this.getGraphics().drawImage(this._bimg, 32, 32+480,320+32,480+32+240,0,240,320,0, this);
+                       // 画像5
+
+                       /*
+                        * threshold2.debugDrawHistgramMap(_workraster, _workraster2); this._bimg2.drawImage(this._workraster2); this.getGraphics().drawImage(this._bimg2,
+                        * 32+320, 32+480,320+32+320,480+32+240,0,240,320,0, this);
+                        */
+
+                       // this.getGraphics().drawImage(this._bimg, 32, 32, this);
+
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+
+       }
+
+       private INyARLabeling labelingFactory(int i_idx)
+       {
+               // switch(i_idx){
+               // case 0:{NyARLabeling_ARToolKit l=new NyARLabeling_ARToolKit();l.setThresh(4);return l;}
+               // case 1:{return new NyLineLabeling();}
+               // }
+               return null;
+
+       }
+
+       private void startCapture()
+       {
+               try {
+                       capture.start();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       public static void main(String[] args)
+       {
+               try {
+                       SingleQrTest mainwin = new SingleQrTest();
+                       mainwin.setVisible(true);
+                       mainwin.startCapture();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+
+       }
+
+}
@@ -37,12 +37,11 @@ import jp.nyatla.nyartoolkit.core.types.*;
 import jp.nyatla.nyartoolkit.core.param.*;\r
 import jp.nyatla.nyartoolkit.core.*;\r
 import jp.nyatla.nyartoolkit.toys.x2.*;\r
-\r
 /**\r
  * 矩形座標をPCAではなく、頂点座標そのものからSquare位置を計算するクラス\r
  *\r
  */\r
-public class NyARQrCodeDetector implements INyARSquareDetector\r
+public class NyARVertexDetector implements INyARSquareDetector\r
 {\r
        private static final double VERTEX_FACTOR = 1.0;// 線検出のファクタ\r
 \r
@@ -64,7 +63,7 @@ public class NyARQrCodeDetector implements INyARSquareDetector
         * \r
         * @param i_param\r
         */\r
-       public NyARQrCodeDetector(NyARCameraDistortionFactor 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
index f0d5bb1..cfadf3a 100644 (file)
@@ -35,7 +35,6 @@ import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.core.NyARCode;\r
 import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
 import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
-import jp.nyatla.nyartoolkit.nymodel.x2.*;\r
 \r
 \r
 /**\r
index c11308a..8e5cc24 100644 (file)
@@ -73,7 +73,7 @@ public class JavaSimpleLite_X2 implements GLEventListener, JmfCaptureListener
        //NyARToolkit関係\r
        private GLNyARSingleDetectMarker_X2 _nya;\r
 \r
-       private GLNyARParam _ar_param;\r
+       private NyARParam _ar_param;\r
 \r
        /**\r
         * 立方体を書く\r
index bcad2e6..3d48cf9 100644 (file)
@@ -38,7 +38,6 @@ import jp.nyatla.nyartoolkit.core.*;
 import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
 import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
 import jp.nyatla.nyartoolkit.core.transmat.*;\r
-import jp.nyatla.nyartoolkit.nymodel.x2.*;\r
 \r
 \r
 /**\r
diff --git a/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARDetectMarker.java b/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARDetectMarker.java
deleted file mode 100644 (file)
index 9bf44e6..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/* \r
- * PROJECT: NyARToolkit JOGL utilities.\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.jogl.utils;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.NyARCode;\r
-import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
-import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
-import jp.nyatla.nyartoolkit.detector.NyARDetectMarker;\r
-\r
-/**\r
- * NyARSingleDetectMarkerにOpenGL向け関数を追加したもの\r
- */\r
-public class GLNyARDetectMarker extends NyARDetectMarker\r
-{\r
-       private NyARTransMatResult trans_mat_result = new NyARTransMatResult();\r
-\r
-       private double view_scale_factor = 0.025;\r
-\r
-       public GLNyARDetectMarker(NyARParam i_param, NyARCode[] i_code, double[] i_marker_width, int i_number_of_code) throws NyARException\r
-       {\r
-               super(i_param, i_code, i_marker_width, i_number_of_code);\r
-       }\r
-\r
-       public void setScaleFactor(double i_new_value)\r
-       {\r
-               view_scale_factor = i_new_value;\r
-       }\r
-\r
-       /**\r
-        * @param i_index\r
-        * マーカーのインデックス番号を指定します。 直前に実行したdetectMarkerLiteの戻り値未満かつ0以上である必要があります。\r
-        * @param o_result\r
-        * 結果値を格納する配列を指定してください。double[16]以上が必要です。\r
-        * @throws NyARException\r
-        */\r
-       public void getCameraViewRH(int i_index, double[] o_result) throws NyARException\r
-       {\r
-               // 座標を計算\r
-               this.getTransmationMatrix(i_index, this.trans_mat_result);\r
-               // 行列変換\r
-               final NyARTransMatResult mat = this.trans_mat_result;\r
-               o_result[0 + 0 * 4] = mat.m00; \r
-               o_result[0 + 1 * 4] = mat.m01;\r
-               o_result[0 + 2 * 4] = mat.m02;\r
-               o_result[0 + 3 * 4] = mat.m03;\r
-               o_result[1 + 0 * 4] = -mat.m10;\r
-               o_result[1 + 1 * 4] = -mat.m11;\r
-               o_result[1 + 2 * 4] = -mat.m12;\r
-               o_result[1 + 3 * 4] = -mat.m13;\r
-               o_result[2 + 0 * 4] = -mat.m20;\r
-               o_result[2 + 1 * 4] = -mat.m21;\r
-               o_result[2 + 2 * 4] = -mat.m22;\r
-               o_result[2 + 3 * 4] = -mat.m23;\r
-               o_result[3 + 0 * 4] = 0.0;\r
-               o_result[3 + 1 * 4] = 0.0;\r
-               o_result[3 + 2 * 4] = 0.0;\r
-               o_result[3 + 3 * 4] = 1.0;\r
-               if (view_scale_factor != 0.0) {\r
-                       o_result[12] *= view_scale_factor;\r
-                       o_result[13] *= view_scale_factor;\r
-                       o_result[14] *= view_scale_factor;\r
-               }\r
-               return;\r
-       }\r
-}\r
diff --git a/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java b/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARParam.java
deleted file mode 100644 (file)
index 416d1be..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/* \r
- * PROJECT: NyARToolkit JOGL utilities.\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.jogl.utils;\r
-\r
-import jp.nyatla.nyartoolkit.core.*;\r
-import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
-\r
-/**\r
- * NyARParamにOpenGL向け関数を追加したもの\r
- */\r
-public class GLNyARParam extends NyARParam\r
-{\r
-       private double view_distance_min = 0.1;//#define VIEW_DISTANCE_MIN              0.1                     // Objects closer to the camera than this will not be displayed.\r
-\r
-       private double view_distance_max = 100.0;//#define VIEW_DISTANCE_MAX            100.0           // Objects further away from the camera than this will not be displayed.\r
-\r
-       private double[] m_projection = null;\r
-\r
-       public void setViewDistanceMin(double i_new_value)\r
-       {\r
-               m_projection = null;//キャッシュ済変数初期化\r
-               view_distance_min = i_new_value;\r
-       }\r
-\r
-       public void setViewDistanceMax(double i_new_value)\r
-       {\r
-               m_projection = null;//キャッシュ済変数初期化\r
-               view_distance_max = i_new_value;\r
-       }\r
-\r
-       /**\r
-        * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])\r
-        * 関数の置き換え\r
-        * @param focalmin\r
-        * @param focalmax\r
-        * @return\r
-        */\r
-       public double[] getCameraFrustumRH()\r
-       {\r
-               //既に値がキャッシュされていたらそれを使う\r
-               if (m_projection != null) {\r
-                       return m_projection;\r
-               }\r
-               //無ければ計算\r
-               m_projection = new double[16];\r
-               NyARMat trans_mat = new NyARMat(3, 4);\r
-               NyARMat icpara_mat = new NyARMat(3, 4);\r
-               double[][] p = new double[3][3], q = new double[4][4];\r
-\r
-               int i, j;\r
-\r
-               final int width = this._screen_size.w;\r
-               final int height = this._screen_size.h;\r
-\r
-               this.getPerspectiveProjectionMatrix().decompMat(icpara_mat, trans_mat);\r
-\r
-               double[][] icpara = icpara_mat.getArray();\r
-               double[][] trans = trans_mat.getArray();\r
-               for (i = 0; i < 4; i++) {\r
-                       icpara[1][i] = (height - 1) * (icpara[2][i]) - icpara[1][i];\r
-               }\r
-\r
-               for (i = 0; i < 3; i++) {\r
-                       for (j = 0; j < 3; j++) {\r
-                               p[i][j] = icpara[i][j] / icpara[2][2];\r
-                       }\r
-               }\r
-               q[0][0] = (2.0 * p[0][0] / (width - 1));\r
-               q[0][1] = (2.0 * p[0][1] / (width - 1));\r
-               q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);\r
-               q[0][3] = 0.0;\r
-\r
-               q[1][0] = 0.0;\r
-               q[1][1] = -(2.0 * p[1][1] / (height - 1));\r
-               q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);\r
-               q[1][3] = 0.0;\r
-\r
-               q[2][0] = 0.0;\r
-               q[2][1] = 0.0;\r
-               q[2][2] = (view_distance_max + view_distance_min) / (view_distance_min - view_distance_max);\r
-               q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);\r
-\r
-               q[3][0] = 0.0;\r
-               q[3][1] = 0.0;\r
-               q[3][2] = -1.0;\r
-               q[3][3] = 0.0;\r
-\r
-               for (i = 0; i < 4; i++) { // Row.\r
-                       // First 3 columns of the current row.\r
-                       for (j = 0; j < 3; j++) { // Column.\r
-                               m_projection[i + j * 4] = q[i][0] * trans[0][j] + q[i][1] * trans[1][j] + q[i][2] * trans[2][j];\r
-                       }\r
-                       // Fourth column of the current row.\r
-                       m_projection[i + 3 * 4] = q[i][0] * trans[0][3] + q[i][1] * trans[1][3] + q[i][2] * trans[2][3] + q[i][3];\r
-               }\r
-               return m_projection;\r
-       }\r
-}\r
diff --git a/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java b/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARSingleDetectMarker.java
deleted file mode 100644 (file)
index c1d79c6..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/* \r
- * PROJECT: NyARToolkit JOGL utilities.\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.jogl.utils;\r
-\r
-import jp.nyatla.nyartoolkit.NyARException;\r
-import jp.nyatla.nyartoolkit.core.NyARCode;\r
-import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
-import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
-import jp.nyatla.nyartoolkit.detector.NyARSingleDetectMarker;\r
-\r
-\r
-/**\r
- * NyARSingleDetectMarkerにOpenGL向け関数を追加したもの\r
- */\r
-public class GLNyARSingleDetectMarker extends NyARSingleDetectMarker\r
-{\r
-       private NyARTransMatResult trans_mat_result = new NyARTransMatResult();\r
-\r
-       private double view_scale_factor = 0.025;// #define VIEW_SCALEFACTOR 0.025 // 1.0 ARToolKit unit becomes 0.025 of my OpenGL units.\r
-\r
-       public GLNyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width) throws NyARException\r
-       {\r
-               super(i_param, i_code, i_marker_width);\r
-       }\r
-\r
-       public void setScaleFactor(double i_new_value)\r
-       {\r
-               view_scale_factor = i_new_value;\r
-       }\r
-\r
-       // public static void arglCameraViewRH(const double para[3][4], GLdouble m_modelview[16], const double scale)\r
-       public double[] getCameraViewRH() throws NyARException\r
-       {\r
-               double[] result = new double[16];\r
-               getCameraViewRH(result);\r
-               return result;\r
-       }\r
-\r
-       /**\r
-        * \r
-        * @param o_result\r
-        * 結果値を格納する配列を指定してください。double[16]以上が必要です。\r
-        * @throws NyARException\r
-        */\r
-       public void getCameraViewRH(double[] o_result) throws NyARException\r
-       {\r
-               // 座標を計算\r
-               this.getTransmationMatrix(this.trans_mat_result);\r
-               // 行列変換\r
-               final NyARTransMatResult mat = this.trans_mat_result;\r
-               o_result[0 + 0 * 4] = mat.m00; // R1C1\r
-               o_result[0 + 1 * 4] = mat.m01; // R1C2\r
-               o_result[0 + 2 * 4] = mat.m02;\r
-               o_result[0 + 3 * 4] = mat.m03;\r
-               o_result[1 + 0 * 4] = -mat.m10; // R2\r
-               o_result[1 + 1 * 4] = -mat.m11;\r
-               o_result[1 + 2 * 4] = -mat.m12;\r
-               o_result[1 + 3 * 4] = -mat.m13;\r
-               o_result[2 + 0 * 4] = -mat.m20; // R3\r
-               o_result[2 + 1 * 4] = -mat.m21;\r
-               o_result[2 + 2 * 4] = -mat.m22;\r
-               o_result[2 + 3 * 4] = -mat.m23;\r
-               o_result[3 + 0 * 4] = 0.0;\r
-               o_result[3 + 1 * 4] = 0.0;\r
-               o_result[3 + 2 * 4] = 0.0;\r
-               o_result[3 + 3 * 4] = 1.0;\r
-               if (view_scale_factor != 0.0) {\r
-                       o_result[12] *= view_scale_factor;\r
-                       o_result[13] *= view_scale_factor;\r
-                       o_result[14] *= view_scale_factor;\r
-               }\r
-               return;\r
-       }\r
-}\r
index f26c2f9..eeeede4 100644 (file)
@@ -37,6 +37,10 @@ import java.nio.IntBuffer;
 import javax.media.opengl.GL;\r
 import javax.media.opengl.glu.GLU;\r
 \r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.NyARMat;\r
+import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
+import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 /**\r
  * NyARToolkit用のJOGL支援関数群\r
@@ -125,4 +129,121 @@ public class NyARGLUtil
                ByteBuffer buf = ByteBuffer.wrap(i_raster.getGLRgbArray());\r
                gl_.glDrawPixels(rsize.w,rsize.h, i_raster.getGLPixelFlag(), GL.GL_UNSIGNED_BYTE, buf);\r
        }\r
+       \r
+       private double view_scale_factor = 0.025;\r
+       private double view_distance_min = 0.1;//#define VIEW_DISTANCE_MIN              0.1                     // Objects closer to the camera than this will not be displayed.\r
+       private double view_distance_max = 100.0;//#define VIEW_DISTANCE_MAX            100.0           // Objects further away from the camera than this will not be displayed.\r
+\r
+       public void setScaleFactor(double i_new_value)\r
+       {\r
+               this.view_scale_factor = i_new_value;\r
+       }\r
+\r
+       public void setViewDistanceMin(double i_new_value)\r
+       {\r
+               this.view_distance_min = i_new_value;\r
+       }\r
+\r
+       public void setViewDistanceMax(double i_new_value)\r
+       {\r
+               this.view_distance_max = i_new_value;\r
+       }\r
+\r
+       /**\r
+        * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])\r
+        * 関数の置き換え\r
+        * NyARParamからOpenGLのProjectionを作成します。\r
+        * @param i_arparam\r
+        * @param o_gl_projection\r
+        * double[16]を指定して下さい。\r
+        */\r
+       public void toCameraFrustumRH(NyARParam i_arparam,double[] o_gl_projection)\r
+       {\r
+               NyARMat trans_mat = new NyARMat(3, 4);\r
+               NyARMat icpara_mat = new NyARMat(3, 4);\r
+               double[][] p = new double[3][3], q = new double[4][4];\r
+               int i, j;\r
+\r
+               final NyARIntSize size=i_arparam.getScreenSize();\r
+               final int width = size.w;\r
+               final int height = size.h;\r
+               \r
+               i_arparam.getPerspectiveProjectionMatrix().decompMat(icpara_mat, trans_mat);\r
+\r
+               double[][] icpara = icpara_mat.getArray();\r
+               double[][] trans = trans_mat.getArray();\r
+               for (i = 0; i < 4; i++) {\r
+                       icpara[1][i] = (height - 1) * (icpara[2][i]) - icpara[1][i];\r
+               }\r
+\r
+               for (i = 0; i < 3; i++) {\r
+                       for (j = 0; j < 3; j++) {\r
+                               p[i][j] = icpara[i][j] / icpara[2][2];\r
+                       }\r
+               }\r
+               q[0][0] = (2.0 * p[0][0] / (width - 1));\r
+               q[0][1] = (2.0 * p[0][1] / (width - 1));\r
+               q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);\r
+               q[0][3] = 0.0;\r
+\r
+               q[1][0] = 0.0;\r
+               q[1][1] = -(2.0 * p[1][1] / (height - 1));\r
+               q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);\r
+               q[1][3] = 0.0;\r
+\r
+               q[2][0] = 0.0;\r
+               q[2][1] = 0.0;\r
+               q[2][2] = (view_distance_max + view_distance_min) / (view_distance_min - view_distance_max);\r
+               q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);\r
+\r
+               q[3][0] = 0.0;\r
+               q[3][1] = 0.0;\r
+               q[3][2] = -1.0;\r
+               q[3][3] = 0.0;\r
+\r
+               for (i = 0; i < 4; i++) { // Row.\r
+                       // First 3 columns of the current row.\r
+                       for (j = 0; j < 3; j++) { // Column.\r
+                               o_gl_projection[i + j * 4] = q[i][0] * trans[0][j] + q[i][1] * trans[1][j] + q[i][2] * trans[2][j];\r
+                       }\r
+                       // Fourth column of the current row.\r
+                       o_gl_projection[i + 3 * 4] = q[i][0] * trans[0][3] + q[i][1] * trans[1][3] + q[i][2] * trans[2][3] + q[i][3];\r
+               }\r
+               return;\r
+       }\r
+       \r
+       \r
+       \r
+       /**\r
+        * NyARTransMatResultをOpenGLの行列へ変換します。\r
+        * @param i_ny_result\r
+        * @param o_gl_result\r
+        * @throws NyARException\r
+        */\r
+       public void toCameraViewRH(NyARTransMatResult i_ny_result, double[] o_gl_result) throws NyARException\r
+       {\r
+               o_gl_result[0 + 0 * 4] = i_ny_result.m00; \r
+               o_gl_result[0 + 1 * 4] = i_ny_result.m01;\r
+               o_gl_result[0 + 2 * 4] = i_ny_result.m02;\r
+               o_gl_result[0 + 3 * 4] = i_ny_result.m03;\r
+               o_gl_result[1 + 0 * 4] = -i_ny_result.m10;\r
+               o_gl_result[1 + 1 * 4] = -i_ny_result.m11;\r
+               o_gl_result[1 + 2 * 4] = -i_ny_result.m12;\r
+               o_gl_result[1 + 3 * 4] = -i_ny_result.m13;\r
+               o_gl_result[2 + 0 * 4] = -i_ny_result.m20;\r
+               o_gl_result[2 + 1 * 4] = -i_ny_result.m21;\r
+               o_gl_result[2 + 2 * 4] = -i_ny_result.m22;\r
+               o_gl_result[2 + 3 * 4] = -i_ny_result.m23;\r
+               o_gl_result[3 + 0 * 4] = 0.0;\r
+               o_gl_result[3 + 1 * 4] = 0.0;\r
+               o_gl_result[3 + 2 * 4] = 0.0;\r
+               o_gl_result[3 + 3 * 4] = 1.0;\r
+               if (view_scale_factor != 0.0) {\r
+                       o_gl_result[12] *= view_scale_factor;\r
+                       o_gl_result[13] *= view_scale_factor;\r
+                       o_gl_result[14] *= view_scale_factor;\r
+               }\r
+               return;\r
+       }       \r
+       \r
 }\r
index 78f18e9..b8a2b5b 100644 (file)
@@ -35,14 +35,20 @@ import jp.nyatla.nyartoolkit.core.types.*;
 /**\r
  * ARMarkerInfoに相当するクラス。 矩形情報を保持します。\r
  * \r
+ * directionは方角を表します。\r
+ * 決定しないときはDIRECTION_UNKNOWNを設定してください。\r
+ * \r
  */\r
 public class NyARSquare\r
 {\r
+       public final static int DIRECTION_UNKNOWN=-1;\r
+       public int direction;\r
        public NyARLinear[] line = new NyARLinear[4];\r
        public NyARDoublePoint2d[] sqvertex = new NyARDoublePoint2d[4];\r
        public NyARIntPoint[] imvertex = new NyARIntPoint[4];\r
        public NyARSquare()\r
        {\r
+               this.direction=DIRECTION_UNKNOWN;\r
                for(int i=0;i<4;i++){\r
                        this.sqvertex[i]=new NyARDoublePoint2d();\r
                        this.imvertex[i]=new NyARIntPoint();\r
index 1a385a3..ac051ab 100644 (file)
@@ -104,9 +104,9 @@ public class NyARSquareDetector implements INyARSquareDetector
        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
-        * \r
+        * arDetectMarker2を基にした関数\r
+        * この関数はNyARSquare要素のうち、directionを除くパラメータを取得して返します。\r
+        * directionの確定は行いません。\r
         * @param i_raster\r
         * 解析する2値ラスタイメージを指定します。\r
         * @param o_square_stack\r
@@ -394,7 +394,8 @@ public class NyARSquareDetector implements INyARSquareDetector
 \r
 \r
 /**\r
- * ラベル同士の重なり(内包関係)を調べるクラスです。 ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。\r
+ * ラベル同士の重なり(内包関係)を調べるクラスです。 \r
+ * ラベルリストに内包するラベルを蓄積し、それにターゲットのラベルが内包されているか を確認します。\r
  */\r
 class OverlapChecker\r
 {\r
@@ -35,13 +35,13 @@ import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;
 import jp.nyatla.nyartoolkit.core.rasterreader.NyARBufferReader;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 \r
-public final class NyARGlayscaleRaster extends NyARRaster_BasicClass\r
+public final class NyARGrayscaleRaster extends NyARRaster_BasicClass\r
 {\r
 \r
        protected int[][] _ref_buf;\r
        private INyARBufferReader _buffer_reader;\r
        \r
-       public NyARGlayscaleRaster(int i_width, int i_height)\r
+       public NyARGrayscaleRaster(int i_width, int i_height)\r
        {\r
                super(new NyARIntSize(i_width,i_height));\r
                this._ref_buf = new int[i_height][i_width];\r
index 29f4920..ba16833 100644 (file)
@@ -36,5 +36,5 @@ import jp.nyatla.nyartoolkit.core.raster.*;
 \r
 public interface INyARRasterFilter_GsToBin\r
 {\r
-       public void doFilter(NyARGlayscaleRaster i_input, NyARBinRaster i_output) throws NyARException;\r
+       public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException;\r
 }\r
index 0fdf48c..c818c2d 100644 (file)
@@ -41,5 +41,5 @@ import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;
  */\r
 public interface INyARRasterFilter_RgbToGs\r
 {\r
-       public void doFilter(INyARRgbRaster i_input, NyARGlayscaleRaster i_output) throws NyARException;\r
+       public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException;\r
 }\r
index 1a83b0c..58f73d8 100644 (file)
@@ -44,7 +44,7 @@ public class NyARRasterFilter_AreaAverage implements INyARRasterFilter_GsToBin
 {\r
        private int _area = 8;\r
 \r
-       public void doFilter(NyARGlayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
+       public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
        {\r
                final NyARIntSize size = i_output.getSize();\r
                final int[][] out_buf = (int[][]) i_output.getBufferReader().getBuffer();\r
index 0ba8de8..f4f3615 100644 (file)
@@ -49,7 +49,7 @@ public class NyARRasterFilter_Threshold implements INyARRasterFilter_GsToBin
                this._threshold = i_threshold;\r
        }\r
 \r
-       public void doFilter(NyARGlayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
+       public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
        {\r
                assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
 \r
index c9da6f5..f349e12 100644 (file)
@@ -40,7 +40,7 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
 \r
 public class NyARRasterFilter_RgbAve implements INyARRasterFilter_RgbToGs\r
 {\r
-       public void doFilter(INyARRgbRaster i_input, NyARGlayscaleRaster i_output) throws NyARException\r
+       public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
        {\r
                INyARBufferReader in_buffer_reader=i_input.getBufferReader();   \r
                INyARBufferReader out_buffer_reader=i_output.getBufferReader(); \r
index d0e21e2..5f11bc0 100644 (file)
@@ -40,14 +40,14 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
 \r
 public class NyARRasterFilter_RgbMul implements INyARRasterFilter_RgbToGs\r
 {\r
-       public void doFilter(INyARRgbRaster i_input, NyARGlayscaleRaster i_output) throws NyARException\r
+       public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
        {\r
                INyARBufferReader in_buffer_reader=i_input.getBufferReader();   \r
                INyARBufferReader out_buffer_reader=i_output.getBufferReader();                 \r
                assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
 \r
-               int[][] out_buf = (int[][]) in_buffer_reader.getBuffer();\r
-               byte[] in_buf = (byte[]) out_buffer_reader.getBuffer();\r
+               int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();\r
+               byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();\r
 \r
                NyARIntSize size = i_output.getSize();\r
                switch (in_buffer_reader.getBufferType()) {\r
index a2b6405..742133b 100644 (file)
@@ -40,7 +40,7 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
 \r
 public class NyARRasterFilter_RgbOr implements INyARRasterFilter_RgbToGs\r
 {\r
-       public void doFilter(INyARRgbRaster i_input, NyARGlayscaleRaster i_output) throws NyARException\r
+       public void doFilter(INyARRgbRaster i_input, NyARGrayscaleRaster i_output) throws NyARException\r
        {\r
                INyARBufferReader in_buffer_reader=i_input.getBufferReader();   \r
                INyARBufferReader out_buffer_reader=i_output.getBufferReader();                 \r
index 6306ae0..ebc4988 100644 (file)
@@ -120,7 +120,7 @@ public class LabelingBufferdImage extends BufferedImage
 \r
 \r
 \r
-       public void drawImage(NyARGlayscaleRaster i_raster) throws NyARException\r
+       public void drawImage(NyARGrayscaleRaster i_raster) throws NyARException\r
        {\r
                assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8);\r
 \r
diff --git a/test/jp/nyatla/nyartoolkit/dev/CopyOfLabelingCamera.java b/test/jp/nyatla/nyartoolkit/dev/CopyOfLabelingCamera.java
deleted file mode 100644 (file)
index 2f7d9e8..0000000
+++ /dev/null
@@ -1,920 +0,0 @@
-/* このソースは実験用のソースです。
- * 動いたり動かなかったりします。
- * 
- */
-package jp.nyatla.nyartoolkit.dev;
-
-import javax.media.*;
-
-import javax.media.util.BufferToImage;
-import javax.media.format.*;
-
-import jp.nyatla.nyartoolkit.NyARException;
-import jp.nyatla.nyartoolkit.jmf.utils.*;
-import jp.nyatla.nyartoolkit.core.*;
-import jp.nyatla.nyartoolkit.toys.x2.NyARLabeling_ARToolKit_X2;
-import jp.nyatla.nyartoolkit.toys.x2.NyARTransMat_X2;
-
-import java.awt.*;
-
-import jp.nyatla.nyartoolkit.core.INyARSquareDetector;
-import jp.nyatla.nyartoolkit.core.labeling.*;
-import jp.nyatla.nyartoolkit.core.match.*;
-import jp.nyatla.nyartoolkit.core.param.*;
-import jp.nyatla.nyartoolkit.core.pickup.*;
-import jp.nyatla.nyartoolkit.core.raster.*;
-import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;
-import jp.nyatla.nyartoolkit.core.rasterfilter.*;
-import jp.nyatla.nyartoolkit.core2.rasteranalyzer.*;
-import jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold.*;
-import jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin.*;
-import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.NyARRasterFilter_RgbAve;
-import jp.nyatla.utils.NyObjectStack;
-import jp.nyatla.utils.j2se.LabelingBufferdImage;
-import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
-import jp.nyatla.nyartoolkit.core.transmat.*;
-import jp.nyatla.nyartoolkit.core.types.*;
-
-
-class NyARMkVertexStack extends NyObjectStack
-{
-       public NyARMkVertexStack(int i_length)
-       {
-               super(new NyARIntPoint[i_length][]);
-
-       }
-
-       protected void onReservRequest(int i_start, int i_end, Object[] i_buffer)
-       {
-               for (int i = i_start; i < i_end; i++) {
-                       i_buffer[i] = NyARIntPoint.createArray(4);
-               }
-       }
-}
-/**
- * QRコードのシンボルを結びつける偉いクラス
- *
- */
-class NyQrCodeSymbolBinder
-{
-       LabelingBufferdImage bimg;
-       
-       NyARIntPoint[][] _sqare;
-       /**
-        * 最小の三角形を構成する頂点セットを得る
-        * @param i_s0
-        * @param i_s1
-        * @param i_s2
-        * @param o_vertex
-        */
-       public static void getMinimumTriangleVertex(NyARIntPoint[][] i_sqare,int[] o_vertex_id)
-       {
-               //辺の長さが最小になる頂点の組合せを探す
-               int d;
-               int x,y;
-               int dmax=0x7fffffff;
-               for(int i=0;i<4;i++)
-               {
-                       for(int i2=0;i2<4;i2++)
-                       {
-                               for(int i3=0;i3<4;i3++){
-                                       x=i_sqare[0][i].x-i_sqare[2][i3].x;
-                                       y=i_sqare[0][i].y-i_sqare[2][i3].y;
-                                       d=x*x+y*y;
-                                       x=i_sqare[1][i2].x-i_sqare[2][i3].x;
-                                       y=i_sqare[1][i2].y-i_sqare[2][i3].y;
-                                       d+=x*x+y*y;
-                                       x=i_sqare[1][i2].x-i_sqare[0][i].x;
-                                       y=i_sqare[1][i2].y-i_sqare[0][i].y;
-                                       d+=x*x+y*y;
-                                       if(d<dmax){
-                                               dmax=d;
-                                               o_vertex_id[0]=i;                                       
-                                               o_vertex_id[1]=i2;
-                                               o_vertex_id[2]=i3;
-                                       }
-                               }
-                       }
-               }
-               return;
-       }
-       /**
-        * 2矩形の頂点距離が最低の組合せを探す
-        * @param i_sqare
-        * @param o_vertex_id
-        */
-       public static void getMinimumLineVertex(NyARIntPoint[] i_sqare0,NyARIntPoint[] i_sqare1,int[] o_vertex_id)
-       {
-               //辺の長さが最小になる頂点の組合せを探す
-               int d;
-               int x,y;
-               int dmax=0x7fffffff;
-               for(int i=0;i<4;i++)
-               {
-                       for(int i2=0;i2<4;i2++)
-                       {
-                               x=i_sqare1[i2].x-i_sqare0[i].x;
-                               y=i_sqare1[i2].y-i_sqare0[i].y;
-                               d=x*x+y*y;
-                               if(d<dmax){
-                                       dmax=d;
-                                       o_vertex_id[0]=i;                                       
-                                       o_vertex_id[1]=i2;
-                               }
-                       }
-               }
-               return;
-       }       
-       
-       /**
-        * キーシンボルのインデックスを得る
-        * @param i_sqare
-        * @param i_vertex_id
-        * 最小三角形の頂点IDセット
-        * @return
-        */
-       public static int getKeySymble(NyARIntPoint[][] i_sqare,int[] i_vertex_id)
-       {
-               //シンボルグループの重心を計算
-               int cx,cy;
-               cx=cy=0;
-               for(int i=0;i<3;i++)
-               {
-                       final NyARIntPoint[] sq_ptr=i_sqare[i];
-                       cx+=sq_ptr[0].x;                        
-                       cx+=sq_ptr[1].x;                        
-                       cx+=sq_ptr[2].x;                        
-                       cx+=sq_ptr[3].x;                        
-                       cy+=sq_ptr[0].y;                        
-                       cy+=sq_ptr[1].y;                        
-                       cy+=sq_ptr[2].y;                        
-                       cy+=sq_ptr[3].y;                        
-               }
-               cx/=12;
-               cy/=12; 
-               //前段で探した頂点候補のうち、最も重心に近いものが中心シンボルの内対角点
-               int key_symble_idx=0;
-               int x=i_sqare[0][i_vertex_id[0]].x-cx;
-               int y=i_sqare[0][i_vertex_id[0]].y-cy;
-               int dmax=x*x+y*y;
-               for(int i=1;i<3;i++){
-                       x=i_sqare[i][i_vertex_id[i]].x-cx;
-                       y=i_sqare[i][i_vertex_id[i]].y-cy;
-                       final int d=x*x+y*y;
-                       if(d<dmax){
-                               dmax=d;
-                               key_symble_idx=i;
-                       }
-               }
-               return key_symble_idx;
-       }
-       public void getLineFromVertex(NyARIntPoint i_v1,NyARIntPoint i_v2)
-       {
-               double sx=i_v1.x-i_v2.x;
-               double sy=i_v1.y-i_v2.y;
-               double k=sy/sx;
-               double b=i_v2.y-k*i_v2.x;
-               Graphics g=this.bimg.getGraphics();
-               g.setColor(Color.red);
-               g.drawLine(0,(int)b,320,(int)(k*320+b));
-               
-       }
-       /**
-        *
-        * @param i_sq
-        * @param o_sq
-        * @return
-        */
-       public boolean margeEdge(NyARIntPoint[][] i_sq,NyARSquare o_sq)
-       {
-               int[] minimum_triangle_vertex=new int[3];
-               int[] minimum_line_vertex=new int[2];
-
-               //辺の長さが最小になる頂点の組合せを探す
-               getMinimumTriangleVertex(i_sq,minimum_triangle_vertex);
-               
-               //キーシンボルのインデクス番号を得る
-               int key_simble_idx=getKeySymble(i_sq,minimum_triangle_vertex);
-               
-               //エッジシンボルのインデックス番号を決める
-               int symbol_e1_idx=(key_simble_idx+1)%3;
-               int symbol_e2_idx=(key_simble_idx+2)%3;
-               
-               //エッジシンボル間で最短距離を取る頂点ペアを取る
-               //(角度を低くするとエラーが出やすい。対角線との類似性を確認する方法のほうがいい。多分)
-               getMinimumLineVertex(i_sq[symbol_e1_idx],i_sq[symbol_e2_idx],minimum_line_vertex);
-               
-               //内対角を外対角に変換
-               int lv1=(minimum_line_vertex[0]+2)%4;
-               int lv2=(minimum_line_vertex[1]+2)%4;
-               int kv =(minimum_triangle_vertex[key_simble_idx]+2)%4;
-
-               getLineFromVertex(i_sq[symbol_e1_idx][(lv1+1)%4],i_sq[symbol_e1_idx][lv1]);
-               getLineFromVertex(i_sq[symbol_e1_idx][(lv1+3)%4],i_sq[symbol_e1_idx][lv1]);
-               getLineFromVertex(i_sq[symbol_e2_idx][(lv2+1)%4],i_sq[symbol_e2_idx][lv2]);
-               getLineFromVertex(i_sq[symbol_e2_idx][(lv2+3)%4],i_sq[symbol_e2_idx][lv2]);
-               getLineFromVertex(i_sq[key_simble_idx][(kv+2)%4],i_sq[key_simble_idx][kv]);
-                               
-               
-               Graphics g=this.bimg.getGraphics();
-               //内対角に緑の点を打つ
-               g.setColor(Color.green);
-               g.fillRect(i_sq[key_simble_idx][minimum_triangle_vertex[key_simble_idx]].x-2,i_sq[key_simble_idx][minimum_triangle_vertex[key_simble_idx]].y-2,4,4);
-               g.fillRect(i_sq[symbol_e1_idx][minimum_line_vertex[0]].x-2,i_sq[symbol_e1_idx][minimum_line_vertex[0]].y-2,4,4);
-               g.fillRect(i_sq[symbol_e2_idx][minimum_line_vertex[1]].x-2,i_sq[symbol_e2_idx][minimum_line_vertex[1]].y-2,4,4);
-               
-               
-               //中央の中心エッジから最も遠い点が
-               //両端のエッジも探す
-               
-               
-               
-
-//             this.bimg.getGraphics().fillRect(i_sq[edge1_id][vid1_id].x,i_sq[edge1_id][vid1_id].y,5,5);
-               
-               for (int i = 0; i <3; i++) {
-                       int[] xp=new int[4]; 
-                       int[] yp=new int[4]; 
-                       for(int i2=0;i2<4;i2++){
-                               xp[i2]=i_sq[i][i2].x;
-                               yp[i2]=i_sq[i][i2].y;
-                       }
-                       this.bimg.getGraphics().setColor(Color.RED);
-                       this.bimg.getGraphics().drawPolygon(xp, yp,4);
-               }               
-               
-               
-               return false;
-               
-               
-               
-               
-
-               
-       }       
-       
-       
-       
-       
-}
-
-
-/**
- * 矩形座標をPCAではなく、頂点座標そのものからSquare位置を計算するクラス
- * 
- */
-class NyARQRCodeDetector implements INyARSquareDetector
-{
-       LabelingBufferdImage bimg;
-       private static final double VERTEX_FACTOR = 2.0;// 線検出のファクタ
-
-       private static final int AR_AREA_MAX = 100000;// #define AR_AREA_MAX 100000
-
-       private static final int AR_AREA_MIN = 70;// #define AR_AREA_MIN 70
-
-       private final int _width;
-
-       private final int _height;
-
-       private final NyARLabeling_ARToolKit_X2 _labeling;
-
-       private final NyARLabelingImage _limage;
-
-       private final NyARCameraDistortionFactor _dist_factor_ref;
-
-       /**
-        * 最大i_squre_max個のマーカーを検出するクラスを作成する。
-        * 
-        * @param i_param
-        */
-       public NyARQRCodeDetector(NyARCameraDistortionFactor i_dist_factor_ref, NyARIntSize i_size) throws NyARException
-       {
-               this._width = i_size.w;
-               this._height = i_size.h;
-               this._dist_factor_ref = i_dist_factor_ref;
-               this._labeling = new NyARLabeling_ARToolKit_X2();
-               this._limage = new NyARLabelingImage(this._width, this._height);
-               this._labeling.attachDestination(this._limage);
-
-               // 輪郭の最大長は画面に映りうる最大の長方形サイズ。
-               int number_of_coord = (this._width + this._height) * 2;
-
-               // 輪郭バッファは頂点変換をするので、輪郭バッファの2倍取る。
-               this._max_coord = number_of_coord;
-               this._xcoord = new int[number_of_coord * 2];
-               this._ycoord = new int[number_of_coord * 2];
-       }
-
-       private final int _max_coord;
-
-       private final int[] _xcoord;
-
-       private final int[] _ycoord;
-
-       private void normalizeCoord(int[] i_coord_x, int[] i_coord_y, int i_index, int i_coord_num)
-       {
-               // vertex1を境界にして、後方に配列を連結
-               System.arraycopy(i_coord_x, 1, i_coord_x, i_coord_num, i_index);
-               System.arraycopy(i_coord_y, 1, i_coord_y, i_coord_num, i_index);
-       }
-
-       private final int[] __detectMarker_mkvertex = new int[5];
-
-       /**
-        * ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double
-        * factor, int *marker_num ) 関数の代替品 ラベリング情報からマーカー一覧を作成してo_marker_listを更新します。 関数はo_marker_listに重なりを除外したマーカーリストを作成します。
-        * 
-        * @param i_raster
-        * 解析する2値ラスタイメージを指定します。
-        * @param o_square_stack
-        * 抽出した正方形候補を格納するリスト
-        * @throws NyARException
-        */
-       public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException
-       {
-               final INyARLabeling labeling_proc = this._labeling;
-               final NyARLabelingImage limage = this._limage;
-
-               // 初期化
-
-               // マーカーホルダをリセット
-               o_square_stack.clear();
-
-               // ラベリング
-               labeling_proc.labeling(i_raster);
-
-               // ラベル数が0ならここまで
-               final int label_num = limage.getLabelStack().getLength();
-               if (label_num < 1) {
-                       return;
-               }
-
-               final NyARLabelingLabelStack stack = limage.getLabelStack();
-               final NyARLabelingLabel[] labels = (NyARLabelingLabel[]) stack.getArray();
-
-               // ラベルを大きい順に整列
-               stack.sortByArea();
-
-               // デカいラベルを読み飛ばし
-               int i;
-               for (i = 0; i < label_num; i++) {
-                       // 検査対象内のラベルサイズになるまで無視
-                       if (labels[i].area <= AR_AREA_MAX) {
-                               break;
-                       }
-               }
-               
-               final int xsize = this._width;
-               final int ysize = this._height;
-               final int[] xcoord = this._xcoord;
-               final int[] ycoord = this._ycoord;
-               final int coord_max = this._max_coord;
-               final int[] mkvertex = this.__detectMarker_mkvertex;
-               final int[][] buf = (int[][]) limage.getBufferReader().getBuffer();
-               final int[] indextable = limage.getIndexArray();
-               int coord_num;
-               int label_area;
-               NyARLabelingLabel label_pt;
-               NyARMkVertexStack vertex_stack=new NyARMkVertexStack(100);
-
-               for (; i < label_num; i++) {
-                       label_pt = labels[i];
-                       label_area = label_pt.area;
-                       // 検査対象サイズよりも小さくなったら終了
-                       if (label_area < AR_AREA_MIN) {
-                               break;
-                       }
-                       // クリップ領域が画面の枠に接していれば除外
-                       if (label_pt.clip_l == 1 || label_pt.clip_r == xsize - 2) {// if(wclip[i*4+0] == 1 || wclip[i*4+1] ==xsize-2){
-                               continue;
-                       }
-                       if (label_pt.clip_t == 1 || label_pt.clip_b == ysize - 2) {// if( wclip[i*4+2] == 1 || wclip[i*4+3] ==ysize-2){
-                               continue;
-                       }
-                       // 特徴点候補であるかを確認する。
-                       if (!hasQrEdgeFeature(buf, indextable, label_pt)) {
-                               continue;
-                       }
-
-                       // 輪郭を取得
-                       coord_num = limage.getContour(i, coord_max, xcoord, ycoord);
-                       if (coord_num == coord_max) {
-                               // 輪郭が大きすぎる。
-                               continue;
-                       }
-                       // 頂点候補のインデクスを取得
-                       final int vertex1 = scanVertex(xcoord, ycoord, coord_num);
-
-                       // 頂点候補(vertex1)を先頭に並べなおした配列を作成する。
-                       normalizeCoord(xcoord, ycoord, vertex1, coord_num);
-
-
-                       // 頂点情報を取得
-                       if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex)) {
-//                             o_square_stack.pop();// 頂点の取得が出来なかったので破棄
-                               continue;
-                       }
-                       // 領域を準備する。
-                       NyARIntPoint[] vertex_ptr = (NyARIntPoint[]) vertex_stack.prePush();
-                       vertex_ptr[0].x=xcoord[mkvertex[0]];
-                       vertex_ptr[0].y=ycoord[mkvertex[0]];
-                       vertex_ptr[1].x=xcoord[mkvertex[1]];
-                       vertex_ptr[1].y=ycoord[mkvertex[1]];
-                       vertex_ptr[2].x=xcoord[mkvertex[2]];
-                       vertex_ptr[2].y=ycoord[mkvertex[2]];
-                       vertex_ptr[3].x=xcoord[mkvertex[3]];
-                       vertex_ptr[3].y=ycoord[mkvertex[3]];
-
-//                     // 頂点情報からライン情報を作っちゃう
-//                     getSquare(mkvertex, xcoord, ycoord, vertex_ptr);
-               }
-               bindQrcodeEdge(vertex_stack);
-               //エッジ同士の相関関係をしらべる。
-
-               return;
-       }
-       /**
-        *
-        * @param i_sq
-        * @param o_sq
-        * @return
-        */
-       public boolean margeEdge(NyARIntPoint[][] i_sq,NyARSquare o_sq)
-       {
-               NyQrCodeSymbolBinder binder=new NyQrCodeSymbolBinder();
-               binder.bimg=this.bimg;
-               binder.margeEdge(i_sq, o_sq);
-
-               return false;
-               
-               
-               
-               
-       }
-       /**
-        * QRコードのエッジペアを作る
-        * @param i_square_stack
-        */
-       public void bindQrcodeEdge(NyARMkVertexStack i_square_stack)
-       {
-               
-               NyARIntPoint[] sq_ptr1,sq_ptr2,sq_ptr3;
-               int number_of_edge=i_square_stack.getLength();
-               if(number_of_edge<3){
-                       return;
-               }
-               NyARIntPoint[][] sa=(NyARIntPoint[][])i_square_stack.getArray();
-               for(int i=0;i<number_of_edge;i++)
-               {       
-                       for(int i2=i+1;i2<number_of_edge;i2++)
-                       {
-                               sq_ptr2=sa[i2];
-                               for(int i3=i2+1;i3<number_of_edge;i3++){
-                                       sq_ptr3=sa[i3];
-                                       //3個のエッジの関連性を確認する。
-                                       margeEdge(sa,null);
-                               }
-                               //
-                       }
-               }
-       }
-       /**
-        * 2つの頂点座標を結ぶ直線から、NyARLinearを計算する。
-        * 
-        * @param i_v1
-        * @param i_v2
-        * @param o_line
-        */
-       final private void getLine(NyARDoublePoint2d i_v1, NyARDoublePoint2d i_v2, NyARLinear o_line)
-       {
-               final double x = i_v1.x - i_v2.x;
-               final double y = i_v1.y - i_v2.y;
-               final double x2 = x * x;
-               final double y2 = y * y;
-               final double rise_ = Math.sqrt(x2 / (x2 + y2));
-               o_line.rise = rise_;
-               o_line.run = Math.sqrt(y2 / (x2 + y2));
-               if (x < 0) {
-                       if (y < 0) {
-                               o_line.rise = -o_line.rise;
-                       } else {
-                               o_line.rise = -o_line.rise;
-                               o_line.run = -o_line.run;
-                       }
-               } else {
-                       if (y < 0) {
-                               o_line.rise = -o_line.rise;
-                               o_line.run = -o_line.run;
-                       } else {
-                               o_line.rise = -o_line.rise;
-                       }
-               }
-               o_line.intercept = (i_v1.y + (o_line.run / o_line.rise) * (i_v1.x)) * rise_;
-
-       }
-
-       private void getSquare(int[] i_mkvertex, int[] i_xcoord, int[] i_ycoord, NyARSquare o_square)
-       {
-               final NyARCameraDistortionFactor dist_factor = this._dist_factor_ref;
-               final NyARDoublePoint2d[] vertex = o_square.sqvertex;
-
-               NyARIntPoint[] imvertex_ptr=o_square.imvertex;
-               NyARIntPoint wk_vertex;
-               //頂点座標取得
-               for (int i = 0; i < 4; i++) {
-                       final int idx = i_mkvertex[i];
-                       imvertex_ptr[i].x = i_xcoord[idx];
-                       imvertex_ptr[i].y = i_ycoord[idx];
-               }
-               // 歪み補正
-               for (int i = 0; i < 4; i++) {
-                       dist_factor.observ2Ideal(imvertex_ptr[i].x,imvertex_ptr[i].y, vertex[i]);
-               }
-               // ライン計算
-               getLine(vertex[1], vertex[0], o_square.line[0]);
-               getLine(vertex[2], vertex[1], o_square.line[1]);
-               getLine(vertex[3], vertex[2], o_square.line[2]);
-               getLine(vertex[0], vertex[3], o_square.line[3]);
-               return;
-       }
-
-       /**
-        * 辺からの対角線が最長になる点を対角線候補として返す。
-        * 
-        * @param i_xcoord
-        * @param i_ycoord
-        * @param i_coord_num
-        * @return
-        */
-       private int scanVertex(int[] i_xcoord, int[] i_ycoord, int i_coord_num)
-       {
-               final int sx = i_xcoord[0];
-               final int sy = i_ycoord[0];
-               int d = 0;
-               int w, x, y;
-               int ret = 0;
-               for (int i = 1; i < i_coord_num; i++) {
-                       x = i_xcoord[i] - sx;
-                       y = i_ycoord[i] - sy;
-                       w = x * x + y * y;
-                       if (w > d) {
-                               d = w;
-                               ret = i;
-                       }
-                       // ここでうまく終了条件入れられないかな。
-               }
-               return ret;
-       }
-
-       private final NyARVertexCounter __getSquareVertex_wv1 = new NyARVertexCounter();
-
-       private final NyARVertexCounter __getSquareVertex_wv2 = new NyARVertexCounter();
-
-       /**
-        * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor ) 関数の代替関数 OPTIMIZED STEP [450->415] o_squareに頂点情報をセットします。
-        * 
-        * @param i_x_coord
-        * @param i_y_coord
-        * @param i_vertex1_index
-        * @param i_coord_num
-        * @param i_area
-        * @param o_vertex
-        * 要素数はint[4]である事
-        * @return
-        */
-       private boolean getSquareVertex(int[] i_x_coord, int[] i_y_coord, int i_vertex1_index, int i_coord_num, int i_area, int[] o_vertex)
-       {
-               final NyARVertexCounter wv1 = this.__getSquareVertex_wv1;
-               final NyARVertexCounter wv2 = this.__getSquareVertex_wv2;
-               final int end_of_coord = i_vertex1_index + i_coord_num - 1;
-               final int sx = i_x_coord[i_vertex1_index];// sx = marker_info2->x_coord[0];
-               final int sy = i_y_coord[i_vertex1_index];// sy = marker_info2->y_coord[0];
-               int dmax = 0;
-               int v1 = i_vertex1_index;
-               for (int i = 1 + i_vertex1_index; i < end_of_coord; i++) {// for(i=1;i<marker_info2->coord_num-1;i++)
-                       // {
-                       final int d = (i_x_coord[i] - sx) * (i_x_coord[i] - sx) + (i_y_coord[i] - sy) * (i_y_coord[i] - sy);
-                       if (d > dmax) {
-                               dmax = d;
-                               v1 = i;
-                       }
-               }
-               final double thresh = (i_area / 0.75) * 0.01 * VERTEX_FACTOR;
-
-               o_vertex[0] = i_vertex1_index;
-
-               if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v1, thresh)) { // if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,0,v1,thresh,wv1,&wvnum1)<
-                       // 0 ) {
-                       return false;
-               }
-               if (!wv2.getVertex(i_x_coord, i_y_coord, v1, end_of_coord, thresh)) {// if(get_vertex(marker_info2->x_coord,marker_info2->y_coord,v1,marker_info2->coord_num-1,thresh,wv2,&wvnum2)
-                       // < 0) {
-                       return false;
-               }
-
-               int v2;
-               if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {// if(wvnum1 == 1 && wvnum2== 1) {
-                       o_vertex[1] = wv1.vertex[0];
-                       o_vertex[2] = v1;
-                       o_vertex[3] = wv2.vertex[0];
-               } else if (wv1.number_of_vertex > 1 && wv2.number_of_vertex == 0) {// }else if( wvnum1 > 1 && wvnum2== 0) {
-                       // 頂点位置を、起点から対角点の間の1/2にあると予想して、検索する。
-                       v2 = (v1 - i_vertex1_index) / 2 + i_vertex1_index;
-                       if (!wv1.getVertex(i_x_coord, i_y_coord, i_vertex1_index, v2, thresh)) {
-                               return false;
-                       }
-                       if (!wv2.getVertex(i_x_coord, i_y_coord, v2, v1, thresh)) {
-                               return false;
-                       }
-                       if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
-                               o_vertex[1] = wv1.vertex[0];
-                               o_vertex[2] = wv2.vertex[0];
-                               o_vertex[3] = v1;
-                       } else {
-                               return false;
-                       }
-               } else if (wv1.number_of_vertex == 0 && wv2.number_of_vertex > 1) {
-                       // v2 = (v1-i_vertex1_index+ end_of_coord-i_vertex1_index) / 2+i_vertex1_index;
-                       v2 = (v1 + end_of_coord) / 2;
-
-                       if (!wv1.getVertex(i_x_coord, i_y_coord, v1, v2, thresh)) {
-                               return false;
-                       }
-                       if (!wv2.getVertex(i_x_coord, i_y_coord, v2, end_of_coord, thresh)) {
-                               return false;
-                       }
-                       if (wv1.number_of_vertex == 1 && wv2.number_of_vertex == 1) {
-                               o_vertex[1] = v1;
-                               o_vertex[2] = wv1.vertex[0];
-                               o_vertex[3] = wv2.vertex[0];
-                       } else {
-                               return false;
-                       }
-               } else {
-                       return false;
-               }
-               o_vertex[4] = end_of_coord;
-               return true;
-       }
-       /**
-        * QRコードのエッジ特徴を持つラベルであるかを調べる
-        * @param buf
-        * @param index_table
-        * @param i_label
-        * @return
-        */
-       private boolean hasQrEdgeFeature(int buf[][], int[] index_table, NyARLabelingLabel i_label)
-       {
-               int tx, bx;
-               int w;
-               int i_label_id = i_label.id;
-               int[] limage_j;
-               final int clip_l = i_label.clip_l;
-               final int clip_b = i_label.clip_b;
-               final int clip_r = i_label.clip_r;
-               final int clip_t = i_label.clip_t;
-
-               tx = bx = 0;
-               // 上接点(→)
-               limage_j = buf[clip_t];
-               for (int i = clip_l; i <= clip_r; i++) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) {
-                       w = limage_j[i];
-                       if (w > 0 && index_table[w - 1] == i_label_id) {
-                               tx = i;
-                               break;
-                       }
-               }
-               // 下接点(←)
-               limage_j = buf[clip_b];
-               for (int i = clip_r; i >= clip_l; i--) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) {
-                       w = limage_j[i];
-                       if (w > 0 && index_table[w - 1] == i_label_id) {
-                               bx = i;
-                               break;
-                       }
-               }
-               final int cx = (clip_l + clip_r) / 2;
-               final int cy = (clip_t + clip_b) / 2;
-               // 横断チェック(中心から線を引いて、101になるかしらべる)
-               if (!checkDiagonalLine(buf, cx, cy, bx, clip_b)) {
-                       return false;
-               }
-               if (!checkDiagonalLine(buf, tx, clip_t, cx, cy)) {
-                       return false;
-               }
-               return true;
-       }
-
-       /**
-        * 対角線のパターンを調べる。
-        * 
-        * @param buf
-        * @param i_px1
-        * @param i_py1
-        * @param i_px2
-        * @param i_py2
-        * @return
-        */
-       private boolean checkDiagonalLine(int[][] buf, int i_px1, int i_py1, int i_px2, int i_py2)
-       {
-               int sub_y = i_py2 - i_py1;
-               int sub_x = i_px2 - i_px1;
-               // 黒
-               int i = 0;
-               for (; i < sub_y; i++) {
-                       int yp = i_py1 + i;
-                       int xp = i_px1 + i * sub_x / sub_y;
-                       if (buf[yp][xp] == 0 && buf[yp][xp-1] == 0 && buf[yp][xp+1] == 0) {
-                               break;
-                       }
-
-               }
-               if (i == sub_y) {
-                       return false;
-               }
-               // 白
-               for (; i < sub_y; i++) {
-                       int yp = i_py1 + i;
-                       int xp = i_px1 + i * sub_x / sub_y;
-                       if (buf[yp][xp] != 0 && buf[yp][xp-1] != 0 && buf[yp][xp+1] != 0) {
-                               break;
-                       }
-
-               }
-               if (i == sub_y) {
-                       return false;
-               }
-               // 黒
-               for (; i < sub_y; i++) {
-                       int yp = i_py1 + i;
-                       int xp = i_px1 + i * sub_x / sub_y;
-                       if (buf[yp][xp] == 0 && buf[yp][xp-1] == 0 && buf[yp][xp+1] == 0) {
-                               break;
-                       }
-
-               }
-               if (i != sub_y) {
-                       return false;
-               }
-               // 端まで到達したらOK
-               return true;
-       }
-
-}
-
-
-public class CopyOfLabelingCamera extends Frame implements JmfCaptureListener
-{
-       private final String camera_file = "../Data/camera_para.dat";
-
-       private JmfNyARRaster_RGB _raster;
-
-       private JmfCameraCapture capture;
-       private NyARParam ap;
-       public CopyOfLabelingCamera() throws NyARException, NyARException
-       {
-               setBounds(0, 0, 640 + 64, 720 + 64);
-               // キャプチャの準備
-               capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB);
-               capture.setCaptureListener(this);
-
-               // キャプチャイメージ用のラスタを準備
-               this._raster = new JmfNyARRaster_RGB(320, 240);
-               
-               // AR用カメラパラメタファイルをロード
-               ap = new NyARParam();
-               ap.loadARParamFromFile(camera_file);
-               ap.changeScreenSize(320, 240);          
-               
-               
-       }
-
-       // そのラベルが特徴点候補か返す。
-
-       private NyARBinRaster _binraster1 = new NyARBinRaster(320, 240);
-
-       private NyARGlayscaleRaster _gsraster1 = new NyARGlayscaleRaster(320, 240);
-
-       private NyARLabelingImage _limage = new NyARLabelingImage(320, 240);
-
-       private LabelingBufferdImage _bimg = new LabelingBufferdImage(320, 240);
-
-       private NyARRasterFilter_ARToolkitThreshold filter_gs2bin;
-
-       public void onUpdateBuffer(Buffer i_buffer)
-       {
-               NyARRasterFilter_AreaAverage gs2bin=new NyARRasterFilter_AreaAverage();
-
-               try {
-                       // キャプチャしたバッファをラスタにセット
-                       _raster.setBuffer(i_buffer);
-
-                       Graphics g = getGraphics();
-                       // キャプチャ画像
-                       BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat());
-                       Image img = b2i.createImage(i_buffer);
-                       this.getGraphics().drawImage(img, 32, 32, this);
-
-                       // 画像1
-                       INyARRasterFilter_RgbToGs filter_rgb2gs = new NyARRasterFilter_RgbAve();
-                       filter_rgb2gs.doFilter(_raster, _gsraster1);
-                       this._bimg.drawImage(this._gsraster1);
-                       this.getGraphics().drawImage(this._bimg, 32 + 320, 32, 320 + 320 + 32, 240 + 32, 0, 240, 320, 0, this);
-                       
-
-                       // 画像2
-                       gs2bin.doFilter(_gsraster1, _binraster1);
-                       this._bimg.drawImage(_binraster1);
-                       this.getGraphics().drawImage(this._bimg, 32, 32 + 240, 320 + 32, 240 + 32 + 240, 0, 240, 320, 0, this);
-
-                       // 画像3
-                       NyARLabelingImage limage = new NyARLabelingImage(320, 240);
-                       NyARLabeling_ARToolKit labeling = new NyARLabeling_ARToolKit();
-                       labeling.attachDestination(limage);
-                       labeling.labeling(_binraster1);
-                       this._bimg.drawImage(this._gsraster1);
-                       NyARLabelingLabel[] labels = (NyARLabelingLabel[]) limage.getLabelStack().getArray();
-
-                       NyARSquareStack stack = new NyARSquareStack(100);
-                       NyARQRCodeDetector detect = new NyARQRCodeDetector(ap.getDistortionFactor(), new NyARIntSize(320,240));
-                       detect.bimg=this._bimg;
-
-                       detect.detectMarker(_binraster1, stack);
-                       for (int i = 0; i < stack.getLength(); i++) {
-                               NyARSquare[] square_ptr = (NyARSquare[]) stack.getArray();
-                               int[] xp=new int[4]; 
-                               int[] yp=new int[4]; 
-                               for(int i2=0;i2<4;i2++){
-                                       xp[i2]=square_ptr[i].imvertex[i2].x;
-                                       yp[i2]=square_ptr[i].imvertex[i2].y;
-                               }
-                               this._bimg.getGraphics().setColor(Color.RED);
-                               this._bimg.getGraphics().drawPolygon(xp, yp,2);
-                       }
-                       this.getGraphics().drawImage(this._bimg, 32 + 320, 32 + 240, 320 + 32 + 320, 240 + 32 + 240, 0, 240, 320, 0, this);
-
-                       // 画像3
-                       // threshold.debugDrawHistgramMap(_workraster, _workraster2);
-                       // this._bimg2.setImage(this._workraster2);
-                       // this.getGraphics().drawImage(this._bimg2, 32+320, 32+240,320+32+320,240+32+240,0,240,320,0, this);
-
-                       // 画像4
-                       // NyARRasterThresholdAnalyzer_SlidePTile threshold=new NyARRasterThresholdAnalyzer_SlidePTile(15);
-                       // threshold.analyzeRaster(_gsraster1);
-                       // filter_gs2bin=new NyARRasterFilter_AreaAverage();
-                       // filter_gs2bin.doFilter(_gsraster1, _binraster1);
-                       // this._bimg.drawImage(_binraster1);
-
-                       // NyARRasterDetector_QrCodeEdge detector=new NyARRasterDetector_QrCodeEdge(10000);
-                       // detector.analyzeRaster(_binraster1);
-
-                       // this._bimg.overlayData(detector.geResult());
-
-                       // this.getGraphics().drawImage(this._bimg, 32, 32+480,320+32,480+32+240,0,240,320,0, this);
-                       // 画像5
-
-                       /*
-                        * threshold2.debugDrawHistgramMap(_workraster, _workraster2); this._bimg2.drawImage(this._workraster2); this.getGraphics().drawImage(this._bimg2,
-                        * 32+320, 32+480,320+32+320,480+32+240,0,240,320,0, this);
-                        */
-
-                       // this.getGraphics().drawImage(this._bimg, 32, 32, this);
-
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-
-       }
-
-       private INyARLabeling labelingFactory(int i_idx)
-       {
-               // switch(i_idx){
-               // case 0:{NyARLabeling_ARToolKit l=new NyARLabeling_ARToolKit();l.setThresh(4);return l;}
-               // case 1:{return new NyLineLabeling();}
-               // }
-               return null;
-
-       }
-
-       private void startCapture()
-       {
-               try {
-                       capture.start();
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-       }
-
-       public static void main(String[] args)
-       {
-               try {
-                       CopyOfLabelingCamera mainwin = new CopyOfLabelingCamera();
-                       mainwin.setVisible(true);
-                       mainwin.startCapture();
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-
-       }
-
-}
index 1946a5d..785ba68 100644 (file)
@@ -11,9 +11,8 @@ import javax.media.format.*;
 
 import jp.nyatla.nyartoolkit.NyARException;
 import jp.nyatla.nyartoolkit.jmf.utils.*;
-import jp.nyatla.nyartoolkit.nymodel.x2.NyARLabeling_ARToolKit_X2;
+
 import jp.nyatla.nyartoolkit.core.*;
-import jp.nyatla.nyartoolkit.nymodel.x2.NyARTransMat_X2;
 
 import java.awt.*;
 
@@ -39,251 +38,236 @@ import jp.nyatla.nyartoolkit.core.types.*;
 import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22;
 
 
-class NyARMkVertexStack extends NyObjectStack
-{
-       public NyARMkVertexStack(int i_length)
-       {
-               super(new NyARIntPoint[i_length][]);
-
-       }
-
-       protected void onReservRequest(int i_start, int i_end, Object[] i_buffer)
-       {
-               for (int i = i_start; i < i_end; i++) {
-                       i_buffer[i] = NyARIntPoint.createArray(4);
-               }
-       }
-}
-/**
- * QRコードのシンボルを結びつける偉いクラス
- *
- */
-class NyQrCodeSymbolBinder
-{
-       LabelingBufferdImage bimg;
-       
-       NyARIntPoint[][] _sqare;
-       /**
-        * 最小の三角形を構成する頂点セットを得る
-        * @param i_s0
-        * @param i_s1
-        * @param i_s2
-        * @param o_vertex
-        */
-       public static void getMinimumTriangleVertex(NyARSquare[] i_sqare,int[] o_vertex_id)
-       {
-               //辺の長さが最小になる頂点の組合せを探す
-               int d;
-               int x,y;
-               int dmax=0x7fffffff;
-               final NyARIntPoint[] vertex0=i_sqare[0].imvertex;
-               final NyARIntPoint[] vertex1=i_sqare[1].imvertex;
-               final NyARIntPoint[] vertex2=i_sqare[2].imvertex;
-               for(int i=0;i<4;i++)
-               {
-                       for(int i2=0;i2<4;i2++)
-                       {
-                               for(int i3=0;i3<4;i3++){
-                                       x=vertex0[i].x-vertex2[i3].x;
-                                       y=vertex0[i].y-vertex2[i3].y;
-                                       d=x*x+y*y;
-                                       x=vertex1[i2].x-vertex2[i3].x;
-                                       y=vertex1[i2].y-vertex2[i3].y;
-                                       d+=x*x+y*y;
-                                       x=vertex1[i2].x-vertex0[i].x;
-                                       y=vertex1[i2].y-vertex0[i].y;
-                                       d+=x*x+y*y;
-                                       if(d<dmax){
-                                               dmax=d;
-                                               o_vertex_id[0]=i;                                       
-                                               o_vertex_id[1]=i2;
-                                               o_vertex_id[2]=i3;
-                                       }
-                               }
-                       }
-               }
-               return;
-       }
-       /**
-        * 2矩形の頂点距離が最低の組合せを探す
-        * @param i_sqare
-        * @param o_vertex_id
-        */
-       public static void getMinimumLineVertex(NyARIntPoint[] i_sqare0,NyARIntPoint[] i_sqare1,int[] o_vertex_id)
-       {
-               //辺の長さが最小になる頂点の組合せを探す
-               int d;
-               int x,y;
-               int dmax=0x7fffffff;
-               for(int i=0;i<4;i++)
-               {
-                       for(int i2=0;i2<4;i2++)
-                       {
-                               x=i_sqare1[i2].x-i_sqare0[i].x;
-                               y=i_sqare1[i2].y-i_sqare0[i].y;
-                               d=x*x+y*y;
-                               if(d<dmax){
-                                       dmax=d;
-                                       o_vertex_id[0]=i;                                       
-                                       o_vertex_id[1]=i2;
-                               }
-                       }
-               }
-               return;
-       }       
-       
-       /**
-        * キーシンボルのインデックスを得る
-        * @param i_sqare
-        * @param i_vertex_id
-        * 最小三角形の頂点IDセット
-        * @return
-        */
-       public static int getKeySymble(NyARSquare[] i_sqare,int[] i_vertex_id)
-       {
-               //シンボルグループの重心を計算
-               int cx,cy;
-               cx=cy=0;
-               for(int i=0;i<3;i++)
-               {
-                       final NyARIntPoint[] sq_ptr=i_sqare[i].imvertex;
-                       cx+=sq_ptr[0].x;                        
-                       cx+=sq_ptr[1].x;                        
-                       cx+=sq_ptr[2].x;                        
-                       cx+=sq_ptr[3].x;                        
-                       cy+=sq_ptr[0].y;                        
-                       cy+=sq_ptr[1].y;                        
-                       cy+=sq_ptr[2].y;                        
-                       cy+=sq_ptr[3].y;                        
-               }
-               cx/=12;
-               cy/=12; 
-               //前段で探した頂点候補のうち、最も重心に近いものが中心シンボルの内対角点
-               int key_symble_idx=0;
-               int x=i_sqare[0].imvertex[i_vertex_id[0]].x-cx;
-               int y=i_sqare[0].imvertex[i_vertex_id[0]].y-cy;
-               int dmax=x*x+y*y;
-               for(int i=1;i<3;i++){
-                       x=i_sqare[i].imvertex[i_vertex_id[i]].x-cx;
-                       y=i_sqare[i].imvertex[i_vertex_id[i]].y-cy;
-                       final int d=x*x+y*y;
-                       if(d<dmax){
-                               dmax=d;
-                               key_symble_idx=i;
-                       }
-               }
-               return key_symble_idx;
-       }
-       public void bindSquare(NyARSquare i_sq1,int i_lv1,NyARSquare i_sq2,int i_lv2)
-       {
-               NyARSquare new_square=new NyARSquare();
-               //4辺の式を計算
-               new_square.line[0].copyFrom(i_sq1.line[(i_lv1)%4]);
-               new_square.line[1].copyFrom(i_sq1.line[(i_lv1+3)%4]);
-               new_square.line[2].copyFrom(i_sq2.line[(i_lv2)%4]);
-               new_square.line[3].copyFrom(i_sq2.line[(i_lv2+3)%4]);
-               //歪み無しの座標系を計算
-               final NyARDoublePoint2d[] l_sqvertex = new_square.sqvertex;
-               final NyARLinear[] l_line = new_square.line;            
-               for (int i = 0; i < 4; i++) {
-                       final NyARLinear l_line_i = l_line[i];
-                       final NyARLinear l_line_2 = l_line[(i + 3) % 4];
-                       final double w1 = l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise;
-                       if (w1 == 0.0) {
-                               return;
-                       }
-                       l_sqvertex[i].x = (l_line_2.rise * l_line_i.intercept - l_line_i.rise * l_line_2.intercept) / w1;
-                       l_sqvertex[i].y = (l_line_i.run * l_line_2.intercept - l_line_2.run * l_line_i.intercept) / w1;
-//                     // 頂点インデクスから頂点座標を得て保存
-//                     l_imvertex[i].x = i_xcoord[i_mkvertex[i]];
-//                     l_imvertex[i].y = i_ycoord[i_mkvertex[i]];
-               }
-               Graphics g=this.bimg.getGraphics();
-               g.setColor(Color.red);
-               int[] x=new int[4];
-               int[] y=new int[4];
-               for(int i=0;i<4;i++){
-                       x[i]=(int)l_sqvertex[i].x;
-                       y[i]=(int)l_sqvertex[i].y;
-               }
-               g.drawPolygon(x,y,4);
-               //基準点はVertexをそのまま採用
-               //2個の想定点は座標を逆変換して設定
-       }
-       /**
-        *
-        * @param i_sq
-        * @param o_sq
-        * @return
-        */
-       public boolean margeEdge(NyARSquare[] i_sq,NyARSquare o_sq)
-       {
-               int[] minimum_triangle_vertex=new int[3];
-               int[] minimum_line_vertex=new int[2];
-
-               //辺の長さが最小になる頂点の組合せを探す
-               getMinimumTriangleVertex(i_sq,minimum_triangle_vertex);
-               
-               //キーシンボルのインデクス番号を得る
-               int key_simble_idx=getKeySymble(i_sq,minimum_triangle_vertex);
-               
-               //エッジシンボルのインデックス番号を決める
-               int symbol_e1_idx=(key_simble_idx+1)%3;
-               int symbol_e2_idx=(key_simble_idx+2)%3;
-               
-               //エッジシンボル間で最短距離を取る頂点ペアを取る
-               //(角度を低くするとエラーが出やすい。対角線との類似性を確認する方法のほうがいい。多分)
-               getMinimumLineVertex(i_sq[symbol_e1_idx].imvertex,i_sq[symbol_e2_idx].imvertex,minimum_line_vertex);
-               
-               //内対角を外対角に変換
-               int lv1=(minimum_line_vertex[0]+2)%4;
-               int lv2=(minimum_line_vertex[1]+2)%4;
-               int kv =(minimum_triangle_vertex[key_simble_idx]+2)%4;
-               //矩形のバインド
-               bindSquare(i_sq[symbol_e1_idx],lv1,i_sq[symbol_e2_idx],lv2);
-                               
-               
-               Graphics g=this.bimg.getGraphics();
-               //内対角に緑の点を打つ
-               g.setColor(Color.green);
-               g.fillRect(i_sq[symbol_e1_idx].imvertex[lv1].x-2,i_sq[symbol_e1_idx].imvertex[lv1].y-2,4,4);
-               g.fillRect(i_sq[symbol_e2_idx].imvertex[lv2].x-2,i_sq[symbol_e2_idx].imvertex[lv2].y-2,4,4);
-//             g.fillRect(i_sq[symbol_e2_idx][minimum_line_vertex[1]].x-2,i_sq[symbol_e2_idx][minimum_line_vertex[1]].y-2,4,4);
-               
-               
-               //中央の中心エッジから最も遠い点が
-               //両端のエッジも探す
-               
-               
-               
-
-//             this.bimg.getGraphics().fillRect(i_sq[edge1_id][vid1_id].x,i_sq[edge1_id][vid1_id].y,5,5);
-               
-               for (int i = 0; i <3; i++) {
-                       int[] xp=new int[4]; 
-                       int[] yp=new int[4]; 
-                       for(int i2=0;i2<4;i2++){
-                               xp[i2]=i_sq[i].imvertex[i2].x;
-                               yp[i2]=i_sq[i].imvertex[i2].y;
-                       }
-                       this.bimg.getGraphics().setColor(Color.RED);
-                       this.bimg.getGraphics().drawPolygon(xp, yp,4);
-               }               
-               
-               
-               return false;
-               
-               
-               
-               
-
-               
-       }       
-       
-       
-       
-       
-}
+///**
+// * QRコードのシンボルを結びつける偉いクラス
+// *
+// */
+//class NyQrCodeSymbolBinder
+//{
+//     LabelingBufferdImage bimg;
+//     
+//     NyARIntPoint[][] _sqare;
+//     /**
+//      * 最小の三角形を構成する頂点セットを得る
+//      * @param i_s0
+//      * @param i_s1
+//      * @param i_s2
+//      * @param o_vertex
+//      */
+//     public static void getMinimumTriangleVertex(NyARSquare[] i_sqare,int[] o_vertex_id)
+//     {
+//             //辺の長さが最小になる頂点の組合せを探す
+//             int d;
+//             int x,y;
+//             int dmax=0x7fffffff;
+//             final NyARIntPoint[] vertex0=i_sqare[0].imvertex;
+//             final NyARIntPoint[] vertex1=i_sqare[1].imvertex;
+//             final NyARIntPoint[] vertex2=i_sqare[2].imvertex;
+//             for(int i=0;i<4;i++)
+//             {
+//                     for(int i2=0;i2<4;i2++)
+//                     {
+//                             for(int i3=0;i3<4;i3++){
+//                                     x=vertex0[i].x-vertex2[i3].x;
+//                                     y=vertex0[i].y-vertex2[i3].y;
+//                                     d=x*x+y*y;
+//                                     x=vertex1[i2].x-vertex2[i3].x;
+//                                     y=vertex1[i2].y-vertex2[i3].y;
+//                                     d+=x*x+y*y;
+//                                     x=vertex1[i2].x-vertex0[i].x;
+//                                     y=vertex1[i2].y-vertex0[i].y;
+//                                     d+=x*x+y*y;
+//                                     if(d<dmax){
+//                                             dmax=d;
+//                                             o_vertex_id[0]=i;                                       
+//                                             o_vertex_id[1]=i2;
+//                                             o_vertex_id[2]=i3;
+//                                     }
+//                             }
+//                     }
+//             }
+//             return;
+//     }
+//     /**
+//      * 2矩形の頂点距離が最低の組合せを探す
+//      * @param i_sqare
+//      * @param o_vertex_id
+//      */
+//     public static void getMinimumLineVertex(NyARIntPoint[] i_sqare0,NyARIntPoint[] i_sqare1,int[] o_vertex_id)
+//     {
+//             //辺の長さが最小になる頂点の組合せを探す
+//             int d;
+//             int x,y;
+//             int dmax=0x7fffffff;
+//             for(int i=0;i<4;i++)
+//             {
+//                     for(int i2=0;i2<4;i2++)
+//                     {
+//                             x=i_sqare1[i2].x-i_sqare0[i].x;
+//                             y=i_sqare1[i2].y-i_sqare0[i].y;
+//                             d=x*x+y*y;
+//                             if(d<dmax){
+//                                     dmax=d;
+//                                     o_vertex_id[0]=i;                                       
+//                                     o_vertex_id[1]=i2;
+//                             }
+//                     }
+//             }
+//             return;
+//     }       
+//     
+//     /**
+//      * キーシンボルのインデックスを得る
+//      * @param i_sqare
+//      * @param i_vertex_id
+//      * 最小三角形の頂点IDセット
+//      * @return
+//      */
+//     public static int getKeySymble(NyARSquare[] i_sqare,int[] i_vertex_id)
+//     {
+//             //シンボルグループの重心を計算
+//             int cx,cy;
+//             cx=cy=0;
+//             for(int i=0;i<3;i++)
+//             {
+//                     final NyARIntPoint[] sq_ptr=i_sqare[i].imvertex;
+//                     cx+=sq_ptr[0].x;                        
+//                     cx+=sq_ptr[1].x;                        
+//                     cx+=sq_ptr[2].x;                        
+//                     cx+=sq_ptr[3].x;                        
+//                     cy+=sq_ptr[0].y;                        
+//                     cy+=sq_ptr[1].y;                        
+//                     cy+=sq_ptr[2].y;                        
+//                     cy+=sq_ptr[3].y;                        
+//             }
+//             cx/=12;
+//             cy/=12; 
+//             //前段で探した頂点候補のうち、最も重心に近いものが中心シンボルの内対角点
+//             int key_symble_idx=0;
+//             int x=i_sqare[0].imvertex[i_vertex_id[0]].x-cx;
+//             int y=i_sqare[0].imvertex[i_vertex_id[0]].y-cy;
+//             int dmax=x*x+y*y;
+//             for(int i=1;i<3;i++){
+//                     x=i_sqare[i].imvertex[i_vertex_id[i]].x-cx;
+//                     y=i_sqare[i].imvertex[i_vertex_id[i]].y-cy;
+//                     final int d=x*x+y*y;
+//                     if(d<dmax){
+//                             dmax=d;
+//                             key_symble_idx=i;
+//                     }
+//             }
+//             return key_symble_idx;
+//     }
+//     public void bindSquare(NyARSquare i_sq1,int i_lv1,NyARSquare i_sq2,int i_lv2)
+//     {
+//             NyARSquare new_square=new NyARSquare();
+//             //4辺の式を計算
+//             new_square.line[0].copyFrom(i_sq1.line[(i_lv1)%4]);
+//             new_square.line[1].copyFrom(i_sq1.line[(i_lv1+3)%4]);
+//             new_square.line[2].copyFrom(i_sq2.line[(i_lv2)%4]);
+//             new_square.line[3].copyFrom(i_sq2.line[(i_lv2+3)%4]);
+//             //歪み無しの座標系を計算
+//             final NyARDoublePoint2d[] l_sqvertex = new_square.sqvertex;
+//             final NyARLinear[] l_line = new_square.line;            
+//             for (int i = 0; i < 4; i++) {
+//                     final NyARLinear l_line_i = l_line[i];
+//                     final NyARLinear l_line_2 = l_line[(i + 3) % 4];
+//                     final double w1 = l_line_2.run * l_line_i.rise - l_line_i.run * l_line_2.rise;
+//                     if (w1 == 0.0) {
+//                             return;
+//                     }
+//                     l_sqvertex[i].x = (l_line_2.rise * l_line_i.intercept - l_line_i.rise * l_line_2.intercept) / w1;
+//                     l_sqvertex[i].y = (l_line_i.run * l_line_2.intercept - l_line_2.run * l_line_i.intercept) / w1;
+////                   // 頂点インデクスから頂点座標を得て保存
+////                   l_imvertex[i].x = i_xcoord[i_mkvertex[i]];
+////                   l_imvertex[i].y = i_ycoord[i_mkvertex[i]];
+//             }
+//             Graphics g=this.bimg.getGraphics();
+//             g.setColor(Color.red);
+//             int[] x=new int[4];
+//             int[] y=new int[4];
+//             for(int i=0;i<4;i++){
+//                     x[i]=(int)l_sqvertex[i].x;
+//                     y[i]=(int)l_sqvertex[i].y;
+//             }
+//             g.drawPolygon(x,y,4);
+//             //基準点はVertexをそのまま採用
+//             //2個の想定点は座標を逆変換して設定
+//     }
+//     /**
+//      *
+//      * @param i_sq
+//      * @param o_sq
+//      * @return
+//      */
+//     public boolean margeEdge(NyARSquare[] i_sq,NyARSquare o_sq)
+//     {
+//             int[] minimum_triangle_vertex=new int[3];
+//             int[] minimum_line_vertex=new int[2];
+//
+//             //辺の長さが最小になる頂点の組合せを探す
+//             getMinimumTriangleVertex(i_sq,minimum_triangle_vertex);
+//             
+//             //キーシンボルのインデクス番号を得る
+//             int key_simble_idx=getKeySymble(i_sq,minimum_triangle_vertex);
+//             
+//             //エッジシンボルのインデックス番号を決める
+//             int symbol_e1_idx=(key_simble_idx+1)%3;
+//             int symbol_e2_idx=(key_simble_idx+2)%3;
+//             
+//             //エッジシンボル間で最短距離を取る頂点ペアを取る
+//             //(角度を低くするとエラーが出やすい。対角線との類似性を確認する方法のほうがいい。多分)
+//             getMinimumLineVertex(i_sq[symbol_e1_idx].imvertex,i_sq[symbol_e2_idx].imvertex,minimum_line_vertex);
+//             
+//             //内対角を外対角に変換
+//             int lv1=(minimum_line_vertex[0]+2)%4;
+//             int lv2=(minimum_line_vertex[1]+2)%4;
+//             int kv =(minimum_triangle_vertex[key_simble_idx]+2)%4;
+//             //矩形のバインド
+//             bindSquare(i_sq[symbol_e1_idx],lv1,i_sq[symbol_e2_idx],lv2);
+//                             
+//             
+//             Graphics g=this.bimg.getGraphics();
+//             //内対角に緑の点を打つ
+//             g.setColor(Color.green);
+//             g.fillRect(i_sq[symbol_e1_idx].imvertex[lv1].x-2,i_sq[symbol_e1_idx].imvertex[lv1].y-2,4,4);
+//             g.fillRect(i_sq[symbol_e2_idx].imvertex[lv2].x-2,i_sq[symbol_e2_idx].imvertex[lv2].y-2,4,4);
+////           g.fillRect(i_sq[symbol_e2_idx][minimum_line_vertex[1]].x-2,i_sq[symbol_e2_idx][minimum_line_vertex[1]].y-2,4,4);
+//             
+//             
+//             //中央の中心エッジから最も遠い点が
+//             //両端のエッジも探す
+//             
+//             
+//             
+//
+////           this.bimg.getGraphics().fillRect(i_sq[edge1_id][vid1_id].x,i_sq[edge1_id][vid1_id].y,5,5);
+//             
+//             for (int i = 0; i <3; i++) {
+//                     int[] xp=new int[4]; 
+//                     int[] yp=new int[4]; 
+//                     for(int i2=0;i2<4;i2++){
+//                             xp[i2]=i_sq[i].imvertex[i2].x;
+//                             yp[i2]=i_sq[i].imvertex[i2].y;
+//                     }
+//                     this.bimg.getGraphics().setColor(Color.RED);
+//                     this.bimg.getGraphics().drawPolygon(xp, yp,4);
+//             }               
+//             
+//             
+//             return false;
+//             
+//             
+//             
+//             
+//
+//             
+//     }       
+//     
+//     
+//     
+//     
+//}
 
 
 /**
@@ -303,7 +287,7 @@ class NyARQRCodeDetector implements INyARSquareDetector
 
        private final int _height;
 
-       private final NyARLabeling_ARToolKit_X2 _labeling;
+       private final NyARLabeling_ARToolKit _labeling;
 
        private final NyARLabelingImage _limage;
 
@@ -319,7 +303,7 @@ class NyARQRCodeDetector implements INyARSquareDetector
                this._width = i_size.w;
                this._height = i_size.h;
                this._dist_factor_ref = i_dist_factor_ref;
-               this._labeling = new NyARLabeling_ARToolKit_X2();
+               this._labeling = new NyARLabeling_ARToolKit();
                this._limage = new NyARLabelingImage(this._width, this._height);
                this._labeling.attachDestination(this._limage);
 
@@ -437,7 +421,6 @@ class NyARQRCodeDetector implements INyARSquareDetector
 
                        // 頂点情報を取得
                        if (!getSquareVertex(xcoord, ycoord, vertex1, coord_num, label_area, mkvertex)) {
-//                             o_square_stack.pop();// 頂点の取得が出来なかったので破棄
                                continue;
                        }
                        NyARSquare square=(NyARSquare)wk_stack.prePush();
@@ -461,7 +444,7 @@ class NyARQRCodeDetector implements INyARSquareDetector
        {
                NyQrCodeSymbolBinder binder=new NyQrCodeSymbolBinder();
                binder.bimg=this.bimg;
-               binder.margeEdge(i_sq, o_sq);
+               binder.(i_sq, o_sq);
 
                return false;
                
@@ -841,7 +824,7 @@ public class LabelingCamera extends Frame implements JmfCaptureListener
 
        private NyARBinRaster _binraster1 = new NyARBinRaster(320, 240);
 
-       private NyARGlayscaleRaster _gsraster1 = new NyARGlayscaleRaster(320, 240);
+       private NyARGrayscaleRaster _gsraster1 = new NyARGrayscaleRaster(320, 240);
 
        private NyARLabelingImage _limage = new NyARLabelingImage(320, 240);