OSDN Git Service

git-svn-id: http://svn.sourceforge.jp/svnroot/nyartoolkit/NyARToolkit/trunk@700 7cac0...
authornyatla <nyatla@7cac0a50-4618-4814-88d0-24b83990f816>
Tue, 30 Nov 2010 14:55:23 +0000 (14:55 +0000)
committerAtsuo Igarashi <atsuoigarashi@ubuntu.(none)>
Tue, 5 Apr 2011 07:25:45 +0000 (16:25 +0900)
lib/.classpath
lib/src.rpf/jp/nyatla/nyartoolkit/rpf/mklib/ARTKMarkerTable.java
lib/test/jp/nyatla/nyartoolkit/sample/NyIdTest.java [new file with mode: 0644]
lib/test/jp/nyatla/nyartoolkit/sample/RawFileTest.java [new file with mode: 0644]
lib/test/jp/nyatla/nyartoolkit/sample/SingleARMarkerTest.java [new file with mode: 0644]

index 274f0d3..c1de479 100644 (file)
@@ -2,7 +2,7 @@
 <classpath>\r
        <classpathentry kind="src" path="src"/>\r
        <classpathentry kind="src" path="src.rpf"/>\r
-       <classpathentry kind="src" path="src.sample"/>\r
+       <classpathentry kind="src" path="test"/>\r
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>\r
        <classpathentry kind="output" path="bin"/>\r
 </classpath>\r
index b5a9967..a94273b 100644 (file)
@@ -8,13 +8,9 @@ import jp.nyatla.nyartoolkit.core.match.NyARMatchPatt_Color_WITHOUT_PCA;
 import jp.nyatla.nyartoolkit.core.raster.rgb.NyARRgbRaster;\r
 import jp.nyatla.nyartoolkit.core.rasterreader.NyARPerspectiveRasterReader;\r
 import jp.nyatla.nyartoolkit.core.types.NyARBufferType;\r
-import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d;\r
 import jp.nyatla.nyartoolkit.core.types.stack.NyARObjectStack;\r
