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.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
44 public class SingleARMarkerTest
\r
46 class MarkerProcessor extends SingleARMarkerProcesser
\r
48 private Object _sync_object=new Object();
\r
49 public NyARTransMatResult transmat=null;
\r
50 public int current_code=-1;
\r
52 public MarkerProcessor(NyARParam i_cparam,int i_raster_format) throws NyARException
\r
54 //アプリケーションフレームワークの初期化
\r
56 initInstance(i_cparam,i_raster_format);
\r
59 protected void onEnterHandler(int i_code)
\r
61 synchronized(this._sync_object){
\r
62 current_code=i_code;
\r
65 protected void onLeaveHandler()
\r
67 synchronized(this._sync_object){
\r
74 protected void onUpdateHandler(NyARSquare i_square, NyARTransMatResult result)
\r
76 synchronized(this._sync_object){
\r
77 this.transmat=result;
\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
85 public SingleARMarkerTest()
\r
88 public void Test() throws Exception
\r
90 //AR用カメラパラメタファイルをロード
\r
91 NyARParam ap = new NyARParam();
\r
92 ap.loadARParamFromFile(PARAM_FILE);
\r
93 ap.changeScreenSize(320, 240);
\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
101 NyARRgbRaster_BGRA ra = NyARRgbRaster_BGRA.wrap(buf, 320, 240);
\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
111 public static void main(String[] args)
\r
115 SingleARMarkerTest t = new SingleARMarkerTest();
\r
116 // t.Test_arGetVersion();
\r
118 } catch (Exception e) {
\r
119 e.printStackTrace();
\r