OSDN Git Service

fdd4fa74db324849de0172f9327976bab9e9ecc5
[nyartoolkit-and/nyartoolkit-and.git] / lib / test / jp / nyatla / nyartoolkit / test / SingleARMarkerTest.java
1 /* \r
2  * PROJECT: NyARToolkit\r
3  * --------------------------------------------------------------------------------\r
4  * This work is based on the original ARToolKit developed by\r
5  *   Hirokazu Kato\r
6  *   Mark Billinghurst\r
7  *   HITLab, University of Washington, Seattle\r
8  * http://www.hitl.washington.edu/artoolkit/\r
9  *\r
10  * The NyARToolkit is Java edition ARToolKit class library.\r
11  * Copyright (C)2008-2009 Ryo Iizuka\r
12  *\r
13  * This program is free software: you can redistribute it and/or modify\r
14  * it under the terms of the GNU General Public License as published by\r
15  * the Free Software Foundation, either version 3 of the License, or\r
16  * (at your option) any later version.\r
17  * \r
18  * This program is distributed in the hope that it will be useful,\r
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
21  * GNU General Public License for more details.\r
22  *\r
23  * You should have received a copy of the GNU General Public License\r
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
25  * \r
26  * For further information please contact.\r
27  *      http://nyatla.jp/nyatoolkit/\r
28  *      <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
29  * \r
30  */\r
31 package jp.nyatla.nyartoolkit.test;\r
32 \r
33 import java.io.*;\r
34 \r
35 \r
36 import jp.nyatla.nyartoolkit.NyARException;\r
37 import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
38 import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
39 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;\r
40 import jp.nyatla.nyartoolkit.core.transmat.*;\r
41 import jp.nyatla.nyartoolkit.core.*;\r
42 import jp.nyatla.nyartoolkit.processor.*;\r
43 \r
44 public class SingleARMarkerTest\r
45 {\r
46         class MarkerProcessor extends SingleARMarkerProcesser\r
47         {       \r
48                 private Object _sync_object=new Object();\r
49                 public NyARTransMatResult transmat=null;\r
50                 public int current_code=-1;\r
51 \r
52                 public MarkerProcessor(NyARParam i_cparam,int i_raster_format) throws NyARException\r
53                 {\r
54                         //アプリケーションフレームワークの初期化\r
55                         super();\r
56                         initInstance(i_cparam,i_raster_format);\r
57                         return;\r
58                 }\r
59                 protected void onEnterHandler(int i_code)\r
60                 {\r
61                         synchronized(this._sync_object){\r
62                                 current_code=i_code;\r
63                         }\r
64                         System.out.println("Marker Number:"+i_code);\r
65                 }\r
66                 protected void onLeaveHandler()\r
67                 {\r
68                         synchronized(this._sync_object){\r
69                                 current_code=-1;\r
70                                 this.transmat=null;\r
71                         }\r
72                         return;                 \r
73                 }\r
74 \r
75                 protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)\r
76                 {\r
77                         synchronized(this._sync_object){\r
78                                 this.transmat=result;\r
79                         }                       \r
80                 }\r
81         }\r
82         private final static String CARCODE_FILE = "../Data/patt.hiro";\r
83         private final static String PARAM_FILE = "../Data/camera_para.dat";     \r
84         private final String data_file = "../Data/320x240ABGR.raw";\r
85 \r
86         public SingleARMarkerTest()\r
87     {\r
88     }\r
89     public void Test() throws Exception\r
90     {\r
91         //AR用カメラパラメタファイルをロード\r
92         NyARParam ap = new NyARParam();\r
93         ap.loadARParamFromFile(PARAM_FILE);\r
94         ap.changeScreenSize(320, 240);\r
95 \r
96                 // 試験イメージの読み出し(320x240 BGRAのRAWデータ)\r
97                 File f = new File(data_file);\r
98                 FileInputStream fs = new FileInputStream(data_file);\r
99                 byte[] buf = new byte[(int) f.length()];\r
100                 fs.read(buf);           \r
101 \r
102         NyARRgbRaster_BGRA ra = new NyARRgbRaster_BGRA(320, 240,false);\r
103         ra.wrapBuffer(buf);\r
104 \r
105         MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferType());\r
106         NyARCode[] codes=new NyARCode[1];\r
107         codes[0]=new NyARCode(16,16);\r
108         codes[0].loadARPattFromFile(CARCODE_FILE);\r
109         pr.setARCodeTable(codes,16,80.0);\r
110         pr.detectMarker(ra);\r
111         return;\r
112     }\r
113         public static void main(String[] args)\r
114         {\r
115 \r
116                 try {\r
117                         SingleARMarkerTest t = new SingleARMarkerTest();\r
118                         // t.Test_arGetVersion();\r
119                         t.Test();\r
120                 } catch (Exception e) {\r
121                         e.printStackTrace();\r
122                 }\r
123         }    \r
124 }\r