OSDN Git Service

[Backup]NyARToolkit for Java
[nyartoolkit-and/nyartoolkit-and.git] / src / jp / nyatla / nyartoolkit / detector / NyARSingleDetectMarker.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 version ARToolkit class library.\r
11  * Copyright (C)2008 R.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 General Public License\r
15  * as published by the Free Software Foundation; either version 2\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 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 framework; if not, write to the Free Software\r
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
26  * \r
27  * For further information please contact.\r
28  *      http://nyatla.jp/nyatoolkit/\r
29  *      <airmail(at)ebony.plala.or.jp>\r
30  * \r
31  */\r
32 package jp.nyatla.nyartoolkit.detector;\r
33 \r
34 import jp.nyatla.nyartoolkit.NyARException;\r
35 import jp.nyatla.nyartoolkit.core.*;\r
36 import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
37 import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt;\r
38 import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
39 \r
40 import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;\r
41 import jp.nyatla.nyartoolkit.core.squaredetect.*;\r
42 import jp.nyatla.nyartoolkit.core.pickup.*;\r
43 import jp.nyatla.nyartoolkit.core.transmat.*;\r
44 /**\r
45  * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。\r
46  * \r
47  */\r
48 public class NyARSingleDetectMarker extends NyARCustomSingleDetectMarker\r
49 {\r
50         public final static int PF_ARTOOLKIT_COMPATIBLE=1;\r
51         public final static int PF_NYARTOOLKIT=2;\r
52         public final static int PF_NYARTOOLKIT_ARTOOLKIT_FITTING=100;\r
53         public final static int PF_TEST2=201;\r
54         \r
55         /**\r
56          * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。\r
57          * \r
58          * @param i_param\r
59          * カメラパラメータを指定します。\r
60          * @param i_code\r
61          * 検出するARCodeを指定します。\r
62          * @param i_marker_width\r
63          * ARコードの物理サイズを、ミリメートルで指定します。\r
64          * @param i_input_raster_type\r
65          * 入力ラスタのピクセルタイプを指定します。この値は、INyARBufferReaderインタフェイスのgetBufferTypeの戻り値を指定します。\r
66          * @throws NyARException\r
67          */\r
68         public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_input_raster_type,int i_profile_id) throws NyARException\r
69         {\r
70                 super();\r
71                 initInstance(i_param,i_code,i_marker_width,i_input_raster_type,i_profile_id);\r
72                 return;\r
73         }\r
74         public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_input_raster_type) throws NyARException\r
75         {\r
76                 super();\r
77                 initInstance(i_param,i_code,i_marker_width,i_input_raster_type,PF_NYARTOOLKIT);\r
78                 return;\r
79         }\r
80         /**\r
81          * コンストラクタから呼び出す関数です。\r
82          * @param i_ref_param\r
83          * @param i_ref_code\r
84          * @param i_marker_width\r
85          * @param i_input_raster_type\r
86          * @param i_profile_id\r
87          * @throws NyARException\r
88          */\r
89         protected void initInstance(\r
90                 NyARParam       i_ref_param,\r
91                 NyARCode        i_ref_code,\r
92                 double          i_marker_width,\r
93                 int i_input_raster_type,\r
94                 int i_profile_id) throws NyARException\r
95         {\r
96                 final NyARRasterFilter_ARToolkitThreshold th=new NyARRasterFilter_ARToolkitThreshold(100,i_input_raster_type);\r
97                 INyARColorPatt patt_inst;\r
98                 INyARSquareDetector sqdetect_inst;\r
99                 INyARTransMat transmat_inst;\r
100 \r
101                 switch(i_profile_id){\r
102                 case PF_ARTOOLKIT_COMPATIBLE:\r
103                         patt_inst=new NyARColorPatt_O3(i_ref_code.getWidth(), i_ref_code.getHeight());\r
104                         sqdetect_inst=new NyARSquareDetector_ARToolKit(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
105                         transmat_inst=new NyARTransMat(i_ref_param);\r
106                         break;\r
107                 case PF_NYARTOOLKIT_ARTOOLKIT_FITTING:\r
108                         patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);\r
109                         sqdetect_inst=new NyARSquareDetector_Rle(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
110                         transmat_inst=new NyARTransMat(i_ref_param);\r
111                         break;\r
112                 case PF_NYARTOOLKIT:\r
113                         patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);\r
114                         sqdetect_inst=new NyARSquareDetector_Rle(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
115                         transmat_inst=new NyARTransMat_NyARToolkit(i_ref_param);\r
116                         break;\r
117                 default:\r
118                         throw new NyARException();\r
119                 }\r
120                 super.initInstance(patt_inst,sqdetect_inst,transmat_inst,th,i_ref_param,i_ref_code,i_marker_width);\r
121                 \r
122         }\r
123 \r
124         /**\r
125          * i_imageにマーカー検出処理を実行し、結果を記録します。\r
126          * \r
127          * @param i_raster\r
128          * マーカーを検出するイメージを指定します。イメージサイズは、コンストラクタで指定i_paramの\r
129          * スクリーンサイズと一致し、かつi_input_raster_typeに指定した形式でなければいけません。\r
130          * @return マーカーが検出できたかを真偽値で返します。\r
131          * @throws NyARException\r
132          */\r
133         public boolean detectMarkerLite(INyARRgbRaster i_raster,int i_threshold) throws NyARException\r
134         {\r
135                 ((NyARRasterFilter_ARToolkitThreshold)this._tobin_filter).setThreshold(i_threshold);\r
136                 return super.detectMarkerLite(i_raster);\r
137         }\r
138 }\r