-import jp.nyatla.nyartoolkit.dev.rpf.reality.nyartk.NyARRealityTarget;\r
-import jp.nyatla.nyartoolkit.dev.rpf.realitysource.nyartk.NyARRealitySource;\r
-import jp.nyatla.nyartoolkit.nyidmarker.*;\r
-import jp.nyatla.nyartoolkit.nyidmarker.data.NyIdMarkerDataEncoder_RawBit;\r
-import jp.nyatla.nyartoolkit.nyidmarker.data.NyIdMarkerData_RawBit;\r
+import jp.nyatla.nyartoolkit.rpf.reality.nyartk.NyARRealityTarget;\r
+import jp.nyatla.nyartoolkit.rpf.realitysource.nyartk.NyARRealitySource;\r
 \r
 /**\r
  * 簡易なARToolKitパターンテーブルです。\r
diff --git a/lib/test/jp/nyatla/nyartoolkit/sample/NyIdTest.java b/lib/test/jp/nyatla/nyartoolkit/sample/NyIdTest.java
new file mode 100644 (file)
index 0000000..400f3f6
--- /dev/null
@@ -0,0 +1,147 @@
+/* \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 edition ARToolKit class library.\r
+ * Copyright (C)2008-2009 Ryo Iizuka\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (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 program.  If not, see <http://www.gnu.org/licenses/>.\r
+ * \r
+ * For further information please contact.\r
+ *     http://nyatla.jp/nyatoolkit/\r
+ *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.sample;\r
+\r
+import java.io.*;\r
+\r
+\r
+import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
+import jp.nyatla.nyartoolkit.core.transmat.*;\r
+import jp.nyatla.nyartoolkit.nyidmarker.data.*;\r
+import jp.nyatla.nyartoolkit.processor.*;\r
+\r
+/**\r
+ * 320x240のBGRA32で記録されたIdmarkerを撮影したRAWイメージから、\r
+ * Idマーカを認識します。\r
+ *\r
+ */\r
+public class NyIdTest\r
+{\r
+    public 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 Exception\r
+        {\r
+               super();//\r
+            initInstance(i_cparam, new NyIdMarkerDataEncoder_RawBit(),100, i_raster_format);\r
+            //アプリケーションフレームワークの初期化\r
+            return;\r
+        }\r
+        /**\r
+         * アプリケーションフレームワークのハンドラ(マーカ出現)\r
+         */\r
+        protected void onEnterHandler(INyIdMarkerData i_code)\r
+        {\r
+            synchronized (this._sync_object)\r
+            {\r
+                NyIdMarkerData_RawBit code = (NyIdMarkerData_RawBit)i_code;\r
+                if (code.length > 4)\r
+                {\r
+                    //4バイト以上の時はint変換しない。\r
+                    this.current_id = -1;//undefined_id\r
+                }\r
+                else\r
+                {\r
+                    this.current_id = 0;\r
+                    //最大4バイト繋げて1個のint値に変換\r
+                    for (int i = 0; i < code.length; i++)\r
+                    {\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
+            {\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
+            {\r
+                this.transmat = result;\r
+            }\r
+        }\r
+    }\r
+       private final String data_file = "../Data/320x240NyId.raw";\r
+       private final String camera_file = "../Data/camera_para.dat";\r
+    public NyIdTest()\r
+    {\r
+    }\r
+    public void Test() throws Exception\r
+    {\r
+        //AR用カメラパラメタファイルをロード\r
+        NyARParam ap = new NyARParam();\r
+        ap.loadARParamFromFile(camera_file);\r
+        ap.changeScreenSize(320, 240);\r
+\r
+               // 試験イメージの読み出し(320x240 BGRAのRAWデータ)\r
+               File f = new File(data_file);\r
+               FileInputStream fs = new FileInputStream(data_file);\r
+               byte[] buf = new byte[(int) f.length()];\r
+               fs.read(buf);           \r
+\r
+        NyARRgbRaster_RGB ra = new NyARRgbRaster_RGB(320, 240,false);\r
+        ra.wrapBuffer(buf);\r
+\r
+        MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferType());\r
+        pr.detectMarker(ra);\r
+        return;\r
+    }\r
+       public static void main(String[] args)\r
+       {\r
+\r
+               try {\r
+                       NyIdTest t = new NyIdTest();\r
+                       // t.Test_arGetVersion();\r
+                       t.Test();\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }    \r
+}\r
diff --git a/lib/test/jp/nyatla/nyartoolkit/sample/RawFileTest.java b/lib/test/jp/nyatla/nyartoolkit/sample/RawFileTest.java
new file mode 100644 (file)
index 0000000..a587cd7
--- /dev/null
@@ -0,0 +1,115 @@
+/* \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 edition ARToolKit class library.\r
+ * Copyright (C)2008-2009 Ryo Iizuka\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (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 program.  If not, see <http://www.gnu.org/licenses/>.\r
+ * \r
+ * For further information please contact.\r
+ *     http://nyatla.jp/nyatoolkit/\r
+ *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.sample;\r
+\r
+import java.io.*;\r
+import java.util.*;\r
+\r
+import jp.nyatla.nyartoolkit.core.*;\r
+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.detector.NyARSingleDetectMarker;\r
+import jp.nyatla.nyartoolkit.core.types.*;\r
+\r
+/**\r
+ * 320x240のBGRA32で記録されたRAWイメージから、1種類のパターンを認識し、\r
+ * その変換行列を1000回求め、それにかかったミリ秒時間を表示します。\r
+ * \r
+ */\r
+public class RawFileTest\r
+{\r
+       private final String code_file = "../Data/patt.hiro";\r
+\r
+       private final String data_file = "../Data/320x240ABGR.raw";\r
+\r
+       private final String camera_file = "../Data/camera_para.dat";\r
+\r
+       public RawFileTest()\r
+       {\r
+       }\r
+\r
+\r
+       public void Test_arDetectMarkerLite() throws Exception\r
+       {\r
+               // AR用カメラパラメタファイルをロード\r
+               NyARParam ap = new NyARParam();\r
+               ap.loadARParamFromFile(camera_file);\r
+               ap.changeScreenSize(320, 240);\r
+\r
+               // AR用のパターンコードを読み出し\r
+               NyARCode code = new NyARCode(16, 16);\r
+               code.loadARPattFromFile(code_file);\r
+\r
+               // 試験イメージの読み出し(320x240 BGRAのRAWデータ)\r
+               File f = new File(data_file);\r
+               FileInputStream fs = new FileInputStream(data_file);\r
+               byte[] buf = new byte[(int) f.length()];\r
+               fs.read(buf);\r
+               INyARRgbRaster ra = new NyARRgbRaster_BGRA(320, 240,false);\r
+               ra.wrapBuffer(buf);\r
+               // Blank_Raster ra=new Blank_Raster(320, 240);\r
+\r
+               // 1パターンのみを追跡するクラスを作成\r
+               NyARSingleDetectMarker ar = new NyARSingleDetectMarker(\r
+                               ap, code, 80.0,ra.getBufferType(),NyARSingleDetectMarker.PF_NYARTOOLKIT);\r
+               NyARTransMatResult result_mat = new NyARTransMatResult();\r
+               ar.setContinueMode(true);\r
+               ar.detectMarkerLite(ra, 100);\r
+               ar.getTransmationMatrix(result_mat);\r
+\r
+               // マーカーを検出\r
+               Date d2 = new Date();\r
+               for (int i = 0; i < 1000; i++) {\r
+                       // 変換行列を取得\r
+                       ar.detectMarkerLite(ra, 100);\r
+                       ar.getTransmationMatrix(result_mat);\r
+               }\r
+               Date d = new Date();\r
+               NyARDoublePoint3d ang=new NyARDoublePoint3d();\r
+               result_mat.getZXYAngle(ang);\r
+               System.out.println(d.getTime() - d2.getTime());\r
+               System.out.print(               ar.getConfidence());\r
+       }\r
+\r
+       public static void main(String[] args)\r
+       {\r
+\r
+               try {\r
+                       RawFileTest t = new RawFileTest();\r
+                       // t.Test_arGetVersion();\r
+                       t.Test_arDetectMarkerLite();\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+\r
+}\r
diff --git a/lib/test/jp/nyatla/nyartoolkit/sample/SingleARMarkerTest.java b/lib/test/jp/nyatla/nyartoolkit/sample/SingleARMarkerTest.java
new file mode 100644 (file)
index 0000000..edaed5f
--- /dev/null
@@ -0,0 +1,123 @@
+/* \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 edition ARToolKit class library.\r
+ * Copyright (C)2008-2009 Ryo Iizuka\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (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 program.  If not, see <http://www.gnu.org/licenses/>.\r
+ * \r
+ * For further information please contact.\r
+ *     http://nyatla.jp/nyatoolkit/\r
+ *     <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.sample;\r
+\r
+import java.io.*;\r
+\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
+import jp.nyatla.nyartoolkit.core.transmat.*;\r
+import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.processor.*;\r
+\r
+public class SingleARMarkerTest\r
+{\r
+       class MarkerProcessor extends SingleARMarkerProcesser\r
+       {       \r
+               private Object _sync_object=new Object();\r
+               public NyARTransMatResult transmat=null;\r
+               public int current_code=-1;\r
+\r
+               public MarkerProcessor(NyARParam i_cparam,int i_raster_format) throws NyARException\r
+               {\r
+                       //アプリケーションフレームワークの初期化\r
+                       super();\r
+                       initInstance(i_cparam,i_raster_format);\r
+                       return;\r
+               }\r
+               protected void onEnterHandler(int i_code)\r
+               {\r
+                       synchronized(this._sync_object){\r
+                               current_code=i_code;\r
+                       }\r
+               }\r
+               protected void onLeaveHandler()\r
+               {\r
+                       synchronized(this._sync_object){\r
+                               current_code=-1;\r
+                               this.transmat=null;\r
+                       }\r
+                       return;                 \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
+       private final static String CARCODE_FILE = "../Data/patt.hiro";\r
+       private final static String PARAM_FILE = "../Data/camera_para.dat";     \r
+       private final String data_file = "../Data/320x240ABGR.raw";\r
+\r
+       public SingleARMarkerTest()\r
+    {\r
+    }\r
+    public void Test() throws Exception\r
+    {\r
+        //AR用カメラパラメタファイルをロード\r
+        NyARParam ap = new NyARParam();\r
+        ap.loadARParamFromFile(PARAM_FILE);\r
+        ap.changeScreenSize(320, 240);\r
+\r
+               // 試験イメージの読み出し(320x240 BGRAのRAWデータ)\r
+               File f = new File(data_file);\r
+               FileInputStream fs = new FileInputStream(data_file);\r
+               byte[] buf = new byte[(int) f.length()];\r
+               fs.read(buf);           \r
+\r
+        NyARRgbRaster_BGRA ra = new NyARRgbRaster_BGRA(320, 240,false);\r
+        ra.wrapBuffer(buf);\r
+\r
+        MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferType());\r
+        NyARCode[] codes=new NyARCode[1];\r
+        codes[0]=new NyARCode(16,16);\r
+        codes[0].loadARPattFromFile(CARCODE_FILE);\r
+        pr.setARCodeTable(codes,16,80.0);\r
+        pr.detectMarker(ra);\r
+        return;\r
+    }\r
+       public static void main(String[] args)\r
+       {\r
+\r
+               try {\r
+                       SingleARMarkerTest t = new SingleARMarkerTest();\r
+                       // t.Test_arGetVersion();\r
+                       t.Test();\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }    \r
+}\r