OSDN Git Service

[バックアップ]NyARToolkit for Java
authornyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Mon, 18 May 2009 11:14:43 +0000 (11:14 +0000)
committernyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Mon, 18 May 2009 11:14:43 +0000 (11:14 +0000)
自動閾値探索機能をSingleNyIdMarkerに追加

git-svn-id: http://svn.sourceforge.jp/svnroot/nyartoolkit/NyARToolkit@238 7cac0a50-4618-4814-88d0-24b83990f816

14 files changed:
trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/SingleNyIdMarker.java
trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java
trunk/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/INyARRasterThresholdAnalyzer.java
trunk/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_DiffHistgram.java
trunk/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_PTile.java
trunk/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_SlidePTile.java
trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerParam.java
trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPattern.java
trunk/src/jp/nyatla/nyartoolkit/nyidmarker/NyIdMarkerPickup.java
trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerData.java
trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/INyIdMarkerDataEncoder.java
trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerDataEncoder_RawBit.java
trunk/src/jp/nyatla/nyartoolkit/nyidmarker/data/NyIdMarkerData_RawBit.java
trunk/src/jp/nyatla/nyartoolkit/processor/SingleNyIdMarkerProcesser.java

index fedd88c..8824b32 100644 (file)
@@ -65,18 +65,70 @@ class TextPanel
 }\r
 \r
 /**\r
- * 1個のIdマーカを認識するサンプルアプリケーション。\r
- * 認識したIDマーカの上に情報を表示します。\r
- * 構造的には、アプリケーションフレームワークのSingleNyIdMarkerProcesserにNyIdMarkerDataEncoder_RawBit\r
- * をバインドしてあります。\r
+ * 1個のRawBit-Idマーカを認識するロジッククラス。\r
+ * detectMarker関数の呼び出しに同期して、transmatとcurrent_idパラメタを更新します。\r
+ * \r
  *\r
  */\r
