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 version ARToolkit class library.
\r
11 * Copyright (C)2008 R.Iizuka
\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
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 framework; if not, write to the Free Software
\r
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
27 * For further information please contact.
\r
28 * http://nyatla.jp/nyatoolkit/
\r
29 * <airmail(at)ebony.plala.or.jp>
\r
32 package jp.nyatla.nyartoolkit.detector;
\r
34 import jp.nyatla.nyartoolkit.NyARException;
\r
35 import jp.nyatla.nyartoolkit.core.*;
\r
36 import jp.nyatla.nyartoolkit.core.match.NyARMatchPatt_Color_WITHOUT_PCA;
\r
37 import jp.nyatla.nyartoolkit.core.raster.*;
\r
39 * 1個のマーカーに対する変換行列を計算するクラスです。
\r
42 public class NyARSingleDetectMarker{
\r
43 private static final int AR_SQUARE_MAX=100;
\r
44 private NyARMatchPatt_Color_WITHOUT_PCA match_patt;
\r
45 private NyARDetectSquare square;
\r
46 private final NyARSquareList square_list=new NyARSquareList(AR_SQUARE_MAX);
\r
47 private NyARCode code;
\r
48 protected NyARTransMat transmat;
\r
49 private double marker_width;
\r
51 private int detected_direction;
\r
52 private double detected_confidence;
\r
53 private NyARSquare detected_square;
\r
54 private NyARColorPatt patt;
\r
55 public NyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width) throws NyARException
\r
58 this.square=new NyARDetectSquare(i_param);
\r
59 this.transmat=new NyARTransMat_O2(i_param);
\r
62 this.marker_width=i_marker_width;
\r
64 this.patt=new NyARColorPatt_O3(code.getWidth(),code.getHeight());
\r
66 this.match_patt=new NyARMatchPatt_Color_WITHOUT_PCA();
\r
69 * i_imageにマーカー検出処理を実行して、結果を保持します。
\r
73 * マーカーが検出できたかを真偽値で返します。
\r
74 * @throws NyARException
\r
76 public boolean detectMarkerLite(NyARRaster i_image,int i_thresh) throws NyARException
\r
78 detected_square=null;
\r
79 NyARSquareList l_square_list=this.square_list;
\r
81 square.detectSquare(i_image, i_thresh,l_square_list);
\r
83 int number_of_square=l_square_list.getSquareNum();
\r
85 if(number_of_square<1){
\r
90 // NyARSquare[] squares=square.getSquareArray();
\r
91 //評価基準になるパターンをイメージから切り出す
\r
92 patt.pickFromRaster(i_image,l_square_list.getSquare(0));
\r
94 if(!this.match_patt.setPatt(patt)){
\r
96 throw new NyARException();
\r
99 match_patt.evaluate(code);
\r
100 int square_index=0;
\r
101 int direction=match_patt.getDirection();
\r
102 double confidence=match_patt.getConfidence();
\r
103 for(int i=1;i<number_of_square;i++){
\r
105 patt.pickFromRaster(i_image,l_square_list.getSquare(i));
\r
107 match_patt.setPatt(patt);
\r
109 match_patt.evaluate(code);
\r
110 double c2=match_patt.getConfidence();
\r
114 //もっと一致するマーカーがあったぽい
\r
116 direction=match_patt.getDirection();
\r
120 detected_square=l_square_list.getSquare(square_index);
\r
121 detected_direction=direction;
\r
122 detected_confidence=confidence;
\r
126 * 変換行列を返します。直前に実行したdetectMarkerLiteが成功していないと使えません。
\r
127 * @param i_marker_width
\r
130 * double[3][4]の変換行列を返します。
\r
131 * @throws NyARException
\r
133 public NyARMat getTransmationMatrix() throws NyARException
\r
135 //一番一致したマーカーの位置とかその辺を計算
\r
136 transmat.transMat(detected_square,detected_direction,marker_width);
\r
137 return transmat.getTransformationMatrix();
\r
139 public double getConfidence()
\r
141 return detected_confidence;
\r
143 public int getDirection()
\r
145 return detected_direction;
\r
154 // public static class arUtil_c{
\r
155 // public static final int arFittingMode =Config.DEFAULT_FITTING_MODE;
\r
156 // private static final int arImageProcMode =Config.DEFAULT_IMAGE_PROC_MODE;
\r
157 // public static final int arTemplateMatchingMode =Config.DEFAULT_TEMPLATE_MATCHING_MODE;
\r
158 // public static final int arMatchingPCAMode =Config.DEFAULT_MATCHING_PCA_MODE;
\r
159 /*int arInitCparam( ARParam *param )*/
\r