/*
* PROJECT: FLARToolKit
* --------------------------------------------------------------------------------
* This work is based on the NyARToolKit developed by
* R.Iizuka (nyatla)
* http://nyatla.jp/nyatoolkit/
*
* The FLARToolKit is ActionScript 3.0 version ARToolkit class library.
* Copyright (C)2008 Saqoosha
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* For further information please contact.
* http://www.libspark.org/wiki/saqoosha/FLARToolKit
*
*
*/
package org.libspark.flartoolkit.detector
{
import flash.display.BitmapData;
import flash.geom.Point;
import jp.nyatla.nyartoolkit.as3.NyARException;
import jp.nyatla.nyartoolkit.as3.core.pickup.NyARColorPatt_Perspective_O2;
import jp.nyatla.nyartoolkit.as3.core.rasterfilter.rgb2bin.INyARRasterFilter_Rgb2Bin;
import jp.nyatla.nyartoolkit.as3.core.squaredetect.NyARSquare;
import jp.nyatla.nyartoolkit.as3.core.squaredetect.NyARSquareContourDetector;
import jp.nyatla.nyartoolkit.as3.core.transmat.INyARTransMat;
import jp.nyatla.nyartoolkit.as3.core.transmat.NyARRectOffset;
import jp.nyatla.nyartoolkit.as3.core.transmat.NyARTransMat;
import jp.nyatla.nyartoolkit.as3.core.types.NyARIntSize;
import org.libspark.flartoolkit.core.FLARCode;
import org.libspark.flartoolkit.core.labeling.fllabeling.FLARLabeling;
import org.libspark.flartoolkit.core.param.FLARParam;
import org.libspark.flartoolkit.core.raster.FLARBinRaster;
import org.libspark.flartoolkit.core.raster.rgb.FLARRgbRaster_BitmapData;
import org.libspark.flartoolkit.core.rasterfilter.rgb2bin.FLARRasterFilter_Threshold;
import org.libspark.flartoolkit.core.squaredetect.FLARSquareContourDetector;
import org.libspark.flartoolkit.core.transmat.FLARTransMatResult;
/**
* 複数のマーカーを検出し、それぞれに最も一致するARコードを、コンストラクタで登録したARコードから 探すクラスです。最大300個を認識しますが、ゴミラベルを認識したりするので100個程度が限界です。
*
*/
public class FLARMultiMarkerDetector
{
private var _detect_cb:MultiDetectSquareCB;
public static const AR_SQUARE_MAX:int = 300;
private var _is_continue:Boolean = false;
private var _square_detect:FLARSquareContourDetector;
protected var _transmat:INyARTransMat;
private var _offset:Vector.;
// import が消える現象回避用
private var _flarcode:FLARCode;
/**
* 複数のマーカーを検出し、最も一致するARCodeをi_codeから検索するオブジェクトを作ります。
*
* @param i_param
* カメラパラメータを指定します。
* @param i_code
* 検出するマーカーのARCode配列を指定します。
* 配列要素のインデックス番号が、そのままgetARCodeIndex関数で得られるARCodeインデックスになります。
* 例えば、要素[1]のARCodeに一致したマーカーである場合は、getARCodeIndexは1を返します。
* @param i_marker_width
* i_codeのマーカーサイズをミリメートルで指定した配列を指定します。 先頭からi_number_of_code個の要素には、有効な値を指定する必要があります。
* @param i_number_of_code
* i_codeに含まれる、ARCodeの数を指定します。
* @throws NyARException
*/
public function FLARMultiMarkerDetector(i_param:FLARParam, i_code:Vector., i_marker_width:Vector., i_number_of_code:int)
{
initInstance(i_param,i_code,i_marker_width,i_number_of_code);
return;
}
protected function initInstance(
i_ref_param:FLARParam,
i_ref_code:Vector.,
i_marker_width:Vector.,
i_number_of_code:int):void
{
var scr_size:NyARIntSize=i_ref_param.getScreenSize();
// @todo この部分にマーカーの幅や高さ、枠線の割合がすべて一致するかのチェックを入れる
// もしくは、FLARCodeの生成時に強制的に同一の数値を入力する事
// 解析オブジェクトを作る
var cw:int = i_ref_code[0].getWidth();
var ch:int = i_ref_code[0].getHeight();
// 枠線の割合(ARToolKit標準と同じなら、25 -> 1.0系と数値の扱いが異なるので注意!)
var markerWidthByDec:Number = (100 - i_ref_code[0].markerPercentWidth) / 2;
var markerHeightByDec:Number = (100 - i_ref_code[0].markerPercentHeight) / 2;
//評価パターンのホルダを作成
// NyARColorPatt_Perspective_O2のパラメータ
// 第1,2パラ…縦横の解像度(patデータ作ったときの分割数)
// 第3パラ…1ピクセルあたりの縦横サンプリング数。2なら2x2=4ポイントをサンプリングする。
// 1,2,4,任意の数値のいずれか。値が大きいほど一致率UP、フレームレート低下。
// 解像度16、サンプリング数4がデフォルト。解像度が大きい場合は、サンプリング数を下げることでフレームレートの低下を回避できる。
// 第4パラ…エッジ幅の割合(ARToolKit標準と同じなら、25)->1.0系と数値の扱いが異なるので注意!
var patt:NyARColorPatt_Perspective_O2 = new NyARColorPatt_Perspective_O2(cw, ch, 4, markerWidthByDec);
// 縦横のエッジの割合が異なる場合にも対応できます。
patt.setEdgeSizeByPercent(markerWidthByDec, markerHeightByDec, 4);
// trace('w:'+markerWidthByDec+'/h:'+markerHeightByDec);
//detectMarkerのコールバック関数
this._detect_cb=new MultiDetectSquareCB(patt,i_ref_code,i_number_of_code,i_ref_param);
this._transmat = new NyARTransMat(i_ref_param);
//NyARToolkitプロファイル
this._square_detect =new FLARSquareContourDetector(i_ref_param.getScreenSize());
this._tobin_filter=new FLARRasterFilter_Threshold(100);
//実サイズ保存
this._offset = NyARRectOffset.createArray(i_number_of_code);
for(var i:int=0;i