-public class SingleNyIdMarker extends SingleNyIdMarkerProcesser implements GLEventListener, JmfCaptureListener\r
+class MarkerProcessor extends SingleNyIdMarkerProcesser\r
+{      \r
+       private Object _sync_object=new Object();\r
+       public NyARTransMatResult transmat=null;\r
+       public int current_id=-1;\r
+\r
+       public MarkerProcessor(NyARParam i_cparam,int i_raster_format) throws NyARException\r
+       {\r
+               //アプリケーションフレームワークの初期化\r
+               super(i_cparam,new NyIdMarkerDataEncoder_RawBit(),i_raster_format);\r
+               return;\r
+       }\r
+       /**\r
+        * アプリケーションフレームワークのハンドラ(マーカ出現)\r
+        */\r
+       protected void onEnterHandler(INyIdMarkerData i_code)\r
+       {\r
+               synchronized(this._sync_object){\r
+                       NyIdMarkerData_RawBit code=(NyIdMarkerData_RawBit)i_code;\r
+                       if(code.length>4){\r
+                               //4バイト以上の時はint変換しない。\r
+                               this.current_id=-1;//undefined_id\r
+                       }else{\r
+                               this.current_id=0;\r
+                               //最大4バイト繋げて1個のint値に変換\r
+                               for(int i=0;i<code.length;i++){\r
+                                       this.current_id=(this.current_id<<8)|code.packet[i];\r
+                               }\r
+                       }\r
+                       this.transmat=null;\r
+               }\r
+       }\r
+       /**\r
+        * アプリケーションフレームワークのハンドラ(マーカ消滅)\r
+        */\r
+       protected void onLeaveHandler()\r
+       {\r
+               synchronized(this._sync_object){\r
+                       this.current_id=-1;\r
+                       this.transmat=null;\r
+               }\r
+               return;\r
+       }\r
+       /**\r
+        * アプリケーションフレームワークのハンドラ(マーカ更新)\r
+        */\r
+       protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)\r
+       {\r
+               synchronized(this._sync_object){\r
+                       this.transmat=result;\r
+               }\r
+       }\r
+}\r
+\r
+\r
+public class SingleNyIdMarker implements GLEventListener, JmfCaptureListener\r
 {\r
        private Animator _animator;\r
-\r
        private GLNyARRaster_RGB _cap_image;\r
-\r
        private JmfCaptureDevice _capture;\r
 \r
        private GL _gl;\r
@@ -90,15 +142,10 @@ public class SingleNyIdMarker extends SingleNyIdMarkerProcesser implements GLEve
        private double[] _camera_projection=new double[16];\r
        \r
        private Object _sync_object=new Object();\r
-       private NyARTransMatResult _ref_result=null;\r
-       private int _current_id=-1;\r
+       private MarkerProcessor _processor;\r
 \r
        public SingleNyIdMarker(NyARParam i_cparam) throws NyARException\r
        {\r
-               //アプリケーションフレームワークの初期化\r
-               super(i_cparam,new NyIdMarkerDataEncoder_RawBit());\r
-               this.setMarkerWidth(100);\r
-               this.setBaseThreshold(110);//基準閾値(そのうち自動にする)\r
                JmfCaptureDeviceList devlist=new JmfCaptureDeviceList();\r
                this._ar_param=i_cparam;\r
 \r
@@ -108,8 +155,12 @@ public class SingleNyIdMarker extends SingleNyIdMarkerProcesser implements GLEve
                        throw new NyARException();\r
                }\r
                this._capture.setOnCapture(this);\r
-               this._cap_image = new GLNyARRaster_RGB(i_cparam,this._capture.getCaptureFormat());              \r
+               this._cap_image = new GLNyARRaster_RGB(i_cparam,this._capture.getCaptureFormat());      \r
 \r
+               //プロセッサの準備\r
+               this._processor=new MarkerProcessor(i_cparam,this._cap_image.getBufferReader().getBufferType());\r
+               this._processor.setMarkerWidth(100);\r
+               \r
                //OpenGLフレームの準備(OpenGLリソースの初期化、カメラの撮影開始は、initコールバック関数内で実行)\r
                Frame frame = new Frame("Java simpleLite with NyARToolkit");\r
                GLCanvas canvas = new GLCanvas();\r
@@ -171,14 +222,14 @@ public class SingleNyIdMarker extends SingleNyIdMarkerProcesser implements GLEve
        \r
        public void display(GLAutoDrawable drawable)\r
        {\r
-               NyARTransMatResult transmat_result = this._ref_result;\r
+               NyARTransMatResult transmat_result = this._processor.transmat;\r
                if (!_cap_image.hasData()) {\r
                        return;\r
                }\r
                // 背景を書く\r
                this._gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.\r
                this._glnya.drawBackGround(this._cap_image, 1.0);                       \r
-               if(this._current_id<0 || transmat_result==null){\r
+               if(this._processor.current_id<0 || transmat_result==null){\r
                        \r
                }else{\r
                        try{\r
@@ -204,7 +255,7 @@ public class SingleNyIdMarker extends SingleNyIdMarkerProcesser implements GLEve
                                        this._gl.glRotatef(r,0f,0f,1.0f);\r
                                        this._gl.glTranslatef(-1.0f,0f,1.0f);\r
                                        this._gl.glRotatef(90,1.0f,0f,0f);\r
-                                       this._panel.draw("MarkerId:"+this._current_id,0.01f);\r
+                                       this._panel.draw("MarkerId:"+this._processor.current_id,0.01f);\r
                                        this._gl.glPopMatrix();\r
                                }\r
                                Thread.sleep(1);// タスク実行権限を一旦渡す\r
@@ -216,48 +267,6 @@ public class SingleNyIdMarker extends SingleNyIdMarkerProcesser implements GLEve
 \r
        }\r
        /**\r
-        * アプリケーションフレームワークのハンドラ(マーカ出現)\r
-        */\r
-       protected void onEnterHandler(INyIdMarkerData i_code)\r
-       {\r
-               synchronized(this._sync_object){\r
-                       NyIdMarkerData_RawBit code=(NyIdMarkerData_RawBit)i_code;\r
-                       if(code.length>4){\r
-                               //4バイト以上の時はint変換しない。\r
-                               this._current_id=-1;//undefined_id\r
-                       }else{\r
-                               this._current_id=0;\r
-                               //最大4バイト繋げて1個のint値に変換\r
-                               for(int i=0;i<code.length;i++){\r
-                                       this._current_id=(this._current_id<<8)|code.packet[i];\r
-                               }\r
-                       }\r
-                       this._ref_result=null;\r
-               }\r
-       }\r
-       /**\r
-        * アプリケーションフレームワークのハンドラ(マーカ消滅)\r
-        */\r
-       protected void onLeaveHandler()\r
-       {\r
-               synchronized(this._sync_object){\r
-                       this._current_id=-1;\r
-                       this._ref_result=null;\r
-               }\r
-               return;\r
-       }\r
-       /**\r
-        * アプリケーションフレームワークのハンドラ(マーカ更新)\r
-        */\r
-       protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)\r
-       {\r
-               synchronized(this._sync_object){\r
-                       this._ref_result=result;\r
-               }\r
-       }\r
-\r
-       \r
-       /**\r
         * カメラデバイスからのコールバック\r
         */\r
        public void onUpdateBuffer(Buffer i_buffer)\r
@@ -266,7 +275,7 @@ public class SingleNyIdMarker extends SingleNyIdMarkerProcesser implements GLEve
                        synchronized (this._sync_object) {\r
                                this._cap_image.setBuffer(i_buffer);\r
                                //フレームワークに画像を転送\r
-                               this.detectMarker(this._cap_image);\r
+                               this._processor.detectMarker(this._cap_image);\r
                        }\r
                } catch (Exception e) {\r
                        e.printStackTrace();\r
@@ -295,3 +304,4 @@ public class SingleNyIdMarker extends SingleNyIdMarkerProcesser implements GLEve
                return;\r
        }\r
 }\r
