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.raster.*;
\r
40 import jp.nyatla.nyartoolkit.core.squaredetect.INyARSquareDetector;
\r
41 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
\r
42 import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareStack;
\r
43 import jp.nyatla.nyartoolkit.core.transmat.*;
\r
44 import jp.nyatla.nyartoolkit.core.types.*;
\r
45 import jp.nyatla.nyartoolkit.core2.rasterfilter.rgb2gs.*;
\r
48 * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。
\r
51 public class NyARSingleQrDetector
\r
53 private static final int AR_SQUARE_MAX = 100;
\r
55 private boolean _is_continue = false;
\r
56 private INyARSquareDetector _square_detect;
\r
58 private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX);
\r
60 protected INyARTransMat _transmat;
\r
62 private double _marker_width;
\r
65 private NyARSquare _detected_square;
\r
69 * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。
\r
73 * @param i_marker_width
\r
74 * ARコードの物理サイズを、ミリメートルで指定します。
\r
75 * @throws NyARException
\r
77 public NyARSingleQrDetector(NyARParam i_param, double i_marker_width) throws NyARException
\r
79 final NyARIntSize scr_size=i_param.getScreenSize();
\r
81 this._square_detect = new NyARQrCodeDetector(i_param.getDistortionFactor(),scr_size);
\r
82 this._transmat = new NyARTransMat_ARToolKit(i_param);
\r
83 this._marker_width = i_marker_width;
\r
85 this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h);
\r
86 //中間のグレースケール画像のバッファを作る
\r
87 this._gs_raster=new NyARGrayscaleRaster(scr_size.w,scr_size.h);
\r
89 private NyARBinRaster _bin_raster;
\r
90 private NyARGrayscaleRaster _gs_raster;
\r
92 private INyARRasterFilter_RgbToGs _rgb2gs_filter=new NyARRasterFilter_RgbAve();
\r
93 private INyARRasterFilter_GsToBin _gstobin_filter=new NyARRasterFilter_QrAreaAverage();
\r
96 * i_imageにマーカー検出処理を実行し、結果を記録します。
\r
99 * マーカーを検出するイメージを指定します。イメージサイズは、カメラパラメータ
\r
101 * @return マーカーが検出できたかを真偽値で返します。
\r
102 * @throws NyARException
\r
104 public boolean detectMarkerLite(INyARRgbRaster i_raster,int i_threshold) throws NyARException
\r
107 if(!this._bin_raster.getSize().isEqualSize(i_raster.getSize())){
\r
108 throw new NyARException();
\r
111 this._rgb2gs_filter.doFilter(i_raster, this._gs_raster);
\r
113 this._gstobin_filter.doFilter(this._gs_raster, this._bin_raster);
\r
115 this._detected_square = null;
\r
116 NyARSquareStack l_square_list = this._square_list;
\r
118 this._square_detect.detectMarker(this._bin_raster, l_square_list);
\r
122 int number_of_square = l_square_list.getLength();
\r
124 if (number_of_square < 1) {
\r
127 this._detected_square=l_square_list.getItem(0);
\r
132 * 検出したマーカーの変換行列を計算して、o_resultへ値を返します。
\r
133 * 直前に実行したdetectMarkerLiteが成功していないと使えません。
\r
136 * 変換行列を受け取るオブジェクトを指定します。
\r
137 * @throws NyARException
\r
139 public void getTransmationMatrix(NyARTransMatResult o_result) throws NyARException
\r
141 // 一番一致したマーカーの位置とかその辺を計算
\r
142 if (this._is_continue) {
\r
143 this._transmat.transMatContinue(this._detected_square,this._detected_square.direction,this._marker_width, o_result);
\r
145 this._transmat.transMat(this._detected_square,this._detected_square.direction,this._marker_width, o_result);
\r
150 * getTransmationMatrixの計算モードを設定します。 初期値はTRUEです。
\r
152 * @param i_is_continue
\r
153 * TRUEなら、transMatCont互換の計算をします。 FALSEなら、transMat互換の計算をします。
\r
155 public void setContinueMode(boolean i_is_continue)
\r
157 this._is_continue = i_is_continue;
\r