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.core.match;
\r
33 import jp.nyatla.nyartoolkit.NyARException;
\r
34 import jp.nyatla.nyartoolkit.core.*;
\r
37 * このクラスは、グレースケールで2パターンの一致度を計算します。
\r
38 * 評価アルゴリズムは、ARToolKitの、AR_TEMPLATE_MATCHING_BWと同様です。
\r
39 * 比較対象のデータには、{@link NyARMatchPattDeviationBlackWhiteData}クラスの物を使います。
\r
41 public class NyARMatchPatt_BlackWhite implements INyARMatchPatt
\r
43 /** 基準となるARマーカパターンを格納するオブジェクトへの参照値です。*/
\r
44 protected NyARCode _ref_code_patt;
\r
46 protected int _pixels;
\r
49 * 基準パターンの解像度を指定して、インスタンスを生成します。
\r
50 * このコンストラクタで生成したインスタンスの基準パターンは、NULLになっています。
\r
51 * 後で基準パターンを{@link #setARCode}関数で設定してください。
\r
57 public NyARMatchPatt_BlackWhite(int i_width, int i_height)
\r
60 this._pixels=i_height*i_width;
\r
65 * 基準パターンを元に、評価インスタンスを生成します。
\r
69 public NyARMatchPatt_BlackWhite(NyARCode i_code_ref)
\r
72 this._pixels=i_code_ref.getWidth()*i_code_ref.getHeight();
\r
74 this._ref_code_patt=i_code_ref;
\r
78 * 基準パターンをセットします。セットできる基準パターンは、コンストラクタに設定したサイズと同じものである必要があります。
\r
80 * セットする基準パターンを格納したオブジェクト
\r
81 * @throws NyARException
\r
83 public void setARCode(NyARCode i_code_ref)
\r
85 this._ref_code_patt=i_code_ref;
\r
89 * この関数は、現在の基準パターンと検査パターンを比較して、類似度を計算します。
\r
91 * 検査パターンを格納したオブジェクトです。このサイズは、基準パターンと一致している必要があります。
\r
95 * 検査に成功するとtrueを返します。
\r
96 * @throws NyARException
\r
98 public boolean evaluate(NyARMatchPattDeviationBlackWhiteData i_patt,NyARMatchPattResult o_result) throws NyARException
\r
100 assert this._ref_code_patt!=null;
\r
102 final int[] linput = i_patt.refData();
\r
105 int res = NyARMatchPattResult.DIRECTION_UNKNOWN;
\r
108 for (int j = 0; j < 4; j++) {
\r
111 final NyARMatchPattDeviationBlackWhiteData code_patt=this._ref_code_patt.getBlackWhiteData(j);
\r
112 final int[] pat_j = code_patt.refData();
\r
113 //<全画素について、比較(FORの1/16展開)/>
\r
115 for(i=this._pixels-1;i>=0;i--){
\r
116 sum += linput[i] * pat_j[i];
\r
118 //0.7776737688877927がでればOK
\r
119 final double sum2 = sum / code_patt.getPow() / i_patt.getPow();// sum2 = sum / patpow[k][j]/ datapow;
\r
125 o_result.direction = res;
\r
126 o_result.confidence= max;
\r