+\r
index c419366..8bb699b 100644 (file)
@@ -101,7 +101,7 @@ public interface INyARBufferReader
         */\r
        public static final int BUFFERFORMAT_INT1D_GLAY_8 = INT1D|0x0001;\r
        /**\r
-        * int[]で特に値範囲を定めない\r
+        * int[]で0/1の2値画像\r
         */\r
        public static final int BUFFERFORMAT_INT1D_BIN_8  = INT1D|0x0002;\r
        /**\r
index 13b2ff4..b9eab05 100644 (file)
@@ -40,6 +40,4 @@ public interface INyARRasterThresholdAnalyzer
        public void analyzeRaster(INyARRaster i_input) throws NyARException;\r
 \r
        public int getThreshold();\r
-\r
-       public int getThreshold(int i_x, int i_y);\r
 }\r
index 9fcc294..f7d2f60 100644 (file)
@@ -148,9 +148,4 @@ public class NyARRasterThresholdAnalyzer_DiffHistgram implements INyARRasterThre
        {\r
                return this._threshold;\r
        }\r
-\r
-       public int getThreshold(int i_x, int i_y)\r
-       {\r
-               return this._threshold;\r
-       }\r
 }\r
index e1f9198..894bede 100644 (file)
@@ -163,9 +163,4 @@ public class NyARRasterThresholdAnalyzer_PTile implements INyARRasterThresholdAn
        {\r
                return this._threshold;\r
        }\r
-\r
-       public int getThreshold(int i_x, int i_y)\r
-       {\r
-               return this._threshold;\r
-       }\r
 }\r
index eba8ad6..c583092 100644 (file)
@@ -44,42 +44,89 @@ import jp.nyatla.nyartoolkit.core.types.*;
  */\r
 public class NyARRasterThresholdAnalyzer_SlidePTile implements INyARRasterThresholdAnalyzer\r
 {\r
+       interface ICreateHistgramImpl{\r
+               public void createHistgramImpl(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram);\r
+       }\r
+       /**\r
+        * Glayscale(MAX256)のヒストグラム計算クラス\r
+        */\r
+       final class CreateHistgramImpl_INT1D_GLAY_8 implements ICreateHistgramImpl\r
+       {\r
+               public void createHistgramImpl(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram)\r
+               {\r
+                       final int[] input=(int[]) i_reader.getBuffer();\r
+                       int pt = 0;\r
+                       for (int y = i_size.h-1; y >=0 ; y--) {\r
+                               for (int x = i_size.w-1; x >=0; x--) {\r
+                                       o_histgram[input[pt]]++;\r
+                                       pt++;\r
+                               }\r
+                       }\r
+                       return;\r
+               }\r
+       }\r
+       final class CreateHistgramImpl_BYTE1D_RGB_24 implements ICreateHistgramImpl\r
+       {\r
+               public void createHistgramImpl(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram)\r
+               {\r
+                       final byte[] input=(byte[]) i_reader.getBuffer();\r
+                       int pt = 0;\r
+                       for (int y = i_size.h-1; y >=0 ; y--) {\r
+                               for (int x = i_size.w-1; x >=0; x--) {\r
+                                       final int v=((input[pt+0]& 0xff)+(input[pt+1]& 0xff)+(input[pt+2]& 0xff))/3;\r
+                                       o_histgram[v]++;\r
+                                       pt+=3;\r
+                               }\r
+                       }\r
+                       return;                 \r
+               }\r
+       }\r
        private int _persentage;\r
-\r
        private int _threshold;\r
-\r
+       private ICreateHistgramImpl _histgram;\r
+       \r
        /**\r
         * @param i_persentage\r
         * 0<=50であること。白/黒マーカーの場合は10~20を推奨 正の場合、黒点を基準にします。 負の場合、白点を基準にします。\r
         * (CMOSカメラの場合、基準点は白点の方が良い)\r
         */\r
-       public NyARRasterThresholdAnalyzer_SlidePTile(int i_persentage)\r
+       public NyARRasterThresholdAnalyzer_SlidePTile(int i_persentage,int i_raster_format) throws NyARException\r
        {\r
                assert (0 <= i_persentage && i_persentage <= 50);\r
                this._persentage = i_persentage;\r
+               switch(i_raster_format){\r
+               case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
+               case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
+                       this._histgram=new CreateHistgramImpl_BYTE1D_RGB_24();\r
+                       break;\r
+               case INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8:\r
+                       this._histgram=new CreateHistgramImpl_BYTE1D_RGB_24();\r
+                       break;\r
+               default:\r
+                       throw new NyARException();\r
+               }\r
        }\r
+       public void setVerticalInterval(int i_step)\r
+       {\r
+               return;//未実装一号\r
+       }\r
+\r
 \r
        private int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram) throws NyARException\r
        {\r
-               int[] in_buf = (int[]) i_reader.getBuffer();\r
-               int[] histgram = o_histgram;\r
+               //最大画像サイズの制限\r
+               assert i_size.w*i_size.h<0x40000000;\r
 \r
-               // ヒストグラムを作成\r
+               int[] histgram = o_histgram;\r
+               \r
+               //ヒストグラム作成              \r
                for (int i = 0; i < 256; i++) {\r
-                       histgram[i] = 0;\r
-               }\r
-               int sum = 0;\r
-               for (int y = 0; y < i_size.h; y++) {\r
-                       int sum2 = 0;\r
-                       for (int x = 0; x < i_size.w; x++) {\r
-                               int v = in_buf[y* i_size.w+x];\r
-                               histgram[v]++;\r
-                               sum2 += v;\r
-                       }\r
-                       sum = sum + sum2 / i_size.w;\r
+                       o_histgram[i] = 0;\r
                }\r
+               this._histgram.createHistgramImpl(i_reader, i_size, o_histgram);\r
+\r
                // 閾値ピクセル数確定\r
-               int th_pixcels = i_size.w * i_size.h * this._persentage / 100;\r
+               final int th_pixcels = i_size.w * i_size.h * this._persentage / 100;\r
                int th_wk;\r
                int th_w, th_b;\r
 \r
index 4b51215..4e67d10 100644 (file)
@@ -8,7 +8,7 @@
  * http://www.hitl.washington.edu/artoolkit/\r
  *\r
  * The NyARToolkit is Java version ARToolkit class library.\r
- * Copyright (C)2008-2009 R.Iizuka\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
index b8cfbd5..f11699f 100644 (file)
@@ -8,7 +8,7 @@
  * http://www.hitl.washington.edu/artoolkit/\r
  *\r
  * The NyARToolkit is Java version ARToolkit class library.\r
- * Copyright (C)2008-2009 R.Iizuka\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
index b9302e1..3b4ef83 100644 (file)
@@ -8,7 +8,7 @@
  * http://www.hitl.washington.edu/artoolkit/\r
  *\r
  * The NyARToolkit is Java version ARToolkit class library.\r
- * Copyright (C)2008-2009 R.Iizuka\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
index dab26f0..84ab726 100644 (file)
@@ -1,3 +1,34 @@
+/* \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.nyidmarker.data;\r
 \r
 \r
index 9ecdbe0..3c49a16 100644 (file)
@@ -1,3 +1,34 @@
+/* \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.nyidmarker.data;\r
 \r
 import jp.nyatla.nyartoolkit.nyidmarker.NyIdMarkerPattern;\r
index 8034e61..8e8a147 100644 (file)
@@ -1,3 +1,34 @@
+/* \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.nyidmarker.data;\r
 \r
 import jp.nyatla.nyartoolkit.nyidmarker.*;\r
index 90b1433..2e771d0 100644 (file)
@@ -1,3 +1,34 @@
+/* \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.nyidmarker.data;\r
 \r
 public class NyIdMarkerData_RawBit implements INyIdMarkerData\r
index 762e11d..47e3fff 100644 (file)
@@ -31,11 +31,11 @@ import jp.nyatla.nyartoolkit.core.raster.*;
 import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
 import jp.nyatla.nyartoolkit.core.transmat.*;\r
 import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;\r
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
 import jp.nyatla.nyartoolkit.core.types.*;\r
 import jp.nyatla.nyartoolkit.nyidmarker.*;\r
-import jp.nyatla.nyartoolkit.nyidmarker.data.INyIdMarkerData;\r
-import jp.nyatla.nyartoolkit.nyidmarker.data.INyIdMarkerDataEncoder;\r
-\r
+import jp.nyatla.nyartoolkit.nyidmarker.data.*;\r
+import jp.nyatla.nyartoolkit.core2.rasteranalyzer.threshold.*;\r
 \r
 public abstract class SingleNyIdMarkerProcesser\r
 {\r
@@ -60,8 +60,6 @@ public abstract class SingleNyIdMarkerProcesser
        private INyIdMarkerData _data_temp;\r
        private INyIdMarkerData _data_current;\r
 \r
-       \r
-       private int _base_threshold = 110;\r
        private int _current_threshold;\r
        // [AR]検出結果の保存用\r
        private NyARBinRaster _bin_raster;\r
@@ -71,7 +69,7 @@ public abstract class SingleNyIdMarkerProcesser
        private NyIdMarkerPickup _id_pickup = new NyIdMarkerPickup();\r
 \r
 \r
-       protected SingleNyIdMarkerProcesser(NyARParam i_param,INyIdMarkerDataEncoder i_encoder) throws NyARException\r
+       protected SingleNyIdMarkerProcesser(NyARParam i_param,INyIdMarkerDataEncoder i_encoder,int i_raster_format) throws NyARException\r
        {\r
                NyARIntSize scr_size = i_param.getScreenSize();\r
                // 解析オブジェクトを作る\r
@@ -85,14 +83,10 @@ public abstract class SingleNyIdMarkerProcesser
                this._is_active=false;\r
                this._data_temp=i_encoder.createDataInstance();\r
                this._data_current=i_encoder.createDataInstance();\r
+               this._threshold_detect=new NyARRasterThresholdAnalyzer_SlidePTile(15,i_raster_format);\r
                return;\r
        }\r
 \r
-       public void setBaseThreshold(int i_threshold)\r
-       {\r
-               this._base_threshold = i_threshold;\r
-               return;\r
-       }\r
        public void setMarkerWidth(int i_width)\r
        {\r
                this._marker_width=i_width;\r
@@ -131,15 +125,15 @@ public abstract class SingleNyIdMarkerProcesser
                        // マーカ認識依頼→継続認識\r
                        detectExistMarker(i_raster, square_stack);\r
                }\r
+               System.out.println(this._current_threshold);\r
                return;\r
        }\r
 \r
        \r
        private final NyIdMarkerPattern _marker_data=new NyIdMarkerPattern();\r
        private final NyIdMarkerParam _marker_param=new NyIdMarkerParam();\r
-\r
+       private final NyARRasterThresholdAnalyzer_SlidePTile _threshold_detect;\r
        \r
-\r
        /**新規マーカ検索 現在認識中のマーカがないものとして、最も認識しやすいマーカを1個認識します。\r
         */\r
        private void detectNewMarker(INyARRgbRaster i_raster, NyARSquareStack i_stack) throws NyARException\r
@@ -163,8 +157,20 @@ public abstract class SingleNyIdMarkerProcesser
                        marker_id=this._data_temp;\r
                        break;\r
                }\r
