X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=lib%2Fsrc%2Fjp%2Fnyatla%2Fnyartoolkit%2Fdetector%2FNyARDetectMarker.java;fp=lib%2Fsrc%2Fjp%2Fnyatla%2Fnyartoolkit%2Fdetector%2FNyARDetectMarker.java;h=0743ac082c6ad0f3137a3e59a3d7098c594f6fd1;hb=67cb5162524c344149f566c3a4b839275445046c;hp=0000000000000000000000000000000000000000;hpb=23b3fefd13f932c92ce6e9c73f6c5b28007243e2;p=nyartoolkit-and%2Fnyartoolkit-and.git
diff --git a/lib/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java b/lib/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java
new file mode 100644
index 0000000..0743ac0
--- /dev/null
+++ b/lib/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java
@@ -0,0 +1,324 @@
+/*
+ * PROJECT: NyARToolkit
+ * --------------------------------------------------------------------------------
+ * This work is based on the original ARToolKit developed by
+ * Hirokazu Kato
+ * Mark Billinghurst
+ * HITLab, University of Washington, Seattle
+ * http://www.hitl.washington.edu/artoolkit/
+ *
+ * The NyARToolkit is Java edition ARToolKit class library.
+ * Copyright (C)2008-2009 Ryo Iizuka
+ *
+ * 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://nyatla.jp/nyatoolkit/
+ * or
+ *
+ */
+package jp.nyatla.nyartoolkit.detector;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.core.match.*;
+import jp.nyatla.nyartoolkit.core.param.NyARParam;
+import jp.nyatla.nyartoolkit.core.pickup.*;
+import jp.nyatla.nyartoolkit.core.raster.*;
+import jp.nyatla.nyartoolkit.core.raster.rgb.*;
+import jp.nyatla.nyartoolkit.core.transmat.*;
+import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARCoord2Linear;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquare;
+import jp.nyatla.nyartoolkit.core.squaredetect.NyARSquareContourDetector_Rle;
+import jp.nyatla.nyartoolkit.core.types.*;
+import jp.nyatla.nyartoolkit.core.types.stack.NyARObjectStack;
+
+
+
+
+
+/**
+ * è¤æ°ã®ãã¼ã«ã¼ãæ¤åºããããããã«æãä¸è´ããARã³ã¼ãããã³ã³ã¹ãã©ã¯ã¿ã§ç»é²ããARã³ã¼ããã æ¢ãã¯ã©ã¹ã§ããæ大300åãèªèãã¾ãããã´ãã©ãã«ãèªèãããããã®ã§100åç¨åº¦ãéçã§ãã
+ *
+ */
+public class NyARDetectMarker
+{
+ private class RleDetector extends NyARSquareContourDetector_Rle
+ {
+ //å
¬éããããã£
+ public NyARDetectMarkerResultStack result_stack=new NyARDetectMarkerResultStack(NyARDetectMarker.AR_SQUARE_MAX);
+ //åç
§ã¤ã³ã¹ã¿ã³ã¹
+ public INyARRgbRaster _ref_raster;
+ //ææã¤ã³ã¹ã¿ã³ã¹
+ private INyARColorPatt _inst_patt;
+ private NyARMatchPattDeviationColorData _deviation_data;
+ private NyARMatchPatt_Color_WITHOUT_PCA[] _match_patt;
+ private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult();
+ private NyARCoord2Linear _coordline;
+
+ public RleDetector(INyARColorPatt i_inst_patt,NyARCode[] i_ref_code,int i_num_of_code,NyARParam i_param) throws NyARException
+ {
+ super(i_param.getScreenSize());
+ final int cw = i_ref_code[0].getWidth();
+ final int ch = i_ref_code[0].getHeight();
+ //NyARMatchPatt_Color_WITHOUT_PCA[]ã®ä½æ
+ this._match_patt=new NyARMatchPatt_Color_WITHOUT_PCA[i_num_of_code];
+ this._match_patt[0]=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[0]);
+ for (int i = 1; i < i_num_of_code; i++){
+ //解å度ãã§ãã¯
+ if (cw != i_ref_code[i].getWidth() || ch != i_ref_code[i].getHeight()) {
+ throw new NyARException();
+ }
+ this._match_patt[i]=new NyARMatchPatt_Color_WITHOUT_PCA(i_ref_code[i]);
+ }
+ this._inst_patt=i_inst_patt;
+ this._coordline=new NyARCoord2Linear(i_param.getScreenSize(),i_param.getDistortionFactor());
+ this._deviation_data=new NyARMatchPattDeviationColorData(cw,ch);
+ return;
+ }
+ private NyARIntPoint2d[] __ref_vertex=new NyARIntPoint2d[4];
+ /**
+ * ç©å½¢ãè¦ä»ãããã³ã«å¼ã³åºããã¾ãã
+ * çºè¦ããç©å½¢ã®ãã¿ã¼ã³ãæ¤æ»ãã¦ãæ¹ä½ãèæ
®ããé ç¹ãã¼ã¿ã確ä¿ãã¾ãã
+ */
+ protected void onSquareDetect(NyARIntCoordinates i_coord,int[] i_vertex_index) throws NyARException
+ {
+ NyARMatchPattResult mr=this.__detectMarkerLite_mr;
+ //輪é座æ¨ããé ç¹ãªã¹ãã«å¤æ
+ NyARIntPoint2d[] vertex=this.__ref_vertex;
+ vertex[0]=i_coord.items[i_vertex_index[0]];
+ vertex[1]=i_coord.items[i_vertex_index[1]];
+ vertex[2]=i_coord.items[i_vertex_index[2]];
+ vertex[3]=i_coord.items[i_vertex_index[3]];
+
+ //ç»åãåå¾
+ if (!this._inst_patt.pickFromRaster(this._ref_raster,vertex)){
+ return;
+ }
+ //åå¾ãã¿ã¼ã³ãã«ã©ã¼å·®åãã¼ã¿ã«å¤æãã¦è©ä¾¡ããã
+ this._deviation_data.setRaster(this._inst_patt);
+
+ //æãä¸è´ãããã¿ã¼ã³ãå²ãå½ã¦ãã
+ int square_index,direction;
+ double confidence;
+ this._match_patt[0].evaluate(this._deviation_data,mr);
+ square_index=0;
+ direction=mr.direction;
+ confidence=mr.confidence;
+ //2çªç®ä»¥é
+ for(int i=1;i mr.confidence) {
+ continue;
+ }
+ // ãã£ã¨ä¸è´ãããã¼ã«ã¼ããã£ãã½ã
+ square_index = i;
+ direction = mr.direction;
+ confidence = mr.confidence;
+ }
+ //æãä¸è´ãããã¼ã«æ
å ±ãããã®ç©å½¢ã®æ
å ±ã¨ãã¦è¨é²ããã
+ final NyARDetectMarkerResult result = this.result_stack.prePush();
+ result.arcode_id = square_index;
+ result.confidence = confidence;
+
+ final NyARSquare sq=result.square;
+ //directionãèæ
®ãã¦ãsquareãæ´æ°ããã
+ for(int i=0;i<4;i++){
+ int idx=(i+4 - direction) % 4;
+ this._coordline.coord2Line(i_vertex_index[idx],i_vertex_index[(idx+1)%4],i_coord,sq.line[i]);
+ }
+ for (int i = 0; i < 4; i++) {
+ //ç´ç·å士ã®äº¤ç¹è¨ç®
+ if(!sq.line[i].crossPos(sq.line[(i + 3) % 4],sq.sqvertex[i])){
+ throw new NyARException();//ããã®ã¨ã©ã¼å¾©å¸°ãããªãããã«ãããã¡ã«ããã°OK
+ }
+ }
+ }
+ public void init(INyARRgbRaster i_raster)
+ {
+ this._ref_raster=i_raster;
+ this.result_stack.clear();
+
+ }
+ }
+ private static final int AR_SQUARE_MAX = 300;
+ private boolean _is_continue = false;
+ private RleDetector _square_detect;
+ protected INyARTransMat _transmat;
+ private NyARRectOffset[] _offset;
+
+
+ /**
+ * è¤æ°ã®ãã¼ã«ã¼ãæ¤åºããæãä¸è´ãã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ã®æ°ãæå®ãã¾ãã
+ * @param i_input_raster_type
+ * å
¥åã©ã¹ã¿ã®ãã¯ã»ã«ã¿ã¤ããæå®ãã¾ãããã®å¤ã¯ãINyARBufferReaderã¤ã³ã¿ãã§ã¤ã¹ã®getBufferTypeã®æ»ãå¤ãæå®ãã¾ãã
+ * @throws NyARException
+ */
+ public NyARDetectMarker(NyARParam i_param,NyARCode[] i_code,double[] i_marker_width, int i_number_of_code,int i_input_raster_type) throws NyARException
+ {
+ initInstance(i_param,i_code,i_marker_width,i_number_of_code,i_input_raster_type);
+ return;
+ }
+ protected void initInstance(
+ NyARParam i_ref_param,
+ NyARCode[] i_ref_code,
+ double[] i_marker_width,
+ int i_number_of_code,
+ int i_input_raster_type) throws NyARException
+ {
+
+ final NyARIntSize scr_size=i_ref_param.getScreenSize();
+ // 解æãªãã¸ã§ã¯ããä½ã
+ final int cw = i_ref_code[0].getWidth();
+ final int ch = i_ref_code[0].getHeight();
+
+ this._transmat = new NyARTransMat(i_ref_param);
+ //NyARToolkitãããã¡ã¤ã«
+ this._square_detect =new RleDetector(new NyARColorPatt_Perspective_O2(cw, ch,4,25,i_input_raster_type),i_ref_code,i_number_of_code,i_ref_param);
+ this._tobin_filter=new NyARRasterFilter_ARToolkitThreshold(100,i_input_raster_type);
+
+ //å®ãµã¤ãºä¿å
+ this._offset = NyARRectOffset.createArray(i_number_of_code);
+ for(int i=0;i
+{
+ public NyARDetectMarkerResultStack(int i_length) throws NyARException
+ {
+ super();
+ this.initInstance(i_length,NyARDetectMarkerResult.class);
+ return;
+ }
+ protected NyARDetectMarkerResult createElement()
+ {
+ return new NyARDetectMarkerResult();
+ }
+}
\ No newline at end of file