* HITLab, University of Washington, Seattle\r
* http://www.hitl.washington.edu/artoolkit/\r
*\r
- * The NyARToolkit is Java version ARToolkit class library.\r
- * Copyright (C)2008 R.Iizuka\r
+ * The NyARToolkit is Java edition ARToolKit class library.\r
+ * Copyright (C)2008-2009 Ryo Iizuka\r
*\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
* \r
* This program is distributed in the hope that it will be useful,\r
* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
* GNU General Public License for more details.\r
- * \r
+ *\r
* You should have received a copy of the GNU General Public License\r
- * along with this framework; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
* \r
* For further information please contact.\r
* http://nyatla.jp/nyatoolkit/\r
- * <airmail(at)ebony.plala.or.jp>\r
+ * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
* \r
*/\r
package jp.nyatla.nyartoolkit.detector;\r
\r
import jp.nyatla.nyartoolkit.NyARException;\r
import jp.nyatla.nyartoolkit.core.*;\r
-import jp.nyatla.nyartoolkit.core.match.NyARMatchPatt_Color_WITHOUT_PCA;\r
-import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
+import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt;\r
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
+\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold;\r
+import jp.nyatla.nyartoolkit.core.squaredetect.*;\r
+import jp.nyatla.nyartoolkit.core.pickup.*;\r
+import jp.nyatla.nyartoolkit.core.transmat.*;\r
/**\r
* 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。\r
- *\r
+ * \r
*/\r
-public class NyARSingleDetectMarker{\r
- private static final int AR_SQUARE_MAX=100;\r
- private boolean is_continue=false;\r
- private NyARMatchPatt_Color_WITHOUT_PCA match_patt;\r
- private NyARDetectSquare square;\r
- private final NyARSquareList square_list=new NyARSquareList(AR_SQUARE_MAX);\r
- private NyARCode code;\r
- protected NyARTransMat transmat;\r
- private double marker_width;\r
- //検出結果の保存用\r
- private int detected_direction;\r
- private double detected_confidence;\r
- private NyARSquare detected_square;\r
- private NyARColorPatt patt;\r
- /**\r
- * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。\r
- * @param i_param\r
- * カメラパラメータを指定します。\r
- * @param i_code\r
- * 検出するARCodeを指定します。\r
- * @param i_marker_width\r
- * ARコードの物理サイズを、ミリメートルで指定します。\r
- * @throws NyARException\r
- */\r
- public NyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width) throws NyARException\r
- {\r
- //解析オブジェクトを作る\r
- this.square=new NyARDetectSquare(i_param);\r
- this.transmat=new NyARTransMat_O2(i_param);\r
- //比較コードを保存\r
- this.code=i_code;\r
- this.marker_width=i_marker_width;\r
- //評価パターンのホルダを作る\r
- this.patt=new NyARColorPatt_O3(code.getWidth(),code.getHeight());\r
- //評価器を作る。\r
- this.match_patt=new NyARMatchPatt_Color_WITHOUT_PCA(); \r
- }\r
- /**\r
- * i_imageにマーカー検出処理を実行し、結果を記録します。\r
- * @param i_image\r
- * マーカーを検出するイメージを指定します。\r
- * @param i_thresh\r
- * 検出閾値を指定します。0~255の範囲で指定してください。\r
- * 通常は100~130くらいを指定します。\r
- * @return\r
- * マーカーが検出できたかを真偽値で返します。\r
- * @throws NyARException\r
- */\r
- public boolean detectMarkerLite(NyARRaster i_image,int i_thresh) throws NyARException\r
- {\r
- detected_square=null;\r
- NyARSquareList l_square_list=this.square_list;\r
- //スクエアコードを探す\r
- square.detectSquare(i_image, i_thresh,l_square_list);\r
+public class NyARSingleDetectMarker extends NyARCustomSingleDetectMarker\r
+{\r
+ public final static int PF_ARTOOLKIT_COMPATIBLE=1;\r
+ public final static int PF_NYARTOOLKIT=2;\r
+ public final static int PF_NYARTOOLKIT_ARTOOLKIT_FITTING=100;\r
+ public final static int PF_TEST2=201;\r
\r
- int number_of_square=l_square_list.getSquareNum();\r
- //コードは見つかった?\r
- if(number_of_square<1){\r
- return false;\r
- }\r
-\r
- //評価基準になるパターンをイメージから切り出す\r
- if(!patt.pickFromRaster(i_image,l_square_list.getSquare(0))){\r
- //パターンの切り出しに失敗\r
- return false;\r
+ /**\r
+ * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。\r
+ * \r
+ * @param i_param\r
+ * カメラパラメータを指定します。\r
+ * @param i_code\r
+ * 検出するARCodeを指定します。\r
+ * @param i_marker_width\r
+ * ARコードの物理サイズを、ミリメートルで指定します。\r
+ * @param i_input_raster_type\r
+ * 入力ラスタのピクセルタイプを指定します。この値は、INyARBufferReaderインタフェイスのgetBufferTypeの戻り値を指定します。\r
+ * @throws NyARException\r
+ */\r
+ public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_input_raster_type,int i_profile_id) throws NyARException\r
+ {\r
+ super();\r
+ initialize(i_param,i_code,i_marker_width,i_input_raster_type,i_profile_id);\r
+ return;\r
}\r
- //パターンを評価器にセット\r
- if(!this.match_patt.setPatt(patt)){\r
- //計算に失敗した。\r
- throw new NyARException();\r
+ public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,int i_input_raster_type) throws NyARException\r
+ {\r
+ super();\r
+ initialize(i_param,i_code,i_marker_width,i_input_raster_type,PF_NYARTOOLKIT);\r
+ return;\r
}\r
- //コードと比較する\r
- match_patt.evaluate(code);\r
- int square_index=0;\r
- int direction=match_patt.getDirection();\r
- double confidence=match_patt.getConfidence();\r
- for(int i=1;i<number_of_square;i++){\r
- //次のパターンを取得\r
- patt.pickFromRaster(i_image,l_square_list.getSquare(i));\r
- //評価器にセットする。\r
- match_patt.setPatt(patt);\r
- //コードと比較する\r
- match_patt.evaluate(code);\r
- double c2=match_patt.getConfidence();\r
- if(confidence>c2){\r
- continue;\r
- }\r
- //もっと一致するマーカーがあったぽい\r
- square_index=i;\r
- direction=match_patt.getDirection();\r
- confidence=c2;\r
+ /**\r
+ * コンストラクタから呼び出す関数です。\r
+ * @param i_ref_param\r
+ * @param i_ref_code\r
+ * @param i_marker_width\r
+ * @param i_input_raster_type\r
+ * @param i_profile_id\r
+ * @throws NyARException\r
+ */\r
+ private void initialize(\r
+ NyARParam i_ref_param,\r
+ NyARCode i_ref_code,\r
+ double i_marker_width,\r
+ int i_input_raster_type,\r
+ int i_profile_id) throws NyARException\r
+ {\r
+ final NyARRasterFilter_ARToolkitThreshold th=new NyARRasterFilter_ARToolkitThreshold(100,i_input_raster_type);\r
+ INyARColorPatt patt_inst;\r
+ NyARSquareContourDetector sqdetect_inst;\r
+ INyARTransMat transmat_inst;\r
+\r
+ switch(i_profile_id){\r
+ case PF_ARTOOLKIT_COMPATIBLE:\r
+ patt_inst=new NyARColorPatt_O3(i_ref_code.getWidth(), i_ref_code.getHeight());\r
+ sqdetect_inst=new NyARSquareContourDetector_ARToolKit(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
+ transmat_inst=new NyARTransMat_ARToolKit(i_ref_param);\r
+ break;\r
+ case PF_NYARTOOLKIT_ARTOOLKIT_FITTING:\r
+ patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);\r
+ sqdetect_inst=new NyARSquareContourDetector_Rle(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
+ transmat_inst=new NyARTransMat_ARToolKit(i_ref_param);\r
+ break;\r
+ case PF_NYARTOOLKIT://default\r
+ patt_inst=new NyARColorPatt_Perspective_O2(i_ref_code.getWidth(), i_ref_code.getHeight(),4,25);\r
+ sqdetect_inst=new NyARSquareContourDetector_Rle(i_ref_param.getDistortionFactor(),i_ref_param.getScreenSize());\r
+ transmat_inst=new NyARTransMat(i_ref_param);\r
+ break;\r
+ default:\r
+ throw new NyARException();\r
+ }\r
+ super.initInstance(patt_inst,sqdetect_inst,transmat_inst,th,i_ref_param,i_ref_code,i_marker_width);\r
+ \r
}\r
- //マーカー情報を保存\r
- detected_square=l_square_list.getSquare(square_index);\r
- detected_direction=direction;\r
- detected_confidence=confidence;\r
- return true;\r
- }\r
- /**\r
- * 検出したマーカーの変換行列を計算して、o_resultへ値を返します。\r
- * 直前に実行したdetectMarkerLiteが成功していないと使えません。\r
- * @param o_result\r
- * 変換行列を受け取るオブジェクトを指定します。\r
- * @throws NyARException\r
- */ \r
- public void getTransmationMatrix(NyARTransMatResult o_result) throws NyARException\r
- {\r
- //一番一致したマーカーの位置とかその辺を計算\r
- if(is_continue){\r
- transmat.transMatContinue(detected_square,detected_direction,marker_width,o_result);\r
- }else{\r
- transmat.transMat(detected_square,detected_direction,marker_width,o_result);\r
+\r
+ /**\r
+ * i_imageにマーカー検出処理を実行し、結果を記録します。\r
+ * \r
+ * @param i_raster\r
+ * マーカーを検出するイメージを指定します。イメージサイズは、コンストラクタで指定i_paramの\r
+ * スクリーンサイズと一致し、かつi_input_raster_typeに指定した形式でなければいけません。\r
+ * @return マーカーが検出できたかを真偽値で返します。\r
+ * @throws NyARException\r
+ */\r
+ public boolean detectMarkerLite(INyARRgbRaster i_raster,int i_threshold) throws NyARException\r
+ {\r
+ ((NyARRasterFilter_ARToolkitThreshold)this._tobin_filter).setThreshold(i_threshold);\r
+ return super.detectMarkerLite(i_raster);\r
}\r
- return;\r
- } \r
- /**\r
- * 検出したマーカーの一致度を返します。\r
- * @return\r
- * マーカーの一致度を返します。0~1までの値をとります。\r
- * 一致度が低い場合には、誤認識の可能性が高くなります。\r
- * @throws NyARException\r
- */\r
- public double getConfidence()\r
- {\r
- return detected_confidence;\r
- }\r
- /**\r
- * 検出したマーカーの方位を返します。\r
- * @return\r
- * 0,1,2,3の何れかを返します。\r
- */\r
- public int getDirection()\r
- {\r
- return detected_direction;\r
- }\r
- /**\r
- * getTransmationMatrixの計算モードを設定します。\r
- * 初期値はTRUEです。\r
- * @param i_is_continue\r
- * TRUEなら、transMatCont互換の計算をします。\r
- * FALSEなら、transMat互換の計算をします。\r
- */\r
- public void setContinueMode(boolean i_is_continue)\r
- {\r
- this.is_continue=i_is_continue;\r
- }\r
}\r
-\r
- \r
-\r
- \r
- \r
- \r
- \r
- \r
- \r
-\r
- \r
-\r
-\r
- \r
-\r