+               \r
                // 認識状態を更新\r
-               updateStatus((NyARSquare) this._square_list.getItem(square_index),marker_id, param);\r
+               final boolean is_id_found=updateStatus((NyARSquare) this._square_list.getItem(square_index),marker_id, param);\r
+\r
+               //閾値フィードバック(detectExistMarkerにもあるよ)\r
+               if(is_id_found){\r
+                       //マーカがあれば、マーカの周辺閾値を反映\r
+                       this._current_threshold=(this._current_threshold+param.threshold)/2;\r
+               }else{\r
+                       //マーカがなければ、探索+DualPTailで基準輝度検索\r
+                       this._threshold_detect.analyzeRaster(i_raster);\r
+                       this._current_threshold=(this._current_threshold+this._threshold_detect.getThreshold())/2;\r
+               }\r
+               return;\r
        }\r
 \r
        /**マーカの継続認識 現在認識中のマーカを優先して認識します。 \r
@@ -194,14 +200,25 @@ public abstract class SingleNyIdMarkerProcesser
                        break;\r
                }\r
                // 認識状態を更新\r
-               updateStatus((NyARSquare) this._square_list.getItem(square_index),marker_id,param);\r
+               final boolean is_id_found=updateStatus((NyARSquare) this._square_list.getItem(square_index),marker_id,param);\r
+\r
+               //閾値フィードバック(detectExistMarkerにもあるよ)\r
+               if(is_id_found){\r
+                       //マーカがあれば、マーカの周辺閾値を反映\r
+                       this._current_threshold=(this._current_threshold+param.threshold)/2;\r
+               }else{\r
+                       //マーカがなければ、探索+DualPTailで基準輝度検索\r
+                       this._threshold_detect.analyzeRaster(i_raster);\r
+                       this._current_threshold=(this._current_threshold+this._threshold_detect.getThreshold())/2;\r
+               }\r
+               return;\r
        }\r
 \r
        private NyARTransMatResult __NyARSquare_result = new NyARTransMatResult();\r
 \r
        /**オブジェクトのステータスを更新し、必要に応じてハンドル関数を駆動します。\r
         */\r
-       private void updateStatus(NyARSquare i_square, INyIdMarkerData i_marker_data,NyIdMarkerParam i_param)  throws NyARException\r
+       private boolean updateStatus(NyARSquare i_square, INyIdMarkerData i_marker_data,NyIdMarkerParam i_param)  throws NyARException\r
        {\r
                boolean is_id_found=false;\r
                NyARTransMatResult result = this.__NyARSquare_result;\r
@@ -242,15 +259,7 @@ public abstract class SingleNyIdMarkerProcesser
                                throw new  NyARException();\r
                        }\r
                }\r
-               //閾値フィードバック\r
-               if(is_id_found){\r
-                       //マーカがあれば、マーカの周辺閾値を反映\r
-                       this._current_threshold=(this._current_threshold+i_param.threshold)/2;\r
-               }else{\r
-                       //マーカがなければ、探索+DualPTailで基準輝度検索(省略)\r
-                       this._current_threshold=(this._current_threshold+this._base_threshold)/2;\r
-               }\r
-               return;\r
+               return is_id_found;\r
        }       \r
        //通知ハンドラ\r
        protected abstract void onEnterHandler(INyIdMarkerData i_code);\r