--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * 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
+ *\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
+ * \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
+ * 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
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.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
+/**\r
+ * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。\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
+ \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
+ //パターンを評価器にセット\r
+ if(!this.match_patt.setPatt(patt)){\r
+ //計算に失敗した。\r
+ throw new NyARException();\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
+ 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
+ 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