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.detector;
\r
33 import jp.nyatla.nyartoolkit.NyARException;
\r
34 import jp.nyatla.nyartoolkit.core.*;
\r
35 import jp.nyatla.nyartoolkit.core.param.NyARParam;
\r
36 import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt;
\r
37 import jp.nyatla.nyartoolkit.core.raster.rgb.*;
\r
39 import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;
\r
40 import jp.nyatla.nyartoolkit.core.squaredetect.*;
\r
41 import jp.nyatla.nyartoolkit.core.pickup.*;
\r
42 import jp.nyatla.nyartoolkit.core.types.*;
\r
43 import jp.nyatla.nyartoolkit.core.transmat.*;
\r
46 * このクラスは、1個のマーカを取り扱うマーカ検出器です。
\r
47 * 登録した1個のARマーカに対応するマーカを入力画像から検出し、その変換行列と一致度を返します。
\r
50 * <li>インスタンスを作成します。パラメータには、計算アルゴリズムと入力画像形式、カメラパラメータ、検出するマーカがあります。
\r
51 * <li>{@link #detectMarkerLite}関数に画像と敷居値を入力して、マーカを検出します。
\r
52 * <li>マーカが見つかると、インスタンスのプロパティが更新されます。{@link #getConfidence}等の関数を使って、取得したマーカの状態を得ます。
\r
53 * <li>以降は、この処理を繰り返してマーカのパラメータを更新します。
\r
57 public class NyARSingleDetectMarker extends NyARCustomSingleDetectMarker
\r
59 /** ARToolKit互換のアルゴリズムを選択します。*/
\r
60 public final static int PF_ARTOOLKIT_COMPATIBLE=1;
\r
61 /** NyARToolKitのアルゴリズムを選択します。*/
\r
62 public final static int PF_NYARTOOLKIT=2;
\r
63 /** ARToolKit互換アルゴリズムと、NyARToolKitのアルゴリズムの混合です。2D系にNyARToolkit,3D系にARToolKitのアルゴリズムを選択します。*/
\r
64 public final static int PF_NYARTOOLKIT_ARTOOLKIT_FITTING=100;
\r
66 public final static int PF_TEST2=201;
\r
69 * RleLabelingを使った矩形検出機
\r
71 private class RleDetector extends NyARSquareContourDetector_Rle
\r
73 NyARCustomSingleDetectMarker _parent;
\r
74 public RleDetector(NyARCustomSingleDetectMarker i_parent,NyARIntSize i_size) throws NyARException
\r
77 this._parent=i_parent;
\r
79 protected void onSquareDetect(NyARIntCoordinates i_coord,int[] i_vertex_index) throws NyARException
\r
81 this._parent.updateSquareInfo(i_coord, i_vertex_index);
\r
85 * ARTKラべリングを使った矩形検出機へのブリッジ
\r
87 class ARTKDetector extends NyARSquareContourDetector_ARToolKit
\r
89 NyARCustomSingleDetectMarker _parent;
\r
90 public ARTKDetector(NyARCustomSingleDetectMarker i_parent,NyARIntSize i_size) throws NyARException
\r
93 this._parent=i_parent;
\r
95 protected void onSquareDetect(NyARIntCoordinates i_coord,int[] i_vertex_index) throws NyARException
\r
97 this._parent.updateSquareInfo(i_coord, i_vertex_index);
\r
103 * 指定した1種のマーカを1個検出するインスタンスを作ります。
\r
105 * カメラパラメータを指定します。このサイズは、{@link #detectMarker}に入力する画像と同じである必要があります。
\r
107 * 検出するマーカパターンを指定します。
\r
108 * @param i_marker_width
\r
109 * 正方形マーカの物理サイズをmm単位で指定します。
\r
110 * @param i_input_raster_type
\r
111 * {@link #detectMarker}に入力するラスタの画素形式を指定します。
\r
112 * この値は、{@link INyARRgbRaster#getBufferType}関数の戻り値を利用します。
\r
113 * @param i_profile_id
\r
114 * 計算アルゴリズムの選択値です。以下の定数のいずれかを指定します。
\r
116 * <li>{@link NyARSingleDetectMarker#PF_ARTOOLKIT_COMPATIBLE}
\r
117 * <li>{@link NyARSingleDetectMarker#PF_NYARTOOLKIT}
\r
118 * <li>{@link NyARSingleDetectMarker#PF_NYARTOOLKIT_ARTOOLKIT_FITTING}
\r
120 * @throws NyARException
\r
122 public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_input_raster_type,int i_profile_id) throws NyARException
\r
125 initialize(i_param,i_code,i_marker_width,i_input_raster_type,i_profile_id);
\r
130 * 指定した1種のマーカを1個検出するインスタンスを作ります。
\r
131 * i_profile_idに{@link NyARSingleDetectMarker#PF_NYARTOOLKIT}を選択した{@link NyARSingleDetectMarker#NyARSingleDetectMarker(NyARParam, NyARCode, double, int, int)と同じです。
\r
132 * @see NyARSingleDetectMarker#NyARSingleDetectMarker(NyARParam, NyARCode, double, int, int)
\r
137 * @param i_marker_width
\r
139 * @param i_input_raster_type
\r
141 * @throws NyARException
\r
143 public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_input_raster_type) throws NyARException
\r
146 initialize(i_param,i_code,i_marker_width,i_input_raster_type,PF_NYARTOOLKIT);
\r
150 * この関数は、インスタンスを初期化します。
\r
151 * 引数は、{@link NyARSingleDetectMarker#NyARSingleDetectMarker}の対応する引数と同じです。
\r
152 * @see NyARSingleDetectMarker#NyARSingleDetectMarker(NyARParam, NyARCode, double, int, int)
\r
153 * @param i_ref_param
\r
155 * @param i_ref_code
\r
157 * @param i_marker_width
\r
159 * @param i_input_raster_type
\r
161 * @param i_profile_id
\r
163 * @throws NyARException
\r
165 private void initialize(
\r
166 NyARParam i_ref_param,
\r
167 NyARCode i_ref_code,
\r
168 double i_marker_width,
\r
169 int i_input_raster_type,
\r
170 int i_profile_id) throws NyARException
\r
172 final NyARRasterFilter_ARToolkitThreshold th=new NyARRasterFilter_ARToolkitThreshold(100,i_input_raster_type);
\r
173 INyARColorPatt patt_inst;
\r
174 NyARSquareContourDetector sqdetect_inst;
\r
175 INyARTransMat transmat_inst;
\r
177 switch(i_profile_id){
\r
178 case PF_ARTOOLKIT_COMPATIBLE:
\r
179 patt_inst=new NyARColorPatt_O3(i_ref_code.getWidth(), i_ref_code.getHeight());
\r
180 sqdetect_inst=new ARTKDetector(this,i_ref_param.getScreenSize());
\r
181 transmat_inst=new NyARTransMat_ARToolKit(i_ref_param);
\r
183 case PF_NYARTOOLKIT_ARTOOLKIT_FITTING:
\r
184 patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25,i_input_raster_type);
\r
185 sqdetect_inst=new RleDetector(this,i_ref_param.getScreenSize());
\r
186 transmat_inst=new NyARTransMat_ARToolKit(i_ref_param);
\r
188 case PF_NYARTOOLKIT://default
\r
189 // patt_inst=new NyARColorPatt_Perspective(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);
\r
190 patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25,i_input_raster_type);
\r
191 sqdetect_inst=new RleDetector(this,i_ref_param.getScreenSize());
\r
192 transmat_inst=new NyARTransMat(i_ref_param);
\r
195 throw new NyARException();
\r
197 super.initInstance(patt_inst,sqdetect_inst,transmat_inst,th,i_ref_param,i_ref_code,i_marker_width);
\r
201 * この関数は、画像からマーカを検出します。
\r
202 * 関数は、画像の二値化、ラべリング、矩形検出、パターンの一致判定処理までを行い、画像中にある最も一致したパターンを持つ矩形の座標を、thisの
\r
205 * 検出元の画像を指定します。この画像は、コンストラクタで指定したものと同じサイズ、画素形式に限られます。
\r
206 * @param i_threshold
\r
207 * 二値化の敷居値を指定します。0<=n<256の間で指定します。
\r
209 * マーカの検出に成功すると、trueを返します。
\r
210 * @throws NyARException
\r
212 public boolean detectMarkerLite(INyARRgbRaster i_raster,int i_threshold) throws NyARException
\r
214 ((NyARRasterFilter_ARToolkitThreshold)this._tobin_filter).setThreshold(i_threshold);
\r
215 return super.detectMarkerLite(i_raster);
\r