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.squaredetect;
\r
33 import jp.nyatla.nyartoolkit.NyARException;
\r
34 import jp.nyatla.nyartoolkit.core.labeling.NyARLabelOverlapChecker;
\r
35 import jp.nyatla.nyartoolkit.core.labeling.rlelabeling.*;
\r
36 import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;
\r
37 import jp.nyatla.nyartoolkit.core.types.*;
\r
40 public class NyARSquareContourDetector_Rle extends NyARSquareContourDetector
\r
42 private static final int AR_AREA_MAX = 100000;// #define AR_AREA_MAX 100000
\r
43 private static final int AR_AREA_MIN = 70;// #define AR_AREA_MIN 70
\r
44 private final int _width;
\r
45 private final int _height;
\r
47 private final NyARLabeling_Rle _labeling;
\r
49 private final NyARLabelOverlapChecker<NyARRleLabelFragmentInfoStack.RleLabelFragmentInfo> _overlap_checker = new NyARLabelOverlapChecker<NyARRleLabelFragmentInfoStack.RleLabelFragmentInfo>(32,NyARRleLabelFragmentInfoStack.RleLabelFragmentInfo.class);
\r
50 private final NyARContourPickup _cpickup=new NyARContourPickup();
\r
51 private final NyARRleLabelFragmentInfoStack _stack;
\r
52 private final NyARCoord2SquareVertexIndexes _coord2vertex=new NyARCoord2SquareVertexIndexes();
\r
54 private final int _max_coord;
\r
55 private final int[] _xcoord;
\r
56 private final int[] _ycoord;
\r
58 * 最大i_squre_max個のマーカーを検出するクラスを作成する。
\r
62 public NyARSquareContourDetector_Rle(NyARIntSize i_size) throws NyARException
\r
64 this._width = i_size.w;
\r
65 this._height = i_size.h;
\r
66 //ラベリングのサイズを指定したいときはsetAreaRangeを使ってね。
\r
67 this._labeling = new NyARLabeling_Rle(this._width,this._height);
\r
68 this._labeling.setAreaRange(AR_AREA_MAX, AR_AREA_MIN);
\r
69 this._stack=new NyARRleLabelFragmentInfoStack(i_size.w*i_size.h*2048/(320*240)+32);//検出可能な最大ラベル数
\r
72 // 輪郭の最大長は画面に映りうる最大の長方形サイズ。
\r
73 int number_of_coord = (this._width + this._height) * 2;
\r
76 this._max_coord = number_of_coord;
\r
77 this._xcoord = new int[number_of_coord];
\r
78 this._ycoord = new int[number_of_coord];
\r
82 private final int[] __detectMarker_mkvertex = new int[4];
\r
84 public void detectMarkerCB(NyARBinRaster i_raster, IDetectMarkerCallback i_callback) throws NyARException
\r
86 final NyARRleLabelFragmentInfoStack flagment=this._stack;
\r
87 final NyARLabelOverlapChecker<NyARRleLabelFragmentInfoStack.RleLabelFragmentInfo> overlap = this._overlap_checker;
\r
90 final int label_num=this._labeling.labeling(i_raster, 0, i_raster.getHeight(), flagment);
\r
91 if (label_num < 1) {
\r
95 flagment.sortByArea();
\r
97 NyARRleLabelFragmentInfoStack.RleLabelFragmentInfo[] labels=flagment.getArray();
\r
99 final int xsize = this._width;
\r
100 final int ysize = this._height;
\r
101 int[] xcoord = this._xcoord;
\r
102 int[] ycoord = this._ycoord;
\r
103 final int coord_max = this._max_coord;
\r
104 final int[] mkvertex =this.__detectMarker_mkvertex;
\r
108 overlap.setMaxLabels(label_num);
\r
110 for (int i=0; i < label_num; i++) {
\r
111 final NyARRleLabelFragmentInfoStack.RleLabelFragmentInfo label_pt=labels[i];
\r
112 int label_area = label_pt.area;
\r
114 // クリップ領域が画面の枠に接していれば除外
\r
115 if (label_pt.clip_l == 0 || label_pt.clip_r == xsize-1){
\r
118 if (label_pt.clip_t == 0 || label_pt.clip_b == ysize-1){
\r
121 // 既に検出された矩形との重なりを確認
\r
122 if (!overlap.check(label_pt)) {
\r
128 int coord_num = _cpickup.getContour(i_raster,label_pt.entry_x,label_pt.clip_t, coord_max, xcoord, ycoord);
\r
129 if (coord_num == coord_max) {
\r
133 //輪郭線をチェックして、矩形かどうかを判定。矩形ならばmkvertexに取得
\r
134 if (!this._coord2vertex.getVertexIndexes(xcoord, ycoord,coord_num,label_area, mkvertex)) {
\r
138 //矩形を発見したことをコールバック関数で通知
\r
139 i_callback.onSquareDetect(this,xcoord,ycoord,coord_num,mkvertex);
\r
141 // 検出済の矩形の属したラベルを重なりチェックに追加する。
\r
142 overlap.push(label_pt);
\r
151 public NyARRleLabelFragmentInfoStack _getFragmentStack()
\r
153 return this._stack;
\r