From 4c0ec05896755a96b1edfa52372aa0a43ed4b3d0 Mon Sep 17 00:00:00 2001 From: nyatla Date: Tue, 24 Mar 2009 08:48:47 +0000 Subject: [PATCH] =?utf8?q?[=E6=9B=B4=E6=96=B0]NyARToolkit=20for=20Java=201?= =?utf8?q?.NyARCode,NyARPatt=E3=81=AE=E3=83=87=E3=83=BC=E3=82=BF=E3=83=95?= =?utf8?q?=E3=82=A9=E3=83=BC=E3=83=9E=E3=83=83=E3=83=88=E6=A8=99=E6=BA=96?= =?utf8?q?=E5=8C=96=202.=E3=83=91=E3=82=BF=E3=83=BC=E3=83=B3=E3=83=9E?= =?utf8?q?=E3=83=83=E3=83=81=E5=87=A6=E7=90=86=E3=81=AE=E6=9C=80=E9=81=A9?= =?utf8?q?=E5=8C=96=203.NyARPatt=E3=81=AE=E6=9C=80=E9=81=A9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.sourceforge.jp/svnroot/nyartoolkit/NyARToolkit@224 7cac0a50-4618-4814-88d0-24b83990f816 --- .../nyartoolkit/jogl/sample/JavaSimpleLite.java | 4 +- .../sandbox/qrcode/NyARQrCodeDetector.java | 22 +- .../quadx2/NyARSingleDetectMarker_Quad.java | 57 ++-- .../sandbox/x2/NyARFixedFloatRotMatrix.java | 28 +- .../x2/NyARFixedFloatRotTransOptimize_O2.java | 4 +- .../sandbox/x2/NyARSingleDetectMarker_X2.java | 53 ++-- .../nyartoolkit/sandbox/x2/NyARTransMat_X2.java | 5 + .../nyartoolkit/sandbox/x2/RawFileTest_X2.java | 2 + .../nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java | 25 +- trunk/src/jp/nyatla/nyartoolkit/core/NyARCode.java | 249 ++++++++-------- .../nyartoolkit/core/match/INyARMatchPatt.java | 14 +- .../NyARMatchPattDeviationBlackWhiteData.java | 100 +++++++ .../match/NyARMatchPattDeviationColorData.java | 157 ++++++++++ .../core/match/NyARMatchPattResult.java | 38 +++ .../core/match/NyARMatchPatt_BlackWhite.java | 120 +++----- .../match/NyARMatchPatt_Color_WITHOUT_PCA.java | 181 ++++------- .../core/match/NyARMatchPatt_Color_WITH_PCA.java | 135 +++------ .../nyartoolkit/core/pickup/INyARColorPatt.java | 27 +- .../nyartoolkit/core/pickup/NyARColorPatt_O1.java | 229 +++++--------- .../nyartoolkit/core/pickup/NyARColorPatt_O3.java | 306 +++++++------------ .../nyartoolkit/core/raster/NyARBinRaster.java | 2 +- .../nyatla/nyartoolkit/core/raster/NyARRaster.java | 54 ++++ .../core/raster/rgb/NyARRgbRaster_BGRA.java | 9 +- .../core/raster/rgb/NyARRgbRaster_BasicClass.java | 20 +- .../core/raster/rgb/NyARRgbRaster_Blank.java | 2 +- .../core/rasterreader/INyARRgbPixelReader.java | 9 +- .../core/rasterreader/NyARBufferReader.java | 8 +- .../rasterreader/NyARRgbPixelReader_RGB24.java | 12 +- .../detector/NyARCustomSingleDetectMarker.java | 67 +++-- .../nyartoolkit/detector/NyARDetectMarker.java | 77 +++-- .../processor/SingleARMarkerProcesser.java | 330 +++++++++++++++++++++ .../jp/nyatla/nyartoolkit/sample/RawFileTest.java | 2 +- 32 files changed, 1348 insertions(+), 1000 deletions(-) create mode 100644 trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationBlackWhiteData.java create mode 100644 trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationColorData.java create mode 100644 trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattResult.java create mode 100644 trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java create mode 100644 trunk/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java diff --git a/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java b/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java index 022a7b3..9ae8f80 100644 --- a/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java +++ b/trunk/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java @@ -136,6 +136,8 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener public void init(GLAutoDrawable drawable) { this._gl = drawable.getGL(); + this._gl.glEnable(GL.GL_DEPTH_TEST); + this._gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //NyARToolkitの準備 try { @@ -149,11 +151,11 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener //NyARToolkitの準備 this._ar_param = new NyARParam(); NyARCode ar_code = new NyARCode(16, 16); + ar_code.loadARPattFromFile(CARCODE_FILE); this._ar_param.loadARParamFromFile(PARAM_FILE); this._ar_param.changeScreenSize(SCREEN_X, SCREEN_Y); this._nya = new NyARSingleDetectMarker(this._ar_param, ar_code, 80.0); this._nya.setContinueMode(false);//ここをtrueにすると、transMatContinueモード(History計算)になります。 - ar_code.loadARPattFromFile(CARCODE_FILE); //NyARToolkit用の支援クラス _glnya = new NyARGLUtil(_gl); //GL対応のRGBラスタオブジェクト diff --git a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeDetector.java b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeDetector.java index 0433686..21803c9 100644 --- a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeDetector.java +++ b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARQrCodeDetector.java @@ -132,7 +132,7 @@ public class NyARQrCodeDetector implements INyARSquareDetector final int[] ycoord = this._ycoord; final int coord_max = this._max_coord; final int[] mkvertex = this.__detectMarker_mkvertex; - final int[][] buf = (int[][]) limage.getBufferReader().getBuffer(); + final int[] buf = (int[]) limage.getBufferReader().getBuffer(); final int[] indextable = limage.getIndexArray(); int coord_num; int label_area; @@ -393,12 +393,12 @@ public class NyARQrCodeDetector implements INyARSquareDetector * @param i_label * @return */ - private boolean hasQrEdgeFeature(int buf[][], int[] index_table, NyARLabelingLabel i_label) + private boolean hasQrEdgeFeature(int[] buf, int[] index_table, NyARLabelingLabel i_label) { int tx, bx; int w; int i_label_id = i_label.id; - int[] limage_j; + int limage_j_ptr; final int clip_l = i_label.clip_l; final int clip_b = i_label.clip_b; final int clip_r = i_label.clip_r; @@ -406,18 +406,18 @@ public class NyARQrCodeDetector implements INyARSquareDetector tx = bx = 0; // 上接点(→) - limage_j = buf[clip_t]; + limage_j_ptr = clip_t*this._width; for (int i = clip_l; i <= clip_r; i++) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) { - w = limage_j[i]; + w = buf[limage_j_ptr+i]; if (w > 0 && index_table[w - 1] == i_label_id) { tx = i; break; } } // 下接点(←) - limage_j = buf[clip_b]; + limage_j_ptr = clip_b*this._width; for (int i = clip_r; i >= clip_l; i--) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) { - w = limage_j[i]; + w = buf[limage_j_ptr+i]; if (w > 0 && index_table[w - 1] == i_label_id) { bx = i; break; @@ -446,7 +446,7 @@ public class NyARQrCodeDetector implements INyARSquareDetector * @param i_py2 * @return */ - private boolean checkDiagonalLine(int[][] buf, int i_px1, int i_py1, int i_px2, int i_py2) + private boolean checkDiagonalLine(int[] buf, int i_px1, int i_py1, int i_px2, int i_py2) { int sub_y = i_py2 - i_py1; int sub_x = i_px2 - i_px1; @@ -455,7 +455,7 @@ public class NyARQrCodeDetector implements INyARSquareDetector for (; i < sub_y; i++) { int yp = i_py1 + i; int xp = i_px1 + i * sub_x / sub_y; - if (buf[yp][xp] == 0 && buf[yp][xp-1] == 0 && buf[yp][xp+1] == 0) { + if (buf[yp*this._width+xp] == 0 && buf[yp*this._width+(xp-1)] == 0 && buf[yp*this._width+(xp+1)] == 0) { break; } @@ -467,7 +467,7 @@ public class NyARQrCodeDetector implements INyARSquareDetector for (; i < sub_y; i++) { int yp = i_py1 + i; int xp = i_px1 + i * sub_x / sub_y; - if (buf[yp][xp] != 0 && buf[yp][xp-1] != 0 && buf[yp][xp+1] != 0) { + if (buf[yp*this._width+xp] != 0 && buf[yp*this._width+(xp-1)] != 0 && buf[yp*this._width+(xp+1)] != 0) { break; } @@ -479,7 +479,7 @@ public class NyARQrCodeDetector implements INyARSquareDetector for (; i < sub_y; i++) { int yp = i_py1 + i; int xp = i_px1 + i * sub_x / sub_y; - if (buf[yp][xp] == 0 && buf[yp][xp-1] == 0 && buf[yp][xp+1] == 0) { + if (buf[yp*this._width+xp] == 0 && buf[yp*this._width+(xp-1)] == 0 && buf[yp*this._width+(xp+1)] == 0) { break; } diff --git a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSingleDetectMarker_Quad.java b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSingleDetectMarker_Quad.java index aba2104..13baa54 100644 --- a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSingleDetectMarker_Quad.java +++ b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARSingleDetectMarker_Quad.java @@ -58,8 +58,6 @@ public class NyARSingleDetectMarker_Quad private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX); - private NyARCode _code; - protected INyARTransMat _transmat; private double _marker_width; @@ -91,14 +89,16 @@ public class NyARSingleDetectMarker_Quad this._square_detect = new NyARSquareDetector_Quad(i_param.getDistortionFactor(),scr_size); this._transmat = new NyARTransMat_X2(i_param); // 比較コードを保存 - this._code = i_code; this._marker_width = i_marker_width; // 評価パターンのホルダを作る - this._patt = new NyARColorPatt_O3(_code.getWidth(), _code.getHeight()); - // 評価器を作る。 - this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(); + this._patt = new NyARColorPatt_O3(i_code.getWidth(), i_code.getHeight()); + // i_codeに対応する評価器を作る。 + this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(i_code); //2値画像バッファを作る this._bin_raster=new NyARBinRaster(scr_size.w/2,scr_size.h/2); + //差分データインスタンスの作成 + this._deviation_data=new NyARMatchPattDeviationColorData(i_code.getWidth(), i_code.getHeight()); + return; } @@ -106,6 +106,9 @@ public class NyARSingleDetectMarker_Quad // private NyARRasterFilter_ARToolkitThreshold _tobin_filter=new NyARRasterFilter_ARToolkitThreshold(100); private NyARRasterFilter_ARTTh_Quad _tobin_filter=new NyARRasterFilter_ARTTh_Quad(100); + private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult(); + private NyARMatchPattDeviationColorData _deviation_data; + /** * i_imageにマーカー検出処理を実行し、結果を記録します。 * @@ -139,42 +142,36 @@ public class NyARSingleDetectMarker_Quad return false; } - // 評価基準になるパターンをイメージから切り出す - if (!this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(0))) { - // パターンの切り出しに失敗 - return false; - } - // パターンを評価器にセット - if (!this._match_patt.setPatt(this._patt)) { - // 計算に失敗した。 - throw new NyARException(); - } - // コードと比較する - this._match_patt.evaluate(this._code); + boolean result=false; + NyARMatchPattResult mr=this.__detectMarkerLite_mr; int square_index = 0; - int direction = this._match_patt.getDirection(); - double confidence = this._match_patt.getConfidence(); - for (int i = 1; i < number_of_square; i++) { - // 次のパターンを取得 - this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(i)); - // 評価器にセットする。 - this._match_patt.setPatt(this._patt); - // コードと比較する - this._match_patt.evaluate(this._code); - double c2 = this._match_patt.getConfidence(); + int direction = NyARSquare.DIRECTION_UNKNOWN; + double confidence = 0; + for(int i=0;i c2) { continue; } // もっと一致するマーカーがあったぽい square_index = i; - direction = this._match_patt.getDirection(); + direction = mr.direction; confidence = c2; + result=true; } + // マーカー情報を保存 this._detected_square = (NyARSquare)l_square_list.getItem(square_index); this._detected_direction = direction; this._detected_confidence = confidence; - return true; + return false; } /** diff --git a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotMatrix.java b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotMatrix.java index 013e4d0..7a61989 100644 --- a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotMatrix.java +++ b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotMatrix.java @@ -41,7 +41,7 @@ import jp.nyatla.nyartoolkit.core2.types.matrix.NyARFixedFloat24Matrix33; /** - * 回転行列計算用の、3x3行列 + * NyARRotMatrix_NyARToolKitのFixedFloat版です。 * */ public class NyARFixedFloatRotMatrix extends NyARFixedFloat24Matrix33 @@ -60,8 +60,8 @@ public class NyARFixedFloatRotMatrix extends NyARFixedFloat24Matrix33 } final private NyARFixedFloatRotVector __initRot_vec1; - final private NyARFixedFloatRotVector __initRot_vec2; + final private NyARFixedFloat16Point3d _angle=new NyARFixedFloat16Point3d(); public final void initRotByPrevResult(NyARTransMatResult i_prev_result) { @@ -115,16 +115,22 @@ public class NyARFixedFloatRotMatrix extends NyARFixedFloat24Matrix33 this.m02 = (w02<<24) / w; this.m12 = (w12<<24) / w; this.m22 = (w22<<24) / w; + //Matrixからangleをロード + this.updateAngleFromMatrix(); + return; } - + public NyARFixedFloat16Point3d refAngle() + { + return this._angle; + } /** * int arGetAngle( double rot[3][3], double *wa, double *wb, double *wc ) Optimize:2008.04.20:STEP[481→433] 3x3変換行列から、回転角を復元して返します。 * * @param o_angle * @return */ - public final void getAngle(final NyARFixedFloat16Point3d o_angle) + private final void updateAngleFromMatrix() { int a, b, c; long sina, cosa, sinb, cosb, sinc, cosc; @@ -162,7 +168,7 @@ public class NyARFixedFloatRotMatrix extends NyARFixedFloat24Matrix33 sina = -NyMath.FIXEDFLOAT24_1; cosa = 0; } - a = (int)NyMath.acosFixedFloat16((int)cosa); + a = NyMath.acosFixedFloat16((int)cosa); if (sina < 0) { a = -a; } @@ -224,14 +230,14 @@ public class NyARFixedFloatRotMatrix extends NyARFixedFloat24Matrix33 sinc = -NyMath.FIXEDFLOAT24_1; cosc = 0; } - c = (int)NyMath.acosFixedFloat16((int)cosc); + c = NyMath.acosFixedFloat16((int)cosc); if (sinc < 0) { c = -c; } } - o_angle.x = (long)a;// wa.value=a;//*wa = a; - o_angle.y = (long)b;// wb.value=b;//*wb = b; - o_angle.z = (long)c;// wc.value=c;//*wc = c; + this._angle.x = (long)a;// wa.value=a;//*wa = a; + this._angle.y = (long)b;// wb.value=b;//*wb = b; + this._angle.z = (long)c;// wc.value=c;//*wc = c; return; } public final void setAngle(int i_x, int i_y, int i_z) @@ -259,6 +265,10 @@ public class NyARFixedFloatRotMatrix extends NyARFixedFloat24Matrix33 this.m20 =(-Sb * Cac)>>24; this.m21 =(-Sb * Sac)>>24; this.m22 =Cb; + //angleを逆計算せずに直接代入 + this._angle.x=i_x; + this._angle.y=i_y; + this._angle.z=i_z; return; } /** diff --git a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java index e85dabc..5b1666d 100644 --- a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java +++ b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARFixedFloatRotTransOptimize_O2.java @@ -77,7 +77,6 @@ public class NyARFixedFloatRotTransOptimize_O2 } private final long[][] __modifyMatrix_double1D = new long[8][3]; - private final NyARFixedFloat16Point3d __modifyMatrix_angle = new NyARFixedFloat16Point3d(); private final long INITIAL_FACTOR=(long)(0x10000*5.0 * Math.PI / 180.0); /** * arGetRot計算を階層化したModifyMatrix 896 @@ -148,7 +147,6 @@ public class NyARFixedFloatRotTransOptimize_O2 long SACASC, SACACBSC, SACACBCC, SACACC; final long[][] double1D = this.__modifyMatrix_double1D; - final NyARFixedFloat16Point3d angle = this.__modifyMatrix_angle; final long[] a_factor = double1D[1]; final long[] sinb = double1D[2]; final long[] cosb = double1D[3]; @@ -159,7 +157,7 @@ public class NyARFixedFloatRotTransOptimize_O2 long w, w2; long wsin, wcos; - io_rot.getAngle(angle);// arGetAngle( rot, &a, &b, &c ); + final NyARFixedFloat16Point3d angle=io_rot.refAngle();// arGetAngle( rot, &a, &b, &c ); a2 =angle.x; b2 =angle.y; c2 =angle.z; diff --git a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSingleDetectMarker_X2.java b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSingleDetectMarker_X2.java index 93b3a64..e5b2875 100644 --- a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSingleDetectMarker_X2.java +++ b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARSingleDetectMarker_X2.java @@ -57,8 +57,6 @@ public class NyARSingleDetectMarker_X2 private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX); - private NyARCode _code; - protected INyARTransMat _transmat; private double _marker_width; @@ -91,20 +89,24 @@ public class NyARSingleDetectMarker_X2 // 解析オブジェクトを作る this._square_detect = new NyARSquareDetector_X2(dist_map,scr_size); this._transmat = new NyARTransMat_X2(i_param); - // 比較コードを保存 - this._code = i_code; this._marker_width = i_marker_width; + int cw=i_code.getWidth(); + int ch=i_code.getHeight(); // 評価パターンのホルダを作る - this._patt = new NyARColorPatt_O3(_code.getWidth(), _code.getHeight()); + this._patt = new NyARColorPatt_O3(cw,ch); // 評価器を作る。 - this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(); + this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(i_code); //2値画像バッファを作る this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h); + //差分データインスタンスの作成 + this._deviation_data=new NyARMatchPattDeviationColorData(cw,ch); return; } private NyARBinRaster _bin_raster; private NyARRasterFilter_ARToolkitThreshold _tobin_filter=new NyARRasterFilter_ARToolkitThreshold(100); + private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult(); + private NyARMatchPattDeviationColorData _deviation_data; /** @@ -139,38 +141,29 @@ public class NyARSingleDetectMarker_X2 if (number_of_square < 1) { return false; } - - // 評価基準になるパターンをイメージから切り出す - if (!this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(0))) { - // パターンの切り出しに失敗 - return false; - } - // パターンを評価器にセット - if (!this._match_patt.setPatt(this._patt)) { - // 計算に失敗した。 - throw new NyARException(); - } - // コードと比較する - this._match_patt.evaluate(this._code); + NyARMatchPattResult mr=this.__detectMarkerLite_mr; int square_index = 0; - int direction = this._match_patt.getDirection(); - double confidence = this._match_patt.getConfidence(); - for (int i = 1; i < number_of_square; i++) { - // 次のパターンを取得 - this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(i)); - // 評価器にセットする。 - this._match_patt.setPatt(this._patt); - // コードと比較する - this._match_patt.evaluate(this._code); - double c2 = this._match_patt.getConfidence(); + int direction = NyARSquare.DIRECTION_UNKNOWN; + double confidence = 0; + for(int i=0;i c2) { continue; } // もっと一致するマーカーがあったぽい square_index = i; - direction = this._match_patt.getDirection(); + direction = mr.direction; confidence = c2; } + // マーカー情報を保存 this._detected_square = (NyARSquare)l_square_list.getItem(square_index); this._detected_direction = direction; diff --git a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java index ed081b7..e87d2cb 100644 --- a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java +++ b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARTransMat_X2.java @@ -215,7 +215,12 @@ public class NyARTransMat_X2 implements INyARTransMat o_result.m21 =(double)i_rot.m21/NyMath.FIXEDFLOAT24_1; o_result.m22 =(double)i_rot.m22/NyMath.FIXEDFLOAT24_1; o_result.m23 =(double)(((i_rot.m20 * i_off.x + i_rot.m21 * i_off.y + i_rot.m22 * i_off.z)>>24) + i_trans.z)/NyMath.FIXEDFLOAT16_1; + + final NyARFixedFloat16Point3d angle=i_rot.refAngle(); + o_result.angle.x=(double)angle.x/NyMath.FIXEDFLOAT16_1; + o_result.angle.y=(double)angle.y/NyMath.FIXEDFLOAT16_1; + o_result.angle.z=(double)angle.z/NyMath.FIXEDFLOAT16_1; o_result.has_value = true; return; } diff --git a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/RawFileTest_X2.java b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/RawFileTest_X2.java index 9132c88..09e4e72 100644 --- a/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/RawFileTest_X2.java +++ b/trunk/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/RawFileTest_X2.java @@ -38,6 +38,7 @@ import jp.nyatla.nyartoolkit.core.*; import jp.nyatla.nyartoolkit.core.param.NyARParam; import jp.nyatla.nyartoolkit.core.raster.rgb.*; import jp.nyatla.nyartoolkit.core.transmat.*; +import jp.nyatla.nyartoolkit.sandbox.quadx2.*; /** @@ -79,6 +80,7 @@ public class RawFileTest_X2 // Blank_Raster ra=new Blank_Raster(320, 240); // 1パターンのみを追跡するクラスを作成 +// NyARSingleDetectMarker_Quad ar = new NyARSingleDetectMarker_Quad(ap, code, 80.0); NyARSingleDetectMarker_X2 ar = new NyARSingleDetectMarker_X2(ap, code, 80.0); NyARTransMatResult result_mat = new NyARTransMatResult(); ar.setContinueMode(false); diff --git a/trunk/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java b/trunk/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java index b17aeef..0e70559 100644 --- a/trunk/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java +++ b/trunk/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfNyARRaster_RGB.java @@ -133,7 +133,8 @@ class NyARBufferReader_Reader_RGB24 extends NyARBufferReader_Reader throw new NyARException(); } return; - } + } + } @@ -175,7 +176,7 @@ class NyARBufferReader_Reader_YUV extends NyARBufferReader_Reader this._yuv2rgb=new YUVToRGB(); this._rgb_buf=new javax.media.Buffer(); this._ref_buf=null; - //24bit-RGBフォーマットのものを探す + //24bit-BGRフォーマットのものを探す Format output_format=pickRGB24Format(this._yuv2rgb.getSupportedOutputFormats(i_input_format)); if(output_format==null){ throw new NyARException(); @@ -200,26 +201,28 @@ class NyARBufferReader_Reader_YUV extends NyARBufferReader_Reader } public void getPixel(int i_x, int i_y, int[] o_rgb) throws NyARException { - int bp = (i_x + i_y * this._ref_size.w) * 3; - byte[] ref = this._ref_buf; - o_rgb[0] = (ref[bp + 2] & 0xff);// B + //IN :BGRBGR + // :012012 + final int bp = (i_x + i_y * this._ref_size.w) * 3; + final byte[] ref = this._ref_buf; + o_rgb[0] = (ref[bp + 2] & 0xff);// R o_rgb[1] = (ref[bp + 1] & 0xff);// G - o_rgb[2] = (ref[bp + 0] & 0xff);// R + o_rgb[2] = (ref[bp + 0] & 0xff);// B return; } public void getPixelSet(int[] i_x, int i_y[], int i_num, int[] o_rgb) throws NyARException { - int width = this._ref_size.w; - byte[] ref = this._ref_buf; int bp; + final int width = this._ref_size.w; + final byte[] ref = this._ref_buf; for (int i = i_num - 1; i >= 0; i--) { bp = (i_x[i] + i_y[i] * width) * 3; - o_rgb[i * 3 + 0] = (ref[bp + 2] & 0xff);// B + o_rgb[i * 3 + 0] = (ref[bp + 2] & 0xff);// R o_rgb[i * 3 + 1] = (ref[bp + 1] & 0xff);// G - o_rgb[i * 3 + 2] = (ref[bp + 0] & 0xff);// R + o_rgb[i * 3 + 2] = (ref[bp + 0] & 0xff);// B } return; - } + } } diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/NyARCode.java b/trunk/src/jp/nyatla/nyartoolkit/core/NyARCode.java index 886b716..d5e487b 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/NyARCode.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/NyARCode.java @@ -36,163 +36,160 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.StreamTokenizer; -import jp.nyatla.nyartoolkit.NyARException; +import jp.nyatla.nyartoolkit.*; +import jp.nyatla.nyartoolkit.core.match.*; +import jp.nyatla.nyartoolkit.core.raster.*; +import jp.nyatla.nyartoolkit.core.types.*; +import jp.nyatla.nyartoolkit.core.rasterreader.*; - - -/** - * ARToolKitのマーカーコードを1個保持します。 - * - */ -public class NyARCode +class NyARCodeFileReader { - private int[][][][] pat;// static int - // pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; - - private double[] patpow = new double[4];// static double patpow[AR_PATT_NUM_MAX][4]; - - private short[][][] patBW;// static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; - - private double[] patpowBW = new double[4];// static double patpowBW[AR_PATT_NUM_MAX][4]; - private int width, height; - - public int[][][][] getPat() + /** + * ARコードファイルからデータを読み込んでo_raster[4]に格納します。 + * @param i_stream + * @param o_raster + * @throws NyARException + */ + public static void loadFromARToolKitFormFile(InputStream i_stream,NyARRaster[] o_raster) throws NyARException { - return pat; + assert o_raster.length==4; + //4個の要素をラスタにセットする。 + try { + StreamTokenizer st = new StreamTokenizer(new InputStreamReader(i_stream)); + //GBRAで一度読みだす。 + for (int h = 0; h < 4; h++) { + assert o_raster[h].getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32); + final NyARRaster ra=o_raster[h]; + readBlock(st,ra.getWidth(),ra.getHeight(),(int[])ra.getBufferReader().getBuffer()); + } + } catch (Exception e) { + throw new NyARException(e); + } + return; } - - public double[] getPatPow() + /** + * ARコードファイルからデータを読み込んでo_codeに格納します。 + * @param i_stream + * @param o_code + * @throws NyARException + */ + public static void loadFromARToolKitFormFile(InputStream i_stream,NyARCode o_code) throws NyARException { - return patpow; + int width=o_code.getWidth(); + int height=o_code.getHeight(); + NyARRaster tmp_raster=new NyARRaster(new NyARIntSize(width,height),new int[width*height],INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32); + //4個の要素をラスタにセットする。 + try { + StreamTokenizer st = new StreamTokenizer(new InputStreamReader(i_stream)); + int[] buf=(int[])tmp_raster.getBufferReader().getBuffer(); + //GBRAで一度読みだす。 + for (int h = 0; h < 4; h++){ + readBlock(st,width,height,buf); + //ARCodeにセット(カラー) + o_code.getColorData(h).setRaster(tmp_raster); + o_code.getBlackWhiteData(h).setRaster(tmp_raster); + } + } catch (Exception e) { + throw new NyARException(e); + } + tmp_raster=null;//ポイ + return; } - - public short[][][] getPatBW() + /** + * 1ブロック分のXRGBデータをi_stからo_bufへ読みだします。 + * @param i_st + * @param o_buf + */ + private static void readBlock(StreamTokenizer i_st,int i_width,int i_height,int[] o_buf) throws NyARException { - return patBW; + try { + final int pixels=i_width*i_height; + for (int i3 = 0; i3 < 3; i3++) { + for (int i2 = 0; i2 < pixels; i2++){ + // 数値のみ読み出す + switch (i_st.nextToken()){ + case StreamTokenizer.TT_NUMBER: + break; + default: + throw new NyARException(); + } + o_buf[i2]=(o_buf[i2]<<8)|((0x000000ff&(int)i_st.nval)); + } + } + //GBR→RGB + for(int i3=0;i3>16)&0x0000ff); + } + } catch (Exception e) { + throw new NyARException(e); + } + return; } +} - public double[] getPatPowBW() +/** + * ARToolKitのマーカーコードを1個保持します。 + * + */ +public class NyARCode +{ + private NyARMatchPattDeviationColorData[] _color_pat=new NyARMatchPattDeviationColorData[4]; + private NyARMatchPattDeviationBlackWhiteData[] _bw_pat=new NyARMatchPattDeviationBlackWhiteData[4]; + private int _width; + private int _height; + + public NyARMatchPattDeviationColorData getColorData(int i_index) { - return patpowBW; + return this._color_pat[i_index]; } - + public NyARMatchPattDeviationBlackWhiteData getBlackWhiteData(int i_index) + { + return this._bw_pat[i_index]; + } public int getWidth() { - return width; + return _width; } public int getHeight() { - return height; + return _height; } - - public NyARCode(int i_width, int i_height) + public NyARCode(int i_width, int i_height) throws NyARException { - width = i_width; - height = i_height; - pat = new int[4][height][width][3];// static int pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; - patBW = new short[4][height][width];// static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; + this._width = i_width; + this._height = i_height; + //空のラスタを4個作成 + for(int i=0;i<4;i++){ + this._color_pat[i]=new NyARMatchPattDeviationColorData(i_width,i_height); + this._bw_pat[i]=new NyARMatchPattDeviationBlackWhiteData(i_width,i_height); + } + return; } - - /** - * int arLoadPatt( const char *filename ); ARToolKitのパターンファイルをロードする。 - * ファイル形式はBGR形式で記録されたパターンファイルであること。 - * - * @param filename - * @return - * @throws Exception - */ public void loadARPattFromFile(String filename) throws NyARException { try { loadARPatt(new FileInputStream(filename)); - } catch (Exception e) { throw new NyARException(e); } + return; + } + public void setRaster(NyARRaster[] i_raster) throws NyARException + { + assert i_raster.length!=4; + //ラスタにパターンをロードする。 + for(int i=0;i<4;i++){ + this._color_pat[i].setRaster(i_raster[i]); + } + return; } - /** - * - * @param i_stream - * @throws NyARException - */ public void loadARPatt(InputStream i_stream) throws NyARException { - try { - StreamTokenizer st = new StreamTokenizer(new InputStreamReader( - i_stream)); - // パターンデータはGBRAで並んでる。 - for (int h = 0; h < 4; h++) { - int l = 0; - for (int i3 = 0; i3 < 3; i3++) { - for (int i2 = 0; i2 < height; i2++) { - for (int i1 = 0; i1 < width; i1++) { - // 数値のみ読み出す - switch (st.nextToken()) {// if( fscanf(fp, "%d",&j) != 1 ) { - case StreamTokenizer.TT_NUMBER: - break; - default: - throw new NyARException(); - } - short j = (short) (255 - st.nval);// j = 255-j; - // 標準ファイルのパターンはBGRでならんでるからRGBに並べなおす - switch (i3) { - case 0: - pat[h][i2][i1][2] = j; - break;// pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+2]= j;break; - case 1: - pat[h][i2][i1][1] = j; - break;// pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+1]= j;break; - case 2: - pat[h][i2][i1][0] = j; - break;// pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+0]= j;break; - } - // pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+i3]= j; - if (i3 == 0) { - patBW[h][i2][i1] = j;// patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] = j; - } else { - patBW[h][i2][i1] += j;// patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] += j; - } - if (i3 == 2) { - patBW[h][i2][i1] /= 3;// patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1]/= 3; - } - l += j; - } - } - } - - l /= (height * width * 3); - - int m = 0; - for (int i = 0; i < height; i++) {// for( i = 0; i < AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3;i++ ) { - for (int i2 = 0; i2 < width; i2++) { - for (int i3 = 0; i3 < 3; i3++) { - pat[h][i][i2][i3] -= l; - m += (pat[h][i][i2][i3] * pat[h][i][i2][i3]); - } - } - } - patpow[h] = Math.sqrt((double) m); - if (patpow[h] == 0.0) { - patpow[h] = 0.0000001; - } - - m = 0; - for (int i = 0; i < height; i++) { - for (int i2 = 0; i2 < width; i2++) { - patBW[h][i][i2] -= l; - m += (patBW[h][i][i2] * patBW[h][i][i2]); - } - } - patpowBW[h] = Math.sqrt((double) m); - if (patpowBW[h] == 0.0) { - patpowBW[h] = 0.0000001; - } - } - } catch (Exception e) { - throw new NyARException(e); - } + //ラスタにパターンをロードする。 + NyARCodeFileReader.loadFromARToolKitFormFile(i_stream,this); + return; } } diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/match/INyARMatchPatt.java b/trunk/src/jp/nyatla/nyartoolkit/core/match/INyARMatchPatt.java index 4d53e5b..a3100f1 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/match/INyARMatchPatt.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/match/INyARMatchPatt.java @@ -31,22 +31,12 @@ */ package jp.nyatla.nyartoolkit.core.match; -import jp.nyatla.nyartoolkit.NyARException; import jp.nyatla.nyartoolkit.core.NyARCode; -import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt; /** - * ARColorPattのマッチング計算をするインタフェイスです。 基準Patに対して、計算済みのARCodeデータとの間で比較演算をします。 - * pattern_match関数を分解した3種類のパターン検出クラスを定義します。 - * + * ARCodeとINyARColorPattの間で一致計算をするインタフェイスです。 */ public interface INyARMatchPatt { - public double getConfidence(); - - public int getDirection(); - - public void evaluate(NyARCode i_code); - - public boolean setPatt(INyARColorPatt i_target_patt) throws NyARException; + public void setARCode(NyARCode i_code); } diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationBlackWhiteData.java b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationBlackWhiteData.java new file mode 100644 index 0000000..dcf8994 --- /dev/null +++ b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationBlackWhiteData.java @@ -0,0 +1,100 @@ +/* + * 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 version ARToolkit class library. + * Copyright (C)2008 R.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 2 + * 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 framework; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For further information please contact. + * http://nyatla.jp/nyatoolkit/ + * + * + */ +package jp.nyatla.nyartoolkit.core.match; + + +import jp.nyatla.nyartoolkit.core.raster.*; + + +/** + * INyARMatchPattのColor差分ラスタを格納するクラスです。 + * + */ +public class NyARMatchPattDeviationBlackWhiteData +{ + private int _data[]; + private double _pow; + // + private int _number_of_pixels; + public int[] refData() + { + return this._data; + } + public double getPow() + { + return this._pow; + } + + public NyARMatchPattDeviationBlackWhiteData(int i_width,int i_height) + { + this._number_of_pixels=i_height*i_width; + this._data=new int[this._number_of_pixels]; + return; + } + /** + * XRGB[width*height]の配列から、パターンデータを構築。 + * @param i_buffer + */ + public void setRaster(INyARRaster i_raster) + { + //i_buffer[XRGB]→差分[BW]変換 + int i; + int ave;// + int rgb;// + final int[] linput=this._data;// + final int[] buf=(int[])i_raster.getBufferReader().getBuffer(); + + // input配列のサイズとwhも更新// input=new int[height][width][3]; + final int number_of_pixels=this._number_of_pixels; + + //<平均値計算(FORの1/8展開)/> + ave = 0; + for(i=number_of_pixels-1;i>=0;i--){ + rgb = buf[i]; + ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); + } + ave=(number_of_pixels*255*3-ave)/(3*number_of_pixels); + // + int sum = 0,w_sum; + + //<差分値計算/> + for (i = number_of_pixels-1; i >= 0;i--) { + rgb = buf[i]; + w_sum =((255*3-(rgb & 0xff)-((rgb >> 8) & 0xff)-((rgb >> 16) & 0xff))/3)-ave; + linput[i] = w_sum; + sum += w_sum * w_sum; + } + final double p=Math.sqrt((double) sum); + this._pow=p!=0.0?p:0.0000001; + return; + } +} diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationColorData.java b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationColorData.java new file mode 100644 index 0000000..2b1040c --- /dev/null +++ b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattDeviationColorData.java @@ -0,0 +1,157 @@ +/* + * 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 version ARToolkit class library. + * Copyright (C)2008 R.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 2 + * 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 framework; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For further information please contact. + * http://nyatla.jp/nyatoolkit/ + * + * + */ +package jp.nyatla.nyartoolkit.core.match; + + +import jp.nyatla.nyartoolkit.core.raster.*; +import jp.nyatla.nyartoolkit.core.rasterreader.*; + +/** + * INyARMatchPattのRGBColor差分データを格納するクラスです。 + * + */ +public class NyARMatchPattDeviationColorData +{ + private int _data[]; + private double _pow; + // + private int _number_of_pixels; + private int _optimize_for_mod; + public int[] refData() + { + return this._data; + } + public double getPow() + { + return this._pow; + } + + public NyARMatchPattDeviationColorData(int i_width,int i_height) + { + this._number_of_pixels=i_height*i_width; + this._data=new int[this._number_of_pixels*3]; + this._optimize_for_mod=this._number_of_pixels-(this._number_of_pixels%8); + return; + } + + + /** + * NyARRasterからパターンデータをセットします。 + * この関数は、データを元に所有するデータ領域を更新します。 + * @param i_buffer + */ + public void setRaster(INyARRaster i_raster) + { + //画素フォーマット、サイズ制限 + assert i_raster.getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32); + assert i_raster.getSize().isEqualSize(i_raster.getSize()); + + final int[] buf=(int[])i_raster.getBufferReader().getBuffer(); + //i_buffer[XRGB]→差分[R,G,B]変換 + int i; + int ave;// + int rgb;// + final int[] linput=this._data;// + + // input配列のサイズとwhも更新// input=new int[height][width][3]; + final int number_of_pixels=this._number_of_pixels; + final int for_mod=this._optimize_for_mod; + + //<平均値計算(FORの1/8展開)> + ave = 0; + for(i=number_of_pixels-1;i>=for_mod;i--){ + rgb = buf[i];ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); + } + for (;i>=0;) { + rgb = buf[i];ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);i--; + rgb = buf[i];ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);i--; + rgb = buf[i];ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);i--; + rgb = buf[i];ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);i--; + rgb = buf[i];ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);i--; + rgb = buf[i];ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);i--; + rgb = buf[i];ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);i--; + rgb = buf[i];ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);i--; + } + //<平均値計算(FORの1/8展開)/> + ave=number_of_pixels*255*3-ave; + ave =255-(ave/ (number_of_pixels * 3));//(255-R)-ave を分解するための事前計算 + + int sum = 0,w_sum; + int input_ptr=number_of_pixels*3-1; + //<差分値計算(FORの1/8展開)> + for (i = number_of_pixels-1; i >= for_mod;i--) { + rgb = buf[i]; + w_sum = (ave - (rgb & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//B + w_sum = (ave - ((rgb >> 8) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//G + w_sum = (ave - ((rgb >> 16) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//R + } + for (; i >=0;) { + rgb = buf[i];i--; + w_sum = (ave - (rgb & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//B + w_sum = (ave - ((rgb >> 8) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//G + w_sum = (ave - ((rgb >> 16) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//R + rgb = buf[i];i--; + w_sum = (ave - (rgb & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//B + w_sum = (ave - ((rgb >> 8) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//G + w_sum = (ave - ((rgb >> 16) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//R + rgb = buf[i];i--; + w_sum = (ave - (rgb & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//B + w_sum = (ave - ((rgb >> 8) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//G + w_sum = (ave - ((rgb >> 16) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//R + rgb = buf[i];i--; + w_sum = (ave - (rgb & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//B + w_sum = (ave - ((rgb >> 8) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//G + w_sum = (ave - ((rgb >> 16) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//R + rgb = buf[i];i--; + w_sum = (ave - (rgb & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//B + w_sum = (ave - ((rgb >> 8) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//G + w_sum = (ave - ((rgb >> 16) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//R + rgb = buf[i];i--; + w_sum = (ave - (rgb & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//B + w_sum = (ave - ((rgb >> 8) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//G + w_sum = (ave - ((rgb >> 16) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//R + rgb = buf[i];i--; + w_sum = (ave - (rgb & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//B + w_sum = (ave - ((rgb >> 8) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//G + w_sum = (ave - ((rgb >> 16) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//R + rgb = buf[i];i--; + w_sum = (ave - (rgb & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//B + w_sum = (ave - ((rgb >> 8) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//G + w_sum = (ave - ((rgb >> 16) & 0xff)) ;linput[input_ptr--] = w_sum;sum += w_sum * w_sum;//R + } + //<差分値計算(FORの1/8展開)/> + final double p=Math.sqrt((double) sum); + this._pow=p!=0.0?p:0.0000001; + return; + } + +} diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattResult.java b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattResult.java new file mode 100644 index 0000000..66852ee --- /dev/null +++ b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPattResult.java @@ -0,0 +1,38 @@ +/* + * 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 version ARToolkit class library. + * Copyright (C)2008 R.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 2 + * 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 framework; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For further information please contact. + * http://nyatla.jp/nyatoolkit/ + * + * + */ +package jp.nyatla.nyartoolkit.core.match; + +public class NyARMatchPattResult +{ + public double confidence; + public int direction; +} \ No newline at end of file diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java index 1073196..c36c1ea 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_BlackWhite.java @@ -33,101 +33,71 @@ package jp.nyatla.nyartoolkit.core.match; import jp.nyatla.nyartoolkit.NyARException; import jp.nyatla.nyartoolkit.core.*; -import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt; /** - * AR_TEMPLATE_MATCHING_BWと同等のルールで マーカーを評価します。 + * AR_TEMPLATE_MATCHING_BWと同等のルールで マーカを評価します。 * */ public class NyARMatchPatt_BlackWhite implements INyARMatchPatt { - private double datapow; - - private int width; - - private int height; - - private double cf = 0; - - private int dir = 0; - - private int ave; - - private int[][][] input = new int[height][width][3]; - - public boolean setPatt(INyARColorPatt i_target_patt) throws NyARException + protected NyARCode _code_patt; + protected int _pixels; + + public NyARMatchPatt_BlackWhite(int i_width, int i_height) { - width = i_target_patt.getWidth(); - height = i_target_patt.getHeight(); - int[][][] data = i_target_patt.getPatArray(); - input = new int[height][width][3]; - - int sum = ave = 0; - for (int i = 0; i < height; i++) {// for(int - // i=0;i + int i; + for(i=this._pixels-1;i>=0;i--){ + sum += linput[i] * pat_j[i]; } - double sum2 = sum / patpowBW[j] / datapow; + //0.7776737688877927がでればOK + final double sum2 = sum / code_patt.getPow() / i_patt.getPow();// sum2 = sum / patpow[k][j]/ datapow; if (sum2 > max) { max = sum2; res = j; } } - dir = res; - cf = max; + o_result.direction = res; + o_result.confidence= max; + return true; } } diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java index 358a4ec..96e4201 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITHOUT_PCA.java @@ -33,7 +33,6 @@ package jp.nyatla.nyartoolkit.core.match; import jp.nyatla.nyartoolkit.NyARException; import jp.nyatla.nyartoolkit.core.*; -import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt; /** * AR_TEMPLATE_MATCHING_COLORかつAR_MATCHING_WITHOUT_PCAと同等のルールで マーカーを評価します。 @@ -41,145 +40,85 @@ import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt; */ public class NyARMatchPatt_Color_WITHOUT_PCA implements INyARMatchPatt { - private int[][][] input = new int[1][1][3]; + protected NyARCode _code_patt; - private double datapow; - - private int width = 1; - - private int height = 1; - - private double cf = 0; - - private int dir = 0; - - public double getConfidence() + protected int _optimize_for_mod; + protected int _rgbpixels; + public NyARMatchPatt_Color_WITHOUT_PCA(NyARCode i_code_ref) { - return cf; + int w=i_code_ref.getWidth(); + int h=i_code_ref.getHeight(); + //最適化定数の計算 + this._rgbpixels=w*h*3; + this._optimize_for_mod=this._rgbpixels-(this._rgbpixels%16); + this.setARCode(i_code_ref); + return; } - - public int getDirection() + public NyARMatchPatt_Color_WITHOUT_PCA(int i_width, int i_height) { - return dir; + //最適化定数の計算 + this._rgbpixels=i_height*i_width*3; + this._optimize_for_mod=this._rgbpixels-(this._rgbpixels%16); + return; } - /** - * input配列サイズを必要に応じて再アロケートする。 - * - * @param i_width - * @param i_height + * 比較対象のARCodeをセットします。 + * @throws NyARException */ - private void reallocInputArray(int i_width, int i_height) - { - if (this.input.length < i_height || this.input[0].length < i_width) { - // 配列が十分なサイズでなければ取り直す - this.input = new int[i_height][i_width][3]; - } - this.height = i_height; - this.width = i_width; - } - - public boolean setPatt(INyARColorPatt i_target_patt) throws NyARException + public void setARCode(NyARCode i_code_ref) { - int i, k; - int[][][] data, linput; - - // input配列のサイズとwhも更新// input=new int[height][width][3]; - reallocInputArray(i_target_patt.getWidth(), i_target_patt.getHeight()); - int lwidth = this.width; - int lheight = this.height; - linput = this.input; - data = i_target_patt.getPatArray(); - - int sum = 0, l_ave = 0, w_sum; - int[][] data_i, input_i; - int[] data_i_k, input_i_k; - for (i = lheight - 1; i >= 0; i--) {// for(int i=0;i= 0; k--) {// for(int - // i2=0;i2l_ave +=(255-data[i][i2][0])+(255-data[i][i2][1])+(255-data[i][i2][2]); - data_i_k = data_i[k]; - l_ave += 255 * 3 - data_i_k[0] - data_i_k[1] - data_i_k[2]; - } - } - l_ave /= (lheight * lwidth * 3); - for (i = lheight - 1; i >= 0; i--) {// for(i=0;i= 0; k--) {// for(i2=0;i2 - // for(int i3=0;i3<3;i3++){ - // input[i][i2][i3] = (255-data[i][i2][i3]) - l_ave; - // sum += input[i][i2][i3]*input[i][i2][i3]; - // } - data_i_k = data_i[k]; - input_i_k = input_i[k]; - w_sum = (255 - data_i_k[0]) - l_ave; - input_i_k[0] = w_sum; - sum += w_sum * w_sum; - - w_sum = (255 - data_i_k[1]) - l_ave; - input_i_k[1] = w_sum; - sum += w_sum * w_sum; - - w_sum = (255 - data_i_k[2]) - l_ave; - input_i_k[2] = w_sum; - sum += w_sum * w_sum; - // - } - } - datapow = Math.sqrt((double) sum); - if (datapow == 0.0) { - return false;// throw new NyARException(); - // dir.set(0);//*dir = 0; - // cf.set(-1.0);//*cf = -1.0; - // return -1; - } - return true; + this._code_patt=i_code_ref; + return; } - /** - * public int pattern_match(short[][][] data,IntPointer dir,DoublePointer - * cf) - * + * 現在セットされているARコードとi_pattを比較します。 */ - public void evaluate(NyARCode i_code) + public boolean evaluate(NyARMatchPattDeviationColorData i_patt,NyARMatchPattResult o_result) throws NyARException { - int[][][][] pat = i_code.getPat(); - double[] patpow = i_code.getPatPow(); - int res = -1; + assert this._code_patt!=null; + // + final int[] linput = i_patt.refData(); + int sum; double max = 0.0; - int[][][] pat_j, linput; - int[][] pat_j_i, input_i; - int[] pat_j_i_k, input_i_k; - int l_width = this.width; - int l_height = this.height; - linput = this.input; + int res = NyARSquare.DIRECTION_UNKNOWN; + final int for_mod=this._optimize_for_mod; for (int j = 0; j < 4; j++) { - int sum = 0; - pat_j = pat[j]; - for (int i = l_height - 1; i >= 0; i--) {// for(int i=0;i= 0; k--) { - pat_j_i_k = pat_j_i[k]; - input_i_k = input_i[k]; - // for(int i3=0;i3<3;i3++){ - sum += input_i_k[0] * pat_j_i_k[0];// sum +=input[i][i2][i3]*pat[k][j][i][i2][i3]; - sum += input_i_k[1] * pat_j_i_k[1];// sum +=input[i][i2][i3]*pat[k][j][i][i2][i3]; - sum += input_i_k[2] * pat_j_i_k[2];// sum +=input[i][i2][i3]*pat[k][j][i][i2][i3]; - // } - } + //合計値初期化 + sum=0; + final NyARMatchPattDeviationColorData code_patt=this._code_patt.getColorData(j); + final int[] pat_j = code_patt.refData(); + //<全画素について、比較(FORの1/16展開)> + int i; + for(i=this._rgbpixels-1;i>=for_mod;i--){ + sum += linput[i] * pat_j[i]; + } + for (;i>=0;) { + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; + sum += linput[i] * pat_j[i];i--; } - double sum2 = sum / patpow[j] / datapow;// sum2 = sum / patpow[k][j]/ datapow; + //<全画素について、比較(FORの1/16展開)/> + final double sum2 = sum / code_patt.getPow();// sum2 = sum / patpow[k][j]/ datapow; if (sum2 > max) { max = sum2; res = j; } } - dir = res; - cf = max; + o_result.direction = res; + o_result.confidence= max/i_patt.getPow(); + return true; } } \ No newline at end of file diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java index 0cfd37c..6b66b10 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/match/NyARMatchPatt_Color_WITH_PCA.java @@ -33,116 +33,56 @@ package jp.nyatla.nyartoolkit.core.match; import jp.nyatla.nyartoolkit.NyARException; import jp.nyatla.nyartoolkit.core.NyARCode; -import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt; +import jp.nyatla.nyartoolkit.core.NyARSquare; /** * AR_TEMPLATE_MATCHING_COLORかつAR_MATCHING_WITH_PCAと同等のルールで マーカーを評価します。 * */ -public class NyARMatchPatt_Color_WITH_PCA implements INyARMatchPatt +public class NyARMatchPatt_Color_WITH_PCA extends NyARMatchPatt_Color_WITHOUT_PCA { private final int EVEC_MAX = 10;// #define EVEC_MAX 10 private int evec_dim;// static int evec_dim; - - private int[][][] input; - - private double[][][][] evec;// static double evec[EVEC_MAX][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; - + private double[][] evec;// static double evec[EVEC_MAX][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; private double[][] epat = new double[4][EVEC_MAX];// static double epat[AR_PATT_NUM_MAX][4][EVEC_MAX]; - private int ave; - - private double datapow; - - private int width; - - private int height; - - private double cf = 0; - private int dir = 0;// 向きか! - - public double getConfidence() + public NyARMatchPatt_Color_WITH_PCA(int i_width, int i_height) { - return cf; + super(i_width,i_height); + return; } - - public int getDirection() + public NyARMatchPatt_Color_WITH_PCA(NyARCode i_code_ref) { - return dir; - } - - public boolean setPatt(INyARColorPatt i_target_patt) throws NyARException + super(i_code_ref); + return; + } + public boolean evaluate(NyARMatchPattDeviationColorData i_patt,NyARMatchPattResult o_result) throws NyARException { - width = i_target_patt.getWidth(); - height = i_target_patt.getHeight(); - int[][][] data = i_target_patt.getPatArray(); - - input = new int[height][width][3]; - evec = new double[EVEC_MAX][height][width][3];// static double evec[EVEC_MAX][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3]; + final int[] linput = i_patt.refData(); int sum; - - sum = ave = 0; - for (int i = 0; i < height; i++) {// for(int i=0;i=i_new_width && array_h>=i_new_height){ - // //OK 十分だ→サイズ調整のみ - // }else{ - // //足りないよ→取り直し - // this.wk_pickFromRaster_ext_pat2=new int[i_new_height][i_new_width][3]; - // this.extpat=new int[i_new_height][i_new_width][3]; - // } - // this.width =i_new_width; - // this.height=i_new_height; - // return; - // } - - public int[][][] getPatArray() - { - return extpat; + //入力制限 + assert i_width<=64; + assert i_height<=64; + + this._size=new NyARIntSize(i_width,i_height); + this._patdata = new int[i_height*i_width]; + this._buf_reader=new NyARBufferReader(this._patdata,NyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32); + return; } public int getWidth() { - return width; + return this._size.w; } - public int getHeight() { - return height; + return this._size.h; + } + public NyARIntSize getSize() + { + return this._size; + } + public INyARBufferReader getBufferReader() + { + return this._buf_reader; } private final NyARMat wk_get_cpara_a = new NyARMat(8, 8); @@ -106,8 +94,7 @@ public class NyARColorPatt_O1 implements INyARColorPatt * [3x3] * @throws NyARException */ - private boolean get_cpara(double world[][], double vertex[][], double[] para) - throws NyARException + private boolean get_cpara(double world[][], double vertex[][], double[] para)throws NyARException { NyARMat a = wk_get_cpara_a;// 次処理で値を設定するので、初期化不要// new NyARMat( 8, 8 ); double[][] a_array = a.getArray(); @@ -126,35 +113,22 @@ public class NyARColorPatt_O1 implements INyARColorPatt a_pt0[3] = 0.0;// a->m[i*16+3] = 0.0; a_pt0[4] = 0.0;// a->m[i*16+4] = 0.0; a_pt0[5] = 0.0;// a->m[i*16+5] = 0.0; - a_pt0[6] = -world_pti[0] * vertex[i][0];// a->m[i*16+6] = - // -world[i][0] * - // vertex[i][0]; - a_pt0[7] = -world_pti[1] * vertex[i][0];// a->m[i*16+7] = - // -world[i][1] * - // vertex[i][0]; + a_pt0[6] = -world_pti[0] * vertex[i][0];// a->m[i*16+6] =-world[i][0] *vertex[i][0]; + a_pt0[7] = -world_pti[1] * vertex[i][0];// a->m[i*16+7] =-world[i][1] *vertex[i][0]; a_pt1[0] = 0.0;// a->m[i*16+8] = 0.0; a_pt1[1] = 0.0;// a->m[i*16+9] = 0.0; a_pt1[2] = 0.0;// a->m[i*16+10] = 0.0; a_pt1[3] = world_pti[0];// a->m[i*16+11] = world[i][0]; a_pt1[4] = world_pti[1];// a->m[i*16+12] = world[i][1]; a_pt1[5] = 1.0;// a->m[i*16+13] = 1.0; - a_pt1[6] = -world_pti[0] * vertex[i][1];// a->m[i*16+14] = - // -world[i][0] * - // vertex[i][1]; - a_pt1[7] = -world_pti[1] * vertex[i][1];// a->m[i*16+15] = - // -world[i][1] * - // vertex[i][1]; - b_array[i * 2 + 0][0] = vertex[i][0];// b->m[i*2+0] = - // vertex[i][0]; - b_array[i * 2 + 1][0] = vertex[i][1];// b->m[i*2+1] = - // vertex[i][1]; + a_pt1[6] = -world_pti[0] * vertex[i][1];// a->m[i*16+14] =-world[i][0] *vertex[i][1]; + a_pt1[7] = -world_pti[1] * vertex[i][1];// a->m[i*16+15] =-world[i][1] *vertex[i][1]; + b_array[i * 2 + 0][0] = vertex[i][0];// b->m[i*2+0] =vertex[i][0]; + b_array[i * 2 + 1][0] = vertex[i][1];// b->m[i*2+1] =vertex[i][1]; } - // JartkException.trap("未チェックのパス"); if (!a.matrixSelfInv()) { return false;// 逆行列を求められないので失敗 } - - // JartkException.trap("未チェックのパス"); NyARMat c = wk_get_cpara_c;// 次処理で結果を受け取るので、初期化不要//new NyARMat( 8, 1 ); double[][] c_array = c.getArray(); @@ -174,32 +148,9 @@ public class NyARColorPatt_O1 implements INyARColorPatt private final double[] wk_pickFromRaster_para = new double[9];// [3][3]; - private int[][][] wk_pickFromRaster_ext_pat2 = null;// コンストラクタでint[height][width][3]を作る - private final double[][] wk_pickFromRaster_world = {// double world[4][2]; - { 100.0, 100.0 }, { 100.0 + 10.0, 100.0 }, { 100.0 + 10.0, 100.0 + 10.0 }, - { 100.0, 100.0 + 10.0 } }; + { 100.0, 100.0 }, { 100.0 + 10.0, 100.0 }, { 100.0 + 10.0, 100.0 + 10.0 },{ 100.0, 100.0 + 10.0 } }; - /** - * pickFromRaster関数から使う変数です。 - * - */ - private static void initValue_wk_pickFromRaster_ext_pat2( - int[][][] i_ext_pat2, int i_width, int i_height) - { - int i, i2; - int[][] pt2; - int[] pt1; - for (i = i_height - 1; i >= 0; i--) { - pt2 = i_ext_pat2[i]; - for (i2 = i_width - 1; i2 >= 0; i2--) { - pt1 = pt2[i2]; - pt1[0] = 0; - pt1[1] = 0; - pt1[2] = 0; - } - } - } private final int[] wk_pickFromRaster_rgb_tmp = new int[3]; @@ -213,10 +164,6 @@ public class NyARColorPatt_O1 implements INyARColorPatt */ public boolean pickFromRaster(INyARRgbRaster image, NyARSquare i_square)throws NyARException { - double d, xw, yw; - int xc, yc; - int xdiv, ydiv; - int xdiv2, ydiv2; int lx1, lx2, ly1, ly2; int img_x = image.getWidth(); @@ -246,94 +193,74 @@ public class NyARColorPatt_O1 implements INyARColorPatt if (!get_cpara(world, local, para)) { return false; } - lx1 = (int) ((local[0][0] - local[1][0]) * (local[0][0] - local[1][0]) + (local[0][1] - local[1][1]) - * (local[0][1] - local[1][1])); - lx2 = (int) ((local[2][0] - local[3][0]) * (local[2][0] - local[3][0]) + (local[2][1] - local[3][1]) - * (local[2][1] - local[3][1])); - ly1 = (int) ((local[1][0] - local[2][0]) * (local[1][0] - local[2][0]) + (local[1][1] - local[2][1]) - * (local[1][1] - local[2][1])); - ly2 = (int) ((local[3][0] - local[0][0]) * (local[3][0] - local[0][0]) + (local[3][1] - local[0][1]) - * (local[3][1] - local[0][1])); + lx1 = (int) ((local[0][0] - local[1][0]) * (local[0][0] - local[1][0]) + (local[0][1] - local[1][1])* (local[0][1] - local[1][1])); + lx2 = (int) ((local[2][0] - local[3][0]) * (local[2][0] - local[3][0]) + (local[2][1] - local[3][1])* (local[2][1] - local[3][1])); + ly1 = (int) ((local[1][0] - local[2][0]) * (local[1][0] - local[2][0]) + (local[1][1] - local[2][1])* (local[1][1] - local[2][1])); + ly2 = (int) ((local[3][0] - local[0][0]) * (local[3][0] - local[0][0]) + (local[3][1] - local[0][1])* (local[3][1] - local[0][1])); if (lx2 > lx1) { lx1 = lx2; } if (ly2 > ly1) { ly1 = ly2; } - xdiv2 = this.width; - ydiv2 = this.height; + int sample_pixel_x = this._size.w; + int sample_pixel_y = this._size.h; - while (xdiv2 * xdiv2 < lx1 / 4) { - xdiv2 *= 2; + while (sample_pixel_x * sample_pixel_x < lx1 / 4) { + sample_pixel_x *= 2; } - while (ydiv2 * ydiv2 < ly1 / 4) { - ydiv2 *= 2; + while (sample_pixel_y * sample_pixel_y < ly1 / 4) { + sample_pixel_y *= 2; } - if (xdiv2 > AR_PATT_SAMPLE_NUM) { - xdiv2 = AR_PATT_SAMPLE_NUM; + if (sample_pixel_x > AR_PATT_SAMPLE_NUM) { + sample_pixel_x = AR_PATT_SAMPLE_NUM; } - if (ydiv2 > AR_PATT_SAMPLE_NUM) { - ydiv2 = AR_PATT_SAMPLE_NUM; + if (sample_pixel_y > AR_PATT_SAMPLE_NUM) { + sample_pixel_y = AR_PATT_SAMPLE_NUM; } - xdiv = xdiv2 / width;// xdiv = xdiv2/Config.AR_PATT_SIZE_X; - ydiv = ydiv2 / height;// ydiv = ydiv2/Config.AR_PATT_SIZE_Y; + final int xdiv = sample_pixel_x / this._size.w;// xdiv = xdiv2/Config.AR_PATT_SIZE_X; + final int ydiv = sample_pixel_y / this._size.h;// ydiv = ydiv2/Config.AR_PATT_SIZE_Y; - /* wk_pickFromRaster_ext_pat2ワーク変数を初期化する。 */ - int[][][] ext_pat2 = wk_pickFromRaster_ext_pat2;// ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3]; - int extpat_j[][], extpat_j_i[]; - int ext_pat2_j[][], ext_pat2_j_i[]; - initValue_wk_pickFromRaster_ext_pat2(ext_pat2, this.width, this.height); - - xdiv2_reciprocal = 1.0 / xdiv2; - ydiv2_reciprocal = 1.0 / ydiv2; - int i, j; + xdiv2_reciprocal = 1.0 / sample_pixel_x; + ydiv2_reciprocal = 1.0 / sample_pixel_y; + int r,g,b; int[] rgb_tmp = wk_pickFromRaster_rgb_tmp; //ピクセルリーダーを取得 INyARRgbPixelReader reader=image.getRgbPixelReader(); - - // arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, - // AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) ); - for (j = 0; j < ydiv2; j++) { - yw = 102.5 + 5.0 * (j + 0.5) * ydiv2_reciprocal; - for (i = 0; i < xdiv2; i++) { - xw = 102.5 + 5.0 * (i + 0.5) * xdiv2_reciprocal; - d = para[2 * 3 + 0] * xw + para[2 * 3 + 1] * yw+ para[2 * 3 + 2]; - if (d == 0) { - throw new NyARException(); + final int xdiv_x_ydiv = xdiv * ydiv; + + for(int iy=0;iy= 0 && xc < img_x && yc >= 0 && yc < img_y) { + reader.getPixel(xc, yc, rgb_tmp); + r += rgb_tmp[0];// R + g += rgb_tmp[1];// G + b += rgb_tmp[2];// B + // System.out.println(xc+":"+yc+":"+rgb_tmp[0]+":"+rgb_tmp[1]+":"+rgb_tmp[2]); + } + } } - xc = (int) ((para[0 * 3 + 0] * xw + para[0 * 3 + 1] * yw + para[0 * 3 + 2]) / d); - yc = (int) ((para[1 * 3 + 0] * xw + para[1 * 3 + 1] * yw + para[1 * 3 + 2]) / d); - - if (xc >= 0 && xc < img_x && yc >= 0 && yc < img_y) { - reader.getPixel(xc, yc, rgb_tmp); - ext_pat2_j_i = ext_pat2[j / ydiv][i / xdiv]; - - ext_pat2_j_i[0] += rgb_tmp[0];// R - ext_pat2_j_i[1] += rgb_tmp[1];// G - ext_pat2_j_i[2] += rgb_tmp[2];// B - // System.out.println(xc+":"+yc+":"+rgb_tmp[0]+":"+rgb_tmp[1]+":"+rgb_tmp[2]); - } - } - } - // short[][][] ext_pat=new short[Config.AR_PATT_SIZE_Y][Config.AR_PATT_SIZE_X][3];//ARUint32 - // ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3]; - /* */ - int xdiv_x_ydiv = xdiv * ydiv; - for (j = this.height - 1; j >= 0; j--) { - extpat_j = extpat[j]; - ext_pat2_j = ext_pat2[j]; - for (i = this.width - 1; i >= 0; i--) { // PRL 2006-06-08. - ext_pat2_j_i = ext_pat2_j[i]; - extpat_j_i = extpat_j[i]; - extpat_j_i[0] = (ext_pat2_j_i[0] / xdiv_x_ydiv);// ext_pat[j][i][0]=(byte)(ext_pat2[j][i][0] / (xdiv*ydiv)); - extpat_j_i[1] = (ext_pat2_j_i[1] / xdiv_x_ydiv);// ext_pat[j][i][1]=(byte)(ext_pat2[j][i][1]/(xdiv*ydiv)); - extpat_j_i[2] = (ext_pat2_j_i[2] / xdiv_x_ydiv);// ext_pat[j][i][2]=(byte)(ext_pat2[j][i][2]/(xdiv*ydiv)); + this._patdata[iy*this._size.w+ix]=(((r / xdiv_x_ydiv)&0xff)<<16)|(((g / xdiv_x_ydiv)&0xff)<<8)|(((b / xdiv_x_ydiv)&0xff)); } } return true; } + } \ No newline at end of file diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_O3.java b/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_O3.java index 27711a1..dd4d743 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_O3.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/pickup/NyARColorPatt_O3.java @@ -44,50 +44,33 @@ import jp.nyatla.nyartoolkit.core.types.*; */ public class NyARColorPatt_O3 implements INyARColorPatt { - private static final int AR_PATT_SAMPLE_NUM = 64;// #define - // AR_PATT_SAMPLE_NUM 64 - - private int[][][] extpat; - - private int width; - - private int height; + private static final int AR_PATT_SAMPLE_NUM = 64; + private int[] _patdata; + private NyARBufferReader _buf_reader; + private NyARIntSize _size; + public NyARColorPatt_O3(int i_width, int i_height) { - this.width = i_width; - this.height = i_height; - this.extpat = new int[i_height][i_width][3]; - } - - // public void setSize(int i_new_width,int i_new_height) - // { - // int array_w=this.extpat[0].length; - // int array_h=this.extpat.length; - // //十分なサイズのバッファがあるか確認 - // if(array_w>=i_new_width && array_h>=i_new_height){ - // //OK 十分だ→サイズ調整のみ - // }else{ - // //足りないよ→取り直し - // this.extpat=new int[i_new_height][i_new_width][3]; - // } - // this.width =i_new_width; - // this.height=i_new_height; - // return; - // } - public int[][][] getPatArray() - { - return extpat; + this._size=new NyARIntSize(i_width,i_height); + this._patdata = new int[i_height*i_width]; + this._buf_reader=new NyARBufferReader(this._patdata,NyARBufferReader.BUFFERFORMAT_INT1D_X8R8G8B8_32); } - public int getWidth() { - return width; + return this._size.w; } - public int getHeight() { - return height; + return this._size.h; + } + public NyARIntSize getSize() + { + return this._size; + } + public INyARBufferReader getBufferReader() + { + return this._buf_reader; } private final NyARMat wk_get_cpara_a = new NyARMat(8, 8); @@ -146,25 +129,6 @@ public class NyARColorPatt_O3 implements INyARColorPatt private final int[][] wk_pickFromRaster_world = {// double world[4][2]; { 100, 100 }, { 100 + 10, 100 }, { 100 + 10, 100 + 10 }, { 100, 100 + 10 } }; - /** - * pickFromRaster関数から使う変数です。 - * - */ - private static void initValue_wk_pickFromRaster_ext_pat2(int[][][] i_ext_pat2, int i_width, int i_height) - { - int i, i2; - int[][] pt2; - int[] pt1; - for (i = i_height - 1; i >= 0; i--) { - pt2 = i_ext_pat2[i]; - for (i2 = i_width - 1; i2 >= 0; i2--) { - pt1 = pt2[i2]; - pt1[0] = 0; - pt1[1] = 0; - pt1[2] = 0; - } - } - } private final NyARMat wk_pickFromRaster_cpara = new NyARMat(8, 1); @@ -179,19 +143,10 @@ public class NyARColorPatt_O3 implements INyARColorPatt { NyARMat cpara = this.wk_pickFromRaster_cpara; NyARIntPoint[] local = i_square.imvertex; - // //localの計算 - // int[] local_0=wk_pickFromRaster_local[0];//double local[4][2]; - // int[] local_1=wk_pickFromRaster_local[1];//double local[4][2]; - // // - // for(int i = 0; i < 4; i++ ) { - // local_0[i] = i_square.imvertex[i][0]; - // local_1[i] = i_square.imvertex[i][1]; - // } // xdiv2,ydiv2の計算 int xdiv2, ydiv2; int l1, l2; int w1, w2; - // x計算 w1 = local[0].x - local[1].x; w2 = local[0].y - local[1].y; @@ -203,7 +158,7 @@ public class NyARColorPatt_O3 implements INyARColorPatt l1 = l2; } l1 = l1 / 4; - xdiv2 = this.width; + xdiv2 = this._size.w; while (xdiv2 * xdiv2 < l1) { xdiv2 *= 2; } @@ -221,7 +176,7 @@ public class NyARColorPatt_O3 implements INyARColorPatt if (l2 > l1) { l1 = l2; } - ydiv2 = this.height; + ydiv2 = this._size.h; l1 = l1 / 4; while (ydiv2 * ydiv2 < l1) { ydiv2 *= 2; @@ -238,152 +193,105 @@ public class NyARColorPatt_O3 implements INyARColorPatt return true; } - - // かなり大きいワークバッファを取るな…。 - private double[] wk_updateExtpat_para00_xw; - - private double[] wk_updateExtpat_para10_xw; - - private double[] wk_updateExtpat_para20_xw; - - private int[] wk_updateExtpat_rgb_buf; - - private int[] wk_updateExtpat_x_rgb_index; - - private int[] wk_updateExtpat_y_rgb_index; - - private int[] wk_updateExtpat_i_rgb_index; - - private int wk_updateExtpat_buffer_size = 0; - - /** - * ワークバッファを予約する - * - * @param i_xdiv2 - */ - private void reservWorkBuffers(int i_xdiv2) + private int[] __updateExtpat_rgbset; + private int[] __updateExtpat_xc; + private int[] __updateExtpat_yc; + private double[] __updateExtpat_xw; + private double[] __updateExtpat_yw; + private int _last_pix_resolution_x=0; + private int _last_pix_resolution_y=0; + private void reservWorkBuffers(int i_xdiv,int i_ydiv) { - if (this.wk_updateExtpat_buffer_size < i_xdiv2) { - wk_updateExtpat_para00_xw = new double[i_xdiv2]; - wk_updateExtpat_para10_xw = new double[i_xdiv2]; - wk_updateExtpat_para20_xw = new double[i_xdiv2]; - wk_updateExtpat_rgb_buf = new int[i_xdiv2 * 3]; - wk_updateExtpat_x_rgb_index = new int[i_xdiv2]; - wk_updateExtpat_y_rgb_index = new int[i_xdiv2]; - wk_updateExtpat_i_rgb_index = new int[i_xdiv2]; - this.wk_updateExtpat_buffer_size = i_xdiv2; + if(this._last_pix_resolution_xm[i*3+0]; - para01 = cpara_array[0 * 3 + 1][0];// para[i][1] = c->m[i*3+1]; - para02 = cpara_array[0 * 3 + 2][0];// para[i][2] = c->m[i*3+2]; - para10 = cpara_array[1 * 3 + 0][0];// para[i][0] = c->m[i*3+0]; - para11 = cpara_array[1 * 3 + 1][0];// para[i][1] = c->m[i*3+1]; - para12 = cpara_array[1 * 3 + 2][0];// para[i][2] = c->m[i*3+2]; - para20 = cpara_array[2 * 3 + 0][0];// para[2][0] = c->m[2*3+0]; - para21 = cpara_array[2 * 3 + 1][0];// para[2][1] = c->m[2*3+1]; + int i,j; + int r,g,b; + //ピクセルリーダーを取得 + final int pat_size_w=this._size.w; + final int xdiv = i_xdiv2 / pat_size_w;// xdiv = xdiv2/Config.AR_PATT_SIZE_X; + final int ydiv = i_ydiv2 / this._size.h;// ydiv = ydiv2/Config.AR_PATT_SIZE_Y; + final int xdiv_x_ydiv = xdiv * ydiv; + double reciprocal; + final double[][] para=i_cpara.getArray(); + final double para00=para[0*3+0][0]; + final double para01=para[0*3+1][0]; + final double para02=para[0*3+2][0]; + final double para10=para[1*3+0][0]; + final double para11=para[1*3+1][0]; + final double para12=para[1*3+2][0]; + final double para20=para[2*3+0][0]; + final double para21=para[2*3+1][0]; - double d, yw; - int xc, yc; - int i, j; - // arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, - // AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) ); - int xdiv = i_xdiv2 / L_WIDTH;// xdiv = xdiv2/Config.AR_PATT_SIZE_X; - int ydiv = i_ydiv2 / L_HEIGHT;// ydiv = ydiv2/Config.AR_PATT_SIZE_Y; + INyARRgbPixelReader reader=image.getRgbPixelReader(); + final int img_width=image.getWidth(); + final int img_height=image.getHeight(); - // 計算バッファを予約する - this.reservWorkBuffers(i_xdiv2); - double[] para00_xw = this.wk_updateExtpat_para00_xw; - double[] para10_xw = this.wk_updateExtpat_para10_xw; - double[] para20_xw = this.wk_updateExtpat_para20_xw; - int[] x_rgb_index = this.wk_updateExtpat_x_rgb_index; - int[] y_rgb_index = this.wk_updateExtpat_y_rgb_index; - int[] i_rgb_index = this.wk_updateExtpat_i_rgb_index; - int[] rgb_buf = this.wk_updateExtpat_rgb_buf; - double xw; - for (i = 0; i < i_xdiv2; i++) { - xw = 102.5 + 5.0 * ((double) i + 0.5) / i_xdiv2; - para20_xw[i] = para20 * xw; - para00_xw[i] = para00 * xw; - para10_xw[i] = para10 * xw; - } + //ワークバッファの準備 + reservWorkBuffers(xdiv,ydiv); + final double xw[]=this.__updateExtpat_xw; + final double yw[]=this.__updateExtpat_yw; + final int[] xc=this.__updateExtpat_xc; + final int[] yc=this.__updateExtpat_yc; + int[] rgb_set = this.__updateExtpat_rgbset; - int index_num; - //ピクセルリーダーを取得 - INyARRgbPixelReader reader=image.getRgbPixelReader(); - for (j = 0; j < i_ydiv2; j++) { - yw = 102.5 + 5.0 * ((double) j + 0.5) / i_ydiv2; - para21_x_yw = para21 * yw + 1.0; - para11_x_yw = para11 * yw + para12; - para01_x_yw = para01 * yw + para02; - extpat_j = L_extpat[j / ydiv]; - index_num = 0; - // ステップ1.RGB取得用のマップを作成 - for (i = 0; i < i_xdiv2; i++) { - d = para20_xw[i] + para21_x_yw; - if (d == 0) { - throw new NyARException(); + + for(int iy=this._size.h-1;iy>=0;iy--){ + for(int ix=pat_size_w-1;ix>=0;ix--){ + //xw,ywマップを作成 + reciprocal= 1.0 / i_xdiv2; + for(i=xdiv-1;i>=0;i--){ + xw[i]=102.5 + 5.0 * (ix*xdiv+i + 0.5) * reciprocal; } - xc = (int) ((para00_xw[i] + para01_x_yw) / d); - yc = (int) ((para10_xw[i] + para11_x_yw) / d); - // 範囲外は無視 - if (xc < 0 || xc >= img_x || yc < 0 || yc >= img_y) { - continue; + reciprocal= 1.0 / i_ydiv2; + for(i=ydiv-1;i>=0;i--){ + yw[i]=102.5 + 5.0 * (iy*ydiv+i + 0.5) * reciprocal; } - // ピクセル値の計算 - // image.getPixel(xc,yc,rgb_buf); - // ext_pat2_j_i=ext_pat2_j[i/xdiv]; - // ext_pat2_j_i[0] += rgb_buf[0];//R - // ext_pat2_j_i[1] += rgb_buf[1];//G - // ext_pat2_j_i[2] += rgb_buf[2];//B - - x_rgb_index[index_num] = xc; - y_rgb_index[index_num] = yc; - i_rgb_index[index_num] = i / xdiv; - index_num++; - } - // //ステップ2.ピクセル配列を取得 - reader.getPixelSet(x_rgb_index, y_rgb_index, index_num, rgb_buf); - // //ピクセル値の計算 - for (i = index_num - 1; i >= 0; i--) { - extpat_j_i = extpat_j[i_rgb_index[i]]; - extpat_j_i[0] += rgb_buf[i * 3 + 0];// R - extpat_j_i[1] += rgb_buf[i * 3 + 1];// G - extpat_j_i[2] += rgb_buf[i * 3 + 2];// B - } - } - /* */ - int xdiv_x_ydiv = xdiv * ydiv; - for (j = L_HEIGHT - 1; j >= 0; j--) { - extpat_j = L_extpat[j]; - for (i = L_WIDTH - 1; i >= 0; i--) { // PRL 2006-06-08. - extpat_j_i = extpat_j[i]; - extpat_j_i[0] /= (xdiv_x_ydiv);// ext_pat[j][i][0] =(byte)(ext_pat2[j][i][0] /(xdiv*ydiv)); - extpat_j_i[1] /= (xdiv_x_ydiv);// ext_pat[j][i][1] =(byte)(ext_pat2[j][i][1] /(xdiv*ydiv)); - extpat_j_i[2] /= (xdiv_x_ydiv);// ext_pat[j][i][2] =(byte)(ext_pat2[j][i][2] /(xdiv*ydiv)); + //xc,ycマップを作成 + int number_of_pix=0; + for(i=ydiv-1;i>=0;i--) + { + final double para01_x_yw_para02=para01 * yw[i] + para02; + final double para11_x_yw_para12=para11 * yw[i] + para12; + final double para12_x_yw_para22=para21 * yw[i]+ 1.0; + for(j=xdiv-1;j>=0;j--){ + + final double d = para20 * xw[j] + para12_x_yw_para22; + if (d == 0) { + throw new NyARException(); + } + final int xcw= (int) ((para00 * xw[j] + para01_x_yw_para02) / d); + final int ycw= (int) ((para10 * xw[j] + para11_x_yw_para12) / d); + if(xcw<0 || xcw>=img_width || ycw<0 ||ycw>=img_height){ + continue; + } + xc[number_of_pix] =xcw; + yc[number_of_pix] =ycw; + number_of_pix++; + } + } + //ピクセル取得とピクセル値の計算 + reader.getPixelSet(xc,yc,number_of_pix, rgb_set); + r=g=b=0; + for(i=number_of_pix*3-1;i>=0;i-=3){ + r += rgb_set[i-2];// R + g += rgb_set[i-1];// G + b += rgb_set[i];// B + } + //1ピクセル確定 + this._patdata[iy*pat_size_w+ix]=(((r / xdiv_x_ydiv)&0xff)<<16)|(((g / xdiv_x_ydiv)&0xff)<<8)|(((b / xdiv_x_ydiv)&0xff)); } } return; diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java b/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java index 9a13ec2..a2134dc 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java @@ -34,7 +34,7 @@ package jp.nyatla.nyartoolkit.core.raster; import jp.nyatla.nyartoolkit.core.rasterreader.*; import jp.nyatla.nyartoolkit.core.types.*; -public final class NyARBinRaster extends NyARRaster_BasicClass +public class NyARBinRaster extends NyARRaster_BasicClass { private INyARBufferReader _buffer_reader; protected int[] _ref_buf; diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java b/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java new file mode 100644 index 0000000..6c79b1c --- /dev/null +++ b/trunk/src/jp/nyatla/nyartoolkit/core/raster/NyARRaster.java @@ -0,0 +1,54 @@ +/* + * 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 version ARToolkit class library. + * Copyright (C)2008 R.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 2 + * 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 framework; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For further information please contact. + * http://nyatla.jp/nyatoolkit/ + * + * + */ +package jp.nyatla.nyartoolkit.core.raster; + +import jp.nyatla.nyartoolkit.core.rasterreader.*; +import jp.nyatla.nyartoolkit.core.types.*; + +/**このクラスは、単機能のNyARRasterです。 + * 特定タイプのバッファをラップする、INyARBufferReaderインタフェイスを提供します。 + * + */ +public final class NyARRaster extends NyARRaster_BasicClass +{ + private NyARBufferReader _reader; + public INyARBufferReader getBufferReader() + { + return this._reader; + } + public NyARRaster(NyARIntSize i_size,Object i_ref_buf,int i_buf_type) + { + super(i_size); + this._reader=new NyARBufferReader(i_ref_buf,i_buf_type); + return; + } +} \ No newline at end of file diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BGRA.java b/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BGRA.java index 995eb45..ed83cf0 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BGRA.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BGRA.java @@ -47,8 +47,8 @@ public class NyARRgbRaster_BGRA extends NyARRgbRaster_BasicClass implements INyA public void getPixel(int i_x, int i_y, int[] o_rgb) { - byte[] ref_buf = this._parent._ref_buf; - int bp = (i_x + i_y * this._parent._size.w) * 4; + final byte[] ref_buf = this._parent._ref_buf; + final int bp = (i_x + i_y * this._parent._size.w) * 4; o_rgb[0] = (ref_buf[bp + 2] & 0xff);// R o_rgb[1] = (ref_buf[bp + 1] & 0xff);// G o_rgb[2] = (ref_buf[bp + 0] & 0xff);// B @@ -57,15 +57,16 @@ public class NyARRgbRaster_BGRA extends NyARRgbRaster_BasicClass implements INyA public void getPixelSet(int[] i_x, int[] i_y, int i_num, int[] o_rgb) { - int width = _parent._size.w; - byte[] ref_buf = _parent._ref_buf; int bp; + final int width = _parent._size.w; + final byte[] ref_buf = _parent._ref_buf; for (int i = i_num - 1; i >= 0; i--) { bp = (i_x[i] + i_y[i] * width) * 4; o_rgb[i * 3 + 0] = (ref_buf[bp + 2] & 0xff);// R o_rgb[i * 3 + 1] = (ref_buf[bp + 1] & 0xff);// G o_rgb[i * 3 + 2] = (ref_buf[bp + 0] & 0xff);// B } + return; } } diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BasicClass.java b/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BasicClass.java index 5ef9a16..a1abbcf 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BasicClass.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_BasicClass.java @@ -32,7 +32,6 @@ package jp.nyatla.nyartoolkit.core.raster.rgb; import jp.nyatla.nyartoolkit.NyARException; -import jp.nyatla.nyartoolkit.core.raster.NyARRaster_BasicClass; import jp.nyatla.nyartoolkit.core.rasterreader.INyARRgbPixelReader; import jp.nyatla.nyartoolkit.core.types.NyARIntSize; @@ -41,11 +40,26 @@ import jp.nyatla.nyartoolkit.core.types.NyARIntSize; * * */ -public abstract class NyARRgbRaster_BasicClass extends NyARRaster_BasicClass implements INyARRgbRaster +public abstract class NyARRgbRaster_BasicClass implements INyARRgbRaster { + final protected NyARIntSize _size; + final public int getWidth() + { + return this._size.w; + } + + final public int getHeight() + { + return this._size.h; + } + + final public NyARIntSize getSize() + { + return this._size; + } protected NyARRgbRaster_BasicClass(final NyARIntSize i_size) { - super(i_size); + this._size= i_size; } public INyARRgbPixelReader getRgbPixcelReader() throws NyARException { diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_Blank.java b/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_Blank.java index d7780c4..875707d 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_Blank.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/raster/rgb/NyARRgbRaster_Blank.java @@ -59,7 +59,7 @@ public class NyARRgbRaster_Blank extends NyARRgbRaster_BasicClass o_rgb[i * 3 + 1] = 0;// G o_rgb[i * 3 + 2] = 0;// B } - } + } } private INyARRgbPixelReader _reader; diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARRgbPixelReader.java b/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARRgbPixelReader.java index 71b8c9c..956b54d 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARRgbPixelReader.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARRgbPixelReader.java @@ -49,16 +49,13 @@ public interface INyARRgbPixelReader public void getPixel(int i_x, int i_y, int[] i_rgb) throws NyARException; /** - * 複数のピクセル値をi_rgbへ返します。 + * 複数のピクセル値をint配列に返します。 + * 配列には、[R1][G1][B1][R2][G2][B2]の順でピクセル値が格納されます。 * * @param i_x * xのインデックス配列 * @param i_y * yのインデックス配列 - * @param i_num - * 返すピクセル値の数 - * @param i_rgb - * ピクセル値を返すバッファ */ - public void getPixelSet(int[] i_x, int[] i_y, int i_num, int[] i_rgb) throws NyARException; + public void getPixelSet(int i_x[], int i_y[], int i_num, int[] i_intrgb) throws NyARException; } diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java b/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java index d1cd080..f539736 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java @@ -31,11 +31,11 @@ */ package jp.nyatla.nyartoolkit.core.rasterreader; -public class NyARBufferReader implements INyARBufferReader +public final class NyARBufferReader implements INyARBufferReader { - protected Object _buffer; - protected int _buffer_type; - protected NyARBufferReader() + private Object _buffer; + private int _buffer_type; + private NyARBufferReader() { return; } diff --git a/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_RGB24.java b/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_RGB24.java index 86d3dba..77785c5 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_RGB24.java +++ b/trunk/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARRgbPixelReader_RGB24.java @@ -31,6 +31,7 @@ */ package jp.nyatla.nyartoolkit.core.rasterreader; +import jp.nyatla.nyartoolkit.NyARException; import jp.nyatla.nyartoolkit.core.types.*; /** * byte[]配列に、パディング無しの8bit画素値が、RGBRGBの順で並んでいる @@ -51,8 +52,8 @@ public class NyARRgbPixelReader_RGB24 implements INyARRgbPixelReader public void getPixel(int i_x, int i_y, int[] o_rgb) { - byte[] ref_buf = this._ref_buf; - int bp = (i_x + i_y * this._size.w) * 3; + final byte[] ref_buf = this._ref_buf; + final int bp = (i_x + i_y * this._size.w) * 3; o_rgb[0] = (ref_buf[bp + 0] & 0xff);// R o_rgb[1] = (ref_buf[bp + 1] & 0xff);// G o_rgb[2] = (ref_buf[bp + 2] & 0xff);// B @@ -61,14 +62,15 @@ public class NyARRgbPixelReader_RGB24 implements INyARRgbPixelReader public void getPixelSet(int[] i_x, int[] i_y, int i_num, int[] o_rgb) { - int width = this._size.w; - byte[] ref_buf = this._ref_buf; int bp; + final int width = this._size.w; + final byte[] ref_buf = this._ref_buf; for (int i = i_num - 1; i >= 0; i--) { bp = (i_x[i] + i_y[i] * width) * 3; o_rgb[i * 3 + 0] = (ref_buf[bp + 0] & 0xff);// R o_rgb[i * 3 + 1] = (ref_buf[bp + 1] & 0xff);// G o_rgb[i * 3 + 2] = (ref_buf[bp + 2] & 0xff);// B } - } + return; + } } \ No newline at end of file diff --git a/trunk/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java b/trunk/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java index 1e27263..4e332e0 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java +++ b/trunk/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java @@ -42,9 +42,13 @@ import jp.nyatla.nyartoolkit.core.transmat.*; import jp.nyatla.nyartoolkit.core.types.NyARIntSize; import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*; import jp.nyatla.nyartoolkit.core.types.*; +import java.util.*; /** * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。 + * 変換行列を求めるには、detectMarkerLite関数にラスタイメージを入力して、計算対象の矩形を特定します。 + * detectMarkerLiteが成功すると、getTransmationMatrix等の関数が使用可能な状態になり、変換行列を求めることができます。 + * * */ public class NyARCustomSingleDetectMarker @@ -57,8 +61,6 @@ public class NyARCustomSingleDetectMarker private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX); - private NyARCode _code; - protected INyARTransMat _transmat; private double _marker_width; @@ -71,6 +73,7 @@ public class NyARCustomSingleDetectMarker private NyARBinRaster _bin_raster; protected INyARRasterFilter_RgbToBin _tobin_filter; + private NyARMatchPattDeviationColorData _deviation_data; /** * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。 * @@ -91,17 +94,22 @@ public class NyARCustomSingleDetectMarker this._square_detect = new NyARSquareDetector(i_param.getDistortionFactor(),scr_size); this._transmat = new NyARTransMat(i_param); // 比較コードを保存 - this._code = i_code; this._marker_width = i_marker_width; - // 評価パターンのホルダを作る - this._patt = new NyARColorPatt_O3(_code.getWidth(), _code.getHeight()); - // 評価器を作る。 - this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(); + //パターンピックアップを作成 +// this._patt = new NyARColorPatt_O1(i_code.getWidth(), i_code.getHeight()); + this._patt = new NyARColorPatt_O3(i_code.getWidth(), i_code.getHeight()); + //取得パターンの差分データ器を作成 + this._deviation_data=new NyARMatchPattDeviationColorData(i_code.getWidth(),i_code.getHeight()); + //i_code用の評価器を作成 + this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(i_code); + //2値画像バッファを作る this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h); this._tobin_filter=i_filter; + return; } + private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult(); /** * i_imageにマーカー検出処理を実行し、結果を記録します。 @@ -134,43 +142,38 @@ public class NyARCustomSingleDetectMarker if (number_of_square < 1) { return false; } - - // 評価基準になるパターンをイメージから切り出す - if (!this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(0))) { - // パターンの切り出しに失敗 - return false; - } - // パターンを評価器にセット - if (!this._match_patt.setPatt(this._patt)) { - // 計算に失敗した。 - throw new NyARException(); - } - // コードと比較する - this._match_patt.evaluate(this._code); + + boolean result=false; + NyARMatchPattResult mr=this.__detectMarkerLite_mr; int square_index = 0; - int direction = this._match_patt.getDirection(); - double confidence = this._match_patt.getConfidence(); - for (int i = 1; i < number_of_square; i++) { - // 次のパターンを取得 - this._patt.pickFromRaster(i_raster, (NyARSquare)l_square_list.getItem(i)); - // 評価器にセットする。 - this._match_patt.setPatt(this._patt); - // コードと比較する - this._match_patt.evaluate(this._code); - double c2 = this._match_patt.getConfidence(); + int direction = NyARSquare.DIRECTION_UNKNOWN; + double confidence = 0; + for(int i=0;i c2) { continue; } // もっと一致するマーカーがあったぽい square_index = i; - direction = this._match_patt.getDirection(); + direction = mr.direction; confidence = c2; + result=true; } + // マーカー情報を保存 this._detected_square = (NyARSquare)l_square_list.getItem(square_index); this._detected_direction = direction; this._detected_confidence = confidence; - return true; + return result; } /** diff --git a/trunk/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java b/trunk/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java index 4932472..568d315 100644 --- a/trunk/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java +++ b/trunk/src/jp/nyatla/nyartoolkit/detector/NyARDetectMarker.java @@ -84,70 +84,70 @@ public class NyARDetectMarker private boolean _is_continue = false; - private NyARMatchPatt_Color_WITHOUT_PCA _match_patt; + private NyARMatchPatt_Color_WITHOUT_PCA[] _match_patt; private INyARSquareDetector _square_detect; private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX); - private NyARCode[] _codes; - protected INyARTransMat _transmat; - private double[] _marker_width; - - private int _number_of_code; + private double[] _marker_width; // 検出結果の保存用 private INyARColorPatt _patt; private NyARDetectMarkerResultHolder _result_holder = new NyARDetectMarkerResultHolder(); - + private NyARMatchPattDeviationColorData _deviation_data; /** * 複数のマーカーを検出し、最も一致するARCodeをi_codeから検索するオブジェクトを作ります。 * * @param i_param * カメラパラメータを指定します。 * @param i_code - * 検出するマーカーのARCode配列を指定します。配列要素のインデックス番号が、そのままgetARCodeIndex関数で 得られるARCodeインデックスになります。 例えば、要素[1]のARCodeに一致したマーカーである場合は、getARCodeIndexは1を返します。 - * 先頭からi_number_of_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 NyARDetectMarker(NyARParam i_param, NyARCode[] i_code, double[] i_marker_width, int i_number_of_code) throws NyARException + public NyARDetectMarker(NyARParam i_param,NyARCode[] i_code,double[] i_marker_width, int i_number_of_code) throws NyARException { final NyARIntSize scr_size=i_param.getScreenSize(); // 解析オブジェクトを作る this._square_detect = new NyARSquareDetector(i_param.getDistortionFactor(),scr_size); this._transmat = new NyARTransMat(i_param); - // 比較コードを保存 - this._codes = i_code; - // 比較コードの解像度は全部同じかな?(違うとパターンを複数種つくらないといけないから) + + //各コード用の比較器を作る。 + this._match_patt=new NyARMatchPatt_Color_WITHOUT_PCA[i_number_of_code]; final int cw = i_code[0].getWidth(); final int ch = i_code[0].getHeight(); - for (int i = 1; i < i_number_of_code; i++) { + this._match_patt[0]=new NyARMatchPatt_Color_WITHOUT_PCA(i_code[0]); + for (int i = 1; i < i_number_of_code; i++){ + //解像度チェック if (cw != i_code[i].getWidth() || ch != i_code[i].getHeight()) { - // 違う解像度のが混ざっている。 throw new NyARException(); } - } + this._match_patt[i]=new NyARMatchPatt_Color_WITHOUT_PCA(i_code[i]); + } // 評価パターンのホルダを作る this._patt = new NyARColorPatt_O3(cw, ch); - this._number_of_code = i_number_of_code; - + //実サイズ保存 this._marker_width = i_marker_width; - // 評価器を作る。 - this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA(); + //差分データインスタンスの作成 + this._deviation_data=new NyARMatchPattDeviationColorData(cw,ch); //2値画像バッファを作る - this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h); + this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h); + return; } private NyARBinRaster _bin_raster; private NyARRasterFilter_ARToolkitThreshold _tobin_filter = new NyARRasterFilter_ARToolkitThreshold(100); + private final NyARMatchPattResult __detectMarkerLite_mr=new NyARMatchPattResult(); /** * i_imageにマーカー検出処理を実行し、結果を記録します。 @@ -182,40 +182,37 @@ public class NyARDetectMarker } // 保持リストのサイズを調整 this._result_holder.reservHolder(number_of_square); + NyARMatchPattResult mr=this.__detectMarkerLite_mr; // 1スクエア毎に、一致するコードを決定していく for (int i = 0; i < number_of_square; i++) { NyARSquare square = (NyARSquare)l_square_list.getItem(i); + // 評価基準になるパターンをイメージから切り出す if (!this._patt.pickFromRaster(i_raster, square)) { // イメージの切り出しは失敗することもある。 continue; } - // パターンを評価器にセット - if (!this._match_patt.setPatt(this._patt)) { - // 計算に失敗した。 - throw new NyARException(); - } - // コードと順番に比較していく - int code_index = 0; - _match_patt.evaluate(_codes[0]); - double confidence = _match_patt.getConfidence(); - int direction = _match_patt.getDirection(); - for (int i2 = 1; i2 < this._number_of_code; i2++) { - // コードと比較する - _match_patt.evaluate(_codes[i2]); - double c2 = _match_patt.getConfidence(); + //取得パターンをカラー差分データに変換する。 + this._deviation_data.setRaster(this._patt); + int square_index = 0; + int direction = NyARSquare.DIRECTION_UNKNOWN; + double confidence = 0; + for(int i2=0;i2 c2) { continue; } - // より一致するARCodeの情報を保存 - code_index = i2; - direction = _match_patt.getDirection(); + // もっと一致するマーカーがあったぽい + square_index = i2; + direction = mr.direction; confidence = c2; } - // i番目のパターン情報を保存する。 + // i番目のパターン情報を記録する。 final NyARDetectMarkerResult result = this._result_holder.result_array[i]; - result.arcode_id = code_index; + result.arcode_id = square_index; result.confidence = confidence; result.direction = direction; result.ref_square = square; diff --git a/trunk/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java b/trunk/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java new file mode 100644 index 0000000..70ae433 --- /dev/null +++ b/trunk/src/jp/nyatla/nyartoolkit/processor/SingleARMarkerProcesser.java @@ -0,0 +1,330 @@ +/* + * Capture Test NyARToolkitCSサンプルプログラム + * -------------------------------------------------------------------------------- + * Copyright (C)2008 R.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 2 + * 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 framework; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For further information please contact. + * http://nyatla.jp/nyatoolkit/ + * + * + */ +package jp.nyatla.nyartoolkit.processor; + +import jp.nyatla.nyartoolkit.NyARException; +import jp.nyatla.nyartoolkit.core.*; +import jp.nyatla.nyartoolkit.core.match.*; +import jp.nyatla.nyartoolkit.core.param.*; +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.types.*; + +/**このクラスは、同時に1個のマーカを処理することのできる、アプリケーションプロセッサです。 + * マーカの出現・移動・消滅を、イベントで通知することができます。 + * クラスには複数のマーカを登録できます。一つのマーカが見つかると、プロセッサは継続して同じマーカを + * 1つだけ認識し続け、見失うまでの間は他のマーカを認識しません。 + * + * イベントは、 OnEnter→OnUpdate[n]→OnLeaveの順で発生します。 + * マーカが見つかるとまずOnEnterが1度発生して、何番のマーカが発見されたかがわかります。 + * 次にOnUpdateにより、現在の変換行列が連続して渡されます。最後にマーカを見失うと、OnLeave + * イベントがコールされます。 + * + */ +public abstract class SingleARMarkerProcesser +{ + /**selectARCodeIndexFromListが値を返す時に使う変数型です。 + */ + + private class TResult_selectARCodeIndex + { + public int direction; + + public double confidence; + + public int code_index; + } + /**オーナーが自由に使えるタグ変数です。 + */ + public Object tag; + + private int _lost_delay_count = 0; + + private int _lost_delay = 5; + + private NyARSquareDetector _square_detect; + + protected NyARTransMat _transmat; + + private double _marker_width; + + private NyARMatchPatt_Color_WITHOUT_PCA[] _match_patt; + + private NyARSquareStack _square_list = new NyARSquareStack(100); + + private NyARColorPatt_O3 _patt = null; + + private double _cf_threshold_new = 0.30; + + private double _cf_threshold_exist = 0.15; + + private int _threshold = 110; + // [AR]検出結果の保存用 + private NyARBinRaster _bin_raster; + + private NyARRasterFilter_ARToolkitThreshold _tobin_filter = new NyARRasterFilter_ARToolkitThreshold(110); + + protected int _current_arcode_index = -1; + + private NyARMatchPattDeviationColorData _deviation_data; + + + public SingleARMarkerProcesser(NyARParam i_param) throws NyARException + { + NyARIntSize scr_size = i_param.getScreenSize(); + // 解析オブジェクトを作る + this._square_detect = new NyARSquareDetector(i_param.getDistortionFactor(), scr_size); + this._transmat = new NyARTransMat(i_param); + this._deviation_data=new NyARMatchPattDeviationColorData(scr_size.w,scr_size.h); + + // 2値画像バッファを作る + this._bin_raster = new NyARBinRaster(scr_size.w / 2, scr_size.h / 2); + return; + } + + public void setThreshold(int i_threshold) + { + this._threshold = i_threshold; + return; + } + + /**検出するマーカコードの配列を指定します。 検出状態でこの関数を実行すると、 + * オブジェクト状態に強制リセットがかかります。 + */ + public void setARCodeTable(NyARCode[] i_ref_code_table, int i_code_resolution, double i_marker_width) + { + if (this._current_arcode_index != -1) { + // 強制リセット + reset(true); + } + // 検出するマーカセット、情報、検出器を作り直す。 + this._patt = new NyARColorPatt_O3(i_code_resolution, i_code_resolution); + this._marker_width = i_marker_width; + + this._match_patt = new NyARMatchPatt_Color_WITHOUT_PCA[i_ref_code_table.length]; + for(int i=0;i