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.sandbox.qrcode;
\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.raster.rgb.*;
\r
38 import jp.nyatla.nyartoolkit.core.rasterfilter.*;
\r
39 import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2gs.INyARRasterFilter_RgbToGs;
\r
40 import jp.nyatla.nyartoolkit.core.raster.*;
\r
41 import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareContourDetector;
\r
42 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
\r
43 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
\r
44 import jp.nyatla.nyartoolkit.core.transmat.*;
\r
45 import jp.nyatla.nyartoolkit.core.types.*;
\r
46 import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.*;
\r
49 * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。
\r
52 public class NyARSingleQrDetector
\r
54 private static final int AR_SQUARE_MAX = 100;
\r
56 private boolean _is_continue = false;
\r
57 private INyARSquareContourDetector _square_detect;
\r
59 private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX);
\r
61 protected INyARTransMat _transmat;
\r
63 private double _marker_width;
\r
66 private NyARSquare _detected_square;
\r
70 * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。
\r
74 * @param i_marker_width
\r
75 * ARコードの物理サイズを、ミリメートルで指定します。
\r
76 * @throws NyARException
\r
78 public NyARSingleQrDetector(NyARParam i_param, double i_marker_width) throws NyARException
\r
80 final NyARIntSize scr_size=i_param.getScreenSize();
\r
82 this._square_detect = new NyARQrCodeDetector(i_param.getDistortionFactor(),scr_size);
\r
83 this._transmat = new NyARTransMat_ARToolKit(i_param);
\r
84 this._marker_width = i_marker_width;
\r
86 this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);
\r
87 //中間のグレースケール画像のバッファを作る
\r
88 this._gs_raster=new NyARGrayscaleRaster(scr_size.w,scr_size.h);
\r
90 private NyARBinRaster _bin_raster;
\r
91 private NyARGrayscaleRaster _gs_raster;
\r
93 private INyARRasterFilter_RgbToGs _rgb2gs_filter=new NyARRasterFilter_RgbAve();
\r
94 private INyARRasterFilter_GsToBin _gstobin_filter=new NyARRasterFilter_QrAreaAverage();
\r
97 * i_imageにマーカー検出処理を実行し、結果を記録します。
\r
100 * マーカーを検出するイメージを指定します。イメージサイズは、カメラパラメータ
\r
102 * @return マーカーが検出できたかを真偽値で返します。
\r
103 * @throws NyARException
\r
105 public boolean detectMarkerLite(INyARRgbRaster i_raster,int i_threshold) throws NyARException
\r
108 if(!this._bin_raster.getSize().isEqualSize(i_raster.getSize())){
\r
109 throw new NyARException();
\r
112 this._rgb2gs_filter.doFilter(i_raster, this._gs_raster);
\r
114 this._gstobin_filter.doFilter(this._gs_raster, this._bin_raster);
\r
116 this._detected_square = null;
\r
117 NyARSquareStack l_square_list = this._square_list;
\r
119 this._square_detect.detectMarkerCB(this._bin_raster, l_square_list);
\r
123 int number_of_square = l_square_list.getLength();
\r
125 if (number_of_square < 1) {
\r
128 this._detected_square=l_square_list.getItem(0);
\r
133 * 検出したマーカーの変換行列を計算して、o_resultへ値を返します。
\r
134 * 直前に実行したdetectMarkerLiteが成功していないと使えません。
\r
137 * 変換行列を受け取るオブジェクトを指定します。
\r
138 * @throws NyARException
\r
140 public void getTransmationMatrix(NyARTransMatResult o_result) throws NyARException
\r
142 // 一番一致したマーカーの位置とかその辺を計算
\r
143 if (this._is_continue) {
\r
144 this._transmat.transMatContinue(this._detected_square,this._detected_square.direction,this._marker_width, o_result);
\r
146 this._transmat.transMat(this._detected_square,this._detected_square.direction,this._marker_width, o_result);
\r
151 * getTransmationMatrixの計算モードを設定します。 初期値はTRUEです。
\r
153 * @param i_is_continue
\r
154 * TRUEなら、transMatCont互換の計算をします。 FALSEなら、transMat互換の計算をします。
\r
156 public void setContinueMode(boolean i_is_continue)
\r
158 this._is_continue = i_is_continue;
\r