OSDN Git Service

ライセンス文の更新
[nyartoolkit-and/nyartoolkit-and.git] / trunk / src / jp / nyatla / nyartoolkit / sample / 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\r
14  * modify it under the terms of the GNU Lesser General Public License\r
15  * as published by the Free Software Foundation; either version 3\r
16  * of the License, or (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 Lesser General Public License for more details\r
22  * \r
23  * You should have received a copy of the GNU Lesser General Public\r
24  * License 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.sample;\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                 }\r
65                 protected void onLeaveHandler()\r
66                 {\r
67                         synchronized(this._sync_object){\r
68                                 current_code=-1;\r
69                                 this.transmat=null;\r
70                         }\r
71                         return;                 \r
72                 }\r
73 \r
74                 protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)\r
75                 {\r
76                         synchronized(this._sync_object){\r
77                                 this.transmat=result;\r
78                         }                       \r
79                 }\r
80         }\r
81         private final static String CARCODE_FILE = "../Data/patt.hiro";\r
82         private final static String PARAM_FILE = "../Data/camera_para.dat";     \r
83         private final String data_file = "../Data/320x240ABGR.raw";\r
84 \r
85         public SingleARMarkerTest()\r
86     {\r
87     }\r
88     public void Test() throws Exception\r
89     {\r
90         //AR用カメラパラメタファイルをロード\r
91         NyARParam ap = new NyARParam();\r
92         ap.loadARParamFromFile(PARAM_FILE);\r
93         ap.changeScreenSize(320, 240);\r
94 \r
95                 // 試験イメージの読み出し(320x240 BGRAのRAWデータ)\r
96                 File f = new File(data_file);\r
97                 FileInputStream fs = new FileInputStream(data_file);\r
98                 byte[] buf = new byte[(int) f.length()];\r
99                 fs.read(buf);           \r
100 \r
101         NyARRgbRaster_BGRA ra = NyARRgbRaster_BGRA.wrap(buf, 320, 240);\r
102 \r
103         MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferReader().getBufferType());\r
104         NyARCode[] codes=new NyARCode[1];\r
105         codes[0]=new NyARCode(16,16);\r
106         codes[0].loadARPattFromFile(CARCODE_FILE);\r
107         pr.setARCodeTable(codes,16,80.0);\r
108         pr.detectMarker(ra);\r
109         return;\r
110     }\r
111         public static void main(String[] args)\r
112         {\r
113 \r
114                 try {\r
115                         SingleARMarkerTest t = new SingleARMarkerTest();\r
116                         // t.Test_arGetVersion();\r
117                         t.Test();\r
118                 } catch (Exception e) {\r
119                         e.printStackTrace();\r
120                 }\r
121         }    \r
122 }\r