OSDN Git Service

[更新]NyARToolkit/nyatlaブランチ
[nyartoolkit-and/nyartoolkit-and.git] / src / jp / nyatla / nyartoolkit / sample / RawFileTest.java
1 /* \r
2  * PROJECT: NyARToolkit\r
3  * --------------------------------------------------------------------------------\r
4  *\r
5  * The NyARToolkit is Java version ARToolkit class library.\r
6  * Copyright (C)2008 R.Iizuka\r
7  *\r
8  * This program is free software; you can redistribute it and/or\r
9  * modify it under the terms of the GNU General Public License\r
10  * as published by the Free Software Foundation; either version 2\r
11  * of the License, or (at your option) any later version.\r
12  * \r
13  * This program is distributed in the hope that it will be useful,\r
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
16  * GNU General Public License for more details.\r
17  * \r
18  * You should have received a copy of the GNU General Public License\r
19  * along with this framework; if not, write to the Free Software\r
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
21  * \r
22  * For further information please contact.\r
23  *      http://nyatla.jp/nyatoolkit/\r
24  *      <airmail(at)ebony.plala.or.jp>\r
25  * \r
26  */\r
27 package jp.nyatla.nyartoolkit.sample;\r
28 \r
29 \r
30 import java.io.*;\r
31 import java.util.*;\r
32 \r
33 import jp.nyatla.nyartoolkit.core.*;\r
34 import jp.nyatla.nyartoolkit.core.raster.*;\r
35 import jp.nyatla.nyartoolkit.detector.*;\r
36 import jp.nyatla.nyartoolkit.core.transmat.*;\r
37 \r
38 /**\r
39  * 320x240のBGRA32で記録されたRAWイメージから、1種類のパターンを認識し、\r
40  * その変換行列を1000回求め、それにかかったミリ秒時間を表示します。\r
41  *\r
42  */\r
43 public class RawFileTest {\r
44     private final String code_file  ="../Data/patt.hiro";\r
45     private final String data_file  ="../Data/320x240ABGR.raw";\r
46     private final String camera_file="../Data/camera_para.dat";\r
47     public RawFileTest()\r
48     {\r
49     }\r
50     public void Test_arDetectMarkerLite() throws Exception\r
51     {\r
52         //AR用カメラパラメタファイルをロード\r
53         NyARParam ap    =new NyARParam();\r
54         ap.loadFromARFile(camera_file);\r
55         ap.changeSize(320,240);\r
56 \r
57         //AR用のパターンコードを読み出し  \r
58         NyARCode code=new NyARCode(16,16);\r
59         code.loadFromARFile(code_file);\r
60 \r
61         //試験イメージの読み出し(320x240 BGRAのRAWデータ)\r
62         File f=new File(data_file);\r
63         FileInputStream fs=new FileInputStream(data_file);\r
64         byte[] buf=new byte[(int)f.length()];\r
65         fs.read(buf);\r
66         NyARRaster_BGRA ra=NyARRaster_BGRA.wrap(buf, 320, 240);\r
67         //              Blank_Raster ra=new Blank_Raster(320, 240);\r
68 \r
69         //1パターンのみを追跡するクラスを作成\r
70         NyARSingleDetectMarker ar=new NyARSingleDetectMarker(ap,code,80.0);\r
71         NyARTransMatResult result_mat=new NyARTransMatResult();\r
72         ar.setContinueMode(false);\r
73         ar.detectMarkerLite(ra,100);\r
74         ar.getTransmationMatrix(result_mat);\r
75 \r
76         //マーカーを検出\r
77         Date d2=new Date();\r
78         for(int i=0;i<1000;i++){\r
79             //変換行列を取得\r
80             ar.detectMarkerLite(ra,100);\r
81             ar.getTransmationMatrix(result_mat);\r
82         }\r
83         Date d=new Date();\r
84         System.out.println(d.getTime()-d2.getTime()); \r
85     }\r
86     public static void main(String[] args)\r
87     {\r
88 \r
89         try{\r
90             RawFileTest t=new RawFileTest();\r
91             //t.Test_arGetVersion();\r
92             t.Test_arDetectMarkerLite();\r
93         }catch(Exception e){\r
94             e.printStackTrace();\r
95         }\r
96     }\r
97 \r
98 }\r