2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java edition ARToolKit class library.
\r
11 * Copyright (C)2008-2009 Ryo Iizuka
\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
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
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
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
31 package jp.nyatla.nyartoolkit.sample;
\r
36 import jp.nyatla.nyartoolkit.core.param.NyARParam;
\r
37 import jp.nyatla.nyartoolkit.core.raster.rgb.*;
\r
38 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
\r
39 import jp.nyatla.nyartoolkit.core.transmat.*;
\r
40 import jp.nyatla.nyartoolkit.nyidmarker.data.*;
\r
41 import jp.nyatla.nyartoolkit.processor.*;
\r
44 * 320x240のBGRA32で記録されたIdmarkerを撮影したRAWイメージから、
\r
48 public class NyIdTest
\r
50 public class MarkerProcessor extends SingleNyIdMarkerProcesser
\r
52 private Object _sync_object = new Object();
\r
53 public NyARTransMatResult transmat = null;
\r
54 public int current_id = -1;
\r
56 public MarkerProcessor(NyARParam i_cparam, int i_raster_format) throws Exception
\r
59 initInstance(i_cparam, new NyIdMarkerDataEncoder_RawBit(), i_raster_format);
\r
60 //アプリケーションフレームワークの初期化
\r
64 * アプリケーションフレームワークのハンドラ(マーカ出現)
\r
66 protected void onEnterHandler(INyIdMarkerData i_code)
\r
68 synchronized (this._sync_object)
\r
70 NyIdMarkerData_RawBit code = (NyIdMarkerData_RawBit)i_code;
\r
71 if (code.length > 4)
\r
73 //4バイト以上の時はint変換しない。
\r
74 this.current_id = -1;//undefined_id
\r
78 this.current_id = 0;
\r
79 //最大4バイト繋げて1個のint値に変換
\r
80 for (int i = 0; i < code.length; i++)
\r
82 this.current_id = (this.current_id << 8) | code.packet[i];
\r
85 this.transmat = null;
\r
89 * アプリケーションフレームワークのハンドラ(マーカ消滅)
\r
91 protected void onLeaveHandler()
\r
93 synchronized (this._sync_object)
\r
95 this.current_id = -1;
\r
96 this.transmat = null;
\r
101 * アプリケーションフレームワークのハンドラ(マーカ更新)
\r
103 protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)
\r
105 synchronized (this._sync_object)
\r
107 this.transmat = result;
\r
111 private final String data_file = "../Data/320x240NyId.raw";
\r
112 private final String camera_file = "../Data/camera_para.dat";
\r
116 public void Test() throws Exception
\r
118 //AR用カメラパラメタファイルをロード
\r
119 NyARParam ap = new NyARParam();
\r
120 ap.loadARParamFromFile(camera_file);
\r
121 ap.changeScreenSize(320, 240);
\r
123 // 試験イメージの読み出し(320x240 BGRAのRAWデータ)
\r
124 File f = new File(data_file);
\r
125 FileInputStream fs = new FileInputStream(data_file);
\r
126 byte[] buf = new byte[(int) f.length()];
\r
129 NyARRgbRaster_RGB ra = NyARRgbRaster_RGB.wrap(buf, 320, 240);
\r
131 MarkerProcessor pr = new MarkerProcessor(ap, ra.getBufferReader().getBufferType());
\r
132 pr.detectMarker(ra);
\r
135 public static void main(String[] args)
\r
139 NyIdTest t = new NyIdTest();
\r
140 // t.Test_arGetVersion();
\r
142 } catch (Exception e) {
\r
143 e.printStackTrace();
\r