From: nyatla Date: Sat, 7 Jun 2008 01:29:06 +0000 (+0000) Subject: [リリース]NyARToolkit 0.6 X-Git-Tag: 0.6~1 X-Git-Url: http://git.osdn.net/view?p=nyartoolkit-and%2Fnyartoolkit-and.git;a=commitdiff_plain;h=a3eab400fa4987c0399c7549e745ed79c97bbe70 [リリース]NyARToolkit 0.6 --- diff --git a/changelog/0.6.20080330.0.txt b/changelog/0.6.20080330.0.txt new file mode 100644 index 0000000..0dba4ee --- /dev/null +++ b/changelog/0.6.20080330.0.txt @@ -0,0 +1,30 @@ +2008.03.30 version 0.6.20080330.0 + +*Title +-メモリ管理の見直し +-速度向上(84%up) +-サンプルの15fps化 + +*PublicAPI + +-NyARCode.java +[改名--rename] + NyARCode::LoadFromARFileをNyARCode::loadFromARFile + +-NyARDetectMarker.java +[廃止--delete] +NyARDetectMarker::getMarkerArray +[追加--add] +NyARDetectMarker::getMarker + + +-NyARMat.java +[更新--update] +NyARMat::matrixSelfInv +NyARMat::matrixDup + +-DoubleValue.java +[廃止--delete] +DoubleValue::set +DoubleValue::get +DoubleValue::add diff --git a/readme.ja.txt b/readme.ja.txt index 7ef27f4..aff2908 100644 --- a/readme.ja.txt +++ b/readme.ja.txt @@ -1,7 +1,7 @@ ARToolkit Java class library NyARToolkit. Copyright (C)2008 R.Iizuka -version Alpha 0.5.20080329.0 +version Alpha 0.6.20080330.0 http://nyatla.jp/ airmail(at)ebony.plala.or.jp @@ -15,25 +15,30 @@ airmail(at)ebony.plala.or.jp NyARToolkitは、nativeなコードを一切使用しない、Pure Javaのみで 構成されたARToolkitクラスライブラリです。 -ARToolkit 2.72.0をベースに構築されています。 +ARToolkit 2.72.1をベースに構築されています。 J2SEでのみ動作を確認しました。 J2MEやMIDP2.0にはそのうち対応します。 +ARToolkitは加藤博一先生とHuman Interface Technology Labにより +開発されたAugmented Reality (AR) ライブラリです。 +詳しくはこちらをご覧下さい。 +http://www.hitl.washington.edu/artoolkit/ + ・基本構成 -+---------------------------- -| Application | -+-------+-------+-----------+ -|NyARJMF| NyJogl| | -+-------+-------+ | -| JMF | JOGL |NyARToolkit| -+-------+-------+ | -|Camera | 3D | | -----------------------------+ ++-----------------------------+ +| Application | ++-------+-------+-------------+ +|NyARJMF| NyARJogl| | ++-------+---------+ | +| JMF | JOGL |NyARToolkit| ++-------+---------+ | +|Camera | 3D | | +------------------------------+ 映像キャプチャにはJMFを使用し、3D描画にはJoglを使用しています。 NyARJMFとNyJoglは、これらのエクステンションをApplicationやNyARToolKit @@ -103,7 +108,6 @@ GPLです。詳しくはLICENCE.txtをみてください。 ・お願い - NyARToolkitを使って面白いものが出来たら、是非教えてください。 それと強制では有りませんが、NyARToolkitを使った感想などを @@ -111,7 +115,6 @@ NyARToolkitを使って面白いものが出来たら、是非教えてくださ - ではでは、楽しく遊んでくださいネ。 -2008.03.29 R.Iizuka@nyatla.jp +2008.03.29 R.Iizuka nyatla.jp diff --git a/sample/jmf/NyarToolkitLinkTest.java b/sample/jmf/NyarToolkitLinkTest.java index ed667c5..4a6c79a 100644 --- a/sample/jmf/NyarToolkitLinkTest.java +++ b/sample/jmf/NyarToolkitLinkTest.java @@ -44,7 +44,7 @@ public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener ar_param.loadFromARFile(PARAM_FILE); ar_param.changeSize(320,240); nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0); - ar_code.LoadFromARFile(CARCODE_FILE); + ar_code.loadFromARFile(CARCODE_FILE); } diff --git a/sample/jogl/JavaSimpleLite.java b/sample/jogl/JavaSimpleLite.java index 5b54af6..35733fe 100644 --- a/sample/jogl/JavaSimpleLite.java +++ b/sample/jogl/JavaSimpleLite.java @@ -121,7 +121,7 @@ public class JavaSimpleLite implements GLEventListener,JmfCaptureListener //NyARToolkitの準備 try{ //キャプチャの準備 - capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXCEL_FORMAT_RGB); + capture=new JmfCameraCapture(320,240,15f,JmfCameraCapture.PIXCEL_FORMAT_RGB); capture.setCaptureListener(this); capture.start(); //NyARToolkitの準備 @@ -130,7 +130,7 @@ public class JavaSimpleLite implements GLEventListener,JmfCaptureListener ar_param.loadFromARFile(PARAM_FILE); ar_param.changeSize(320,240); nya=new GLNyARSingleDetectMarker(ar_param,ar_code,80.0); - ar_code.LoadFromARFile(CARCODE_FILE); + ar_code.loadFromARFile(CARCODE_FILE); //GL対応のRGBラスタオブジェクト cap_image=new GLNyARRaster_RGB(gl,ar_param,320,240); diff --git a/src/jp/nyatla/nyartoolkit/base/Param.java b/src/jp/nyatla/nyartoolkit/base/Param.java index 5079131..42a7368 100644 --- a/src/jp/nyatla/nyartoolkit/base/Param.java +++ b/src/jp/nyatla/nyartoolkit/base/Param.java @@ -128,7 +128,7 @@ public class Param { NyARException.trap("未チェックのパス"); NyARMat.matrixMul( mat_wm1, mat_at, mat_a );//if( arMatrixMul( mat_wm1, mat_at, mat_a ) < 0 ) { NyARException.trap("未チェックのパス"); - NyARMat.matrixSelfInv(mat_wm1 );//if( arMatrixSelfInv( mat_wm1 ) < 0 ) { + mat_wm1.matrixSelfInv();//if( arMatrixSelfInv( mat_wm1 ) < 0 ) { NyARException.trap("未チェックのパス"); NyARMat.matrixMul( mat_wm2, mat_wm1, mat_at );//if( arMatrixMul( mat_wm2, mat_wm1, mat_at ) < 0 ) { @@ -311,7 +311,7 @@ public class Param { t2_array[3][3]=1.0;//t2->m[15] = 1.0; } JartkException.trap("未チェックのパス"); - ARMat.matrixSelfInv(t1);//if( arMatrixSelfInv(t1) != 0 ) { + t1.matrixSelfInv();//if( arMatrixSelfInv(t1) != 0 ) { JartkException.trap("未チェックのパス"); t3 =ARMat.matrixAllocMul(t2, t1);//t3 = arMatrixAllocMul(t2, t1); diff --git a/src/jp/nyatla/nyartoolkit/core/NyARCode.java b/src/jp/nyatla/nyartoolkit/core/NyARCode.java index acc2596..0a947d8 100644 --- a/src/jp/nyatla/nyartoolkit/core/NyARCode.java +++ b/src/jp/nyatla/nyartoolkit/core/NyARCode.java @@ -84,7 +84,8 @@ public class NyARCode{ 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]; } - + + /** * int arLoadPatt( const char *filename ); * ARToolKitのパターンファイルをロードする。 @@ -92,11 +93,11 @@ public class NyARCode{ * @return * @throws Exception */ - public void LoadFromARFile(String filename) throws NyARException + public void loadFromARFile(String filename) throws NyARException { try{ StreamTokenizer st=new StreamTokenizer(new InputStreamReader(new FileInputStream(filename))); - //パターンデータはGBRAで並んでる。 + //パターンデータはGBRAで並んでる。 for(int h=0; h<4; h++ ) { int l = 0; for(int i3 = 0; i3 < 3; i3++ ) { diff --git a/src/jp/nyatla/nyartoolkit/core/NyARColorPatt.java b/src/jp/nyatla/nyartoolkit/core/NyARColorPatt.java index bfb749d..f2f1021 100644 --- a/src/jp/nyatla/nyartoolkit/core/NyARColorPatt.java +++ b/src/jp/nyatla/nyartoolkit/core/NyARColorPatt.java @@ -93,7 +93,7 @@ public class NyARColorPatt b_array[i*2+1][0]=vertex[i][1];//b->m[i*2+1] = vertex[i][1]; } // JartkException.trap("未チェックのパス"); - NyARMat.matrixSelfInv(a); + a.matrixSelfInv(); // JartkException.trap("未チェックのパス"); NyARMat.matrixMul( c, a, b ); diff --git a/src/jp/nyatla/nyartoolkit/core/NyARDetectMarker.java b/src/jp/nyatla/nyartoolkit/core/NyARDetectMarker.java index 2a73545..3d7370d 100644 --- a/src/jp/nyatla/nyartoolkit/core/NyARDetectMarker.java +++ b/src/jp/nyatla/nyartoolkit/core/NyARDetectMarker.java @@ -48,7 +48,8 @@ public class NyARDetectMarker { private int area_max=AR_AREA_MAX; private int area_min=AR_AREA_MIN; - private NyARMarker[] marker_info2_array; + private NyARMarker[] marker_holder; //マーカーデータの保持配列 + private NyARMarker[] marker_info2_array; //マーカーデータのインデックス配列 private int marker_num; private int width,height; /** @@ -61,15 +62,19 @@ public class NyARDetectMarker { { width =i_width; height=i_height; + marker_holder=new NyARMarker[i_squre_max]; marker_info2_array=new NyARMarker[i_squre_max]; } public int getMarkerNum() { return marker_num; } - public NyARMarker[] getMarkerArray() throws NyARException + public NyARMarker getMarker(int idx) throws NyARException { - return marker_info2_array; + if(idx>=marker_num){ + throw new NyARException(); + } + return marker_info2_array[idx]; } /** * static int get_vertex( int x_coord[], int y_coord[], int st, int ed,double thresh, int vertex[], int *vnum) @@ -214,7 +219,9 @@ public class NyARDetectMarker { } /** * int arGetContour( ARInt16 *limage, int *label_ref,int label, int clip[4], ARMarkerInfo2 *marker_info2 ) - * 関数の代替品 + * 関数の代替品 + * detectMarker関数から使う関数です。marker_holder[i_holder_num]にオブジェクトが無ければまず新規に作成し、もし + * 既に存在すればそこにマーカー情報を上書きして記録します。 * @param limage * @param label_ref * @param label @@ -223,7 +230,7 @@ public class NyARDetectMarker { * 検出したマーカーからマーカーオブジェクトを生成して返す。 * @throws NyARException */ - private NyARMarker arGetContour(short[][] limage, int[] label_ref,int label, int[] clip) throws NyARException + private NyARMarker arGetContour(int i_holder_num,short[][] limage, int[] label_ref,int label, int[] clip) throws NyARException { final int[] xdir={0, 1, 1, 1, 0,-1,-1,-1}; //static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1}; final int[] ydir={-1,-1, 0, 1, 1, 1, 0,-1};//static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1}; @@ -232,30 +239,35 @@ public class NyARDetectMarker { int dmax, d, v1=0; int i, j; -// JartkException.trap("未チェックのパス"); j = clip[2]; //p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 = &(limage[j*xsize+clip[0]]); for( i = clip[0]; i <= clip[1]; i++){//for( i = clip[0]; i <= clip[1]; i++, p1++ ) { - if(limage[j][i] > 0 && label_ref[(limage[j][i])-1] == label ) {//if( *p1 > 0 && label_ref[(*p1)-1] == label ) { - sx = i; sy = j; - break; - } + if(limage[j][i] > 0 && label_ref[(limage[j][i])-1] == label ) {//if( *p1 > 0 && label_ref[(*p1)-1] == label ) { + sx = i; sy = j; + break; + } } if(i> clip[1]){//if( i > clip[1] ) { - System.out.println("??? 1");//printf(); - throw new NyARException();//return(-1); + System.out.println("??? 1");//printf(); + throw new NyARException();//return(-1); } + + //マーカーホルダが既に確保済みかを調べる + if(marker_holder[i_holder_num]==null){ + //確保していなければ確保 + marker_holder[i_holder_num]=new NyARMarker(); + } + NyARMarker marker_ref=marker_holder[i_holder_num]; + - NyARMarker marker_info2=new NyARMarker(); - - marker_info2.coord_num=1;//marker_info2->coord_num = 1; - marker_info2.x_coord[0]=sx;//marker_info2->x_coord[0] = sx; - marker_info2.y_coord[0]=sy;//marker_info2->y_coord[0] = sy; + marker_ref.coord_num=1;//marker_info2->coord_num = 1; + marker_ref.x_coord[0]=sx;//marker_info2->x_coord[0] = sx; + marker_ref.y_coord[0]=sy;//marker_info2->y_coord[0] = sy; dir = 5; for(;;){ - int r=marker_info2.y_coord[marker_info2.coord_num-1]; - int c=marker_info2.x_coord[marker_info2.coord_num-1]; + int r=marker_ref.y_coord[marker_ref.coord_num-1]; + int c=marker_ref.x_coord[marker_ref.coord_num-1]; //p1 = &(limage[marker_info2->y_coord[marker_info2->coord_num-1] * xsize+ marker_info2->x_coord[marker_info2->coord_num-1]]); dir = (dir+5)%8; for(i=0;i<8;i++) { @@ -268,21 +280,21 @@ public class NyARDetectMarker { System.out.println("??? 2");//printf("??? 2\n"); throw new NyARException();//return(-1); } - marker_info2.x_coord[marker_info2.coord_num]= marker_info2.x_coord[marker_info2.coord_num-1] + xdir[dir];//marker_info2->x_coord[marker_info2->coord_num]= marker_info2->x_coord[marker_info2->coord_num-1] + xdir[dir]; - marker_info2.y_coord[marker_info2.coord_num]= marker_info2.y_coord[marker_info2.coord_num-1] + ydir[dir];//marker_info2->y_coord[marker_info2->coord_num]= marker_info2->y_coord[marker_info2->coord_num-1] + ydir[dir]; - if( marker_info2.x_coord[marker_info2.coord_num] == sx && marker_info2.y_coord[marker_info2.coord_num] == sy ){ + marker_ref.x_coord[marker_ref.coord_num]= marker_ref.x_coord[marker_ref.coord_num-1] + xdir[dir];//marker_info2->x_coord[marker_info2->coord_num]= marker_info2->x_coord[marker_info2->coord_num-1] + xdir[dir]; + marker_ref.y_coord[marker_ref.coord_num]= marker_ref.y_coord[marker_ref.coord_num-1] + ydir[dir];//marker_info2->y_coord[marker_info2->coord_num]= marker_info2->y_coord[marker_info2->coord_num-1] + ydir[dir]; + if( marker_ref.x_coord[marker_ref.coord_num] == sx && marker_ref.y_coord[marker_ref.coord_num] == sy ){ break; } - marker_info2.coord_num++; - if( marker_info2.coord_num == marker_info2.x_coord.length-1){//if( marker_info2.coord_num == Config.AR_CHAIN_MAX-1 ){ + marker_ref.coord_num++; + if( marker_ref.coord_num == marker_ref.x_coord.length-1){//if( marker_info2.coord_num == Config.AR_CHAIN_MAX-1 ){ System.out.println("??? 3");//printf("??? 3\n"); throw new NyARException();//return(-1); } } dmax = 0; - for(i=1;icoord_num;i++) { - d = (marker_info2.x_coord[i]-sx)*(marker_info2.x_coord[i]-sx)+ (marker_info2.y_coord[i]-sy)*(marker_info2.y_coord[i]-sy);// d = (marker_info2->x_coord[i]-sx)*(marker_info2->x_coord[i]-sx)+ (marker_info2->y_coord[i]-sy)*(marker_info2->y_coord[i]-sy); + for(i=1;icoord_num;i++) { + d = (marker_ref.x_coord[i]-sx)*(marker_ref.x_coord[i]-sx)+ (marker_ref.y_coord[i]-sy)*(marker_ref.y_coord[i]-sy);// d = (marker_info2->x_coord[i]-sx)*(marker_info2->x_coord[i]-sx)+ (marker_info2->y_coord[i]-sy)*(marker_info2->y_coord[i]-sy); if( d > dmax ) { dmax = d; v1 = i; @@ -292,33 +304,30 @@ public class NyARDetectMarker { int[] wx=new int[v1];//new int[Config.AR_CHAIN_MAX]; int[] wy=new int[v1]; //new int[Config.AR_CHAIN_MAX]; for(i=0;ix_coord[i]; - wy[i] = marker_info2.y_coord[i];//wy[i] = marker_info2->y_coord[i]; + wx[i] = marker_ref.x_coord[i];//wx[i] = marker_info2->x_coord[i]; + wy[i] = marker_ref.y_coord[i];//wy[i] = marker_info2->y_coord[i]; } - for(i=v1;icoord_num;i++) { - marker_info2.x_coord[i-v1] = marker_info2.x_coord[i];//marker_info2->x_coord[i-v1] = marker_info2->x_coord[i]; - marker_info2.y_coord[i-v1] = marker_info2.y_coord[i];//marker_info2->y_coord[i-v1] = marker_info2->y_coord[i]; + for(i=v1;icoord_num;i++) { + marker_ref.x_coord[i-v1] = marker_ref.x_coord[i];//marker_info2->x_coord[i-v1] = marker_info2->x_coord[i]; + marker_ref.y_coord[i-v1] = marker_ref.y_coord[i];//marker_info2->y_coord[i-v1] = marker_info2->y_coord[i]; } for(i=0;ix_coord[i-v1+marker_info2->coord_num] = wx[i]; - marker_info2.y_coord[i-v1+marker_info2.coord_num] = wy[i];//marker_info2->y_coord[i-v1+marker_info2->coord_num] = wy[i]; + marker_ref.x_coord[i-v1+marker_ref.coord_num] = wx[i];//marker_info2->x_coord[i-v1+marker_info2->coord_num] = wx[i]; + marker_ref.y_coord[i-v1+marker_ref.coord_num] = wy[i];//marker_info2->y_coord[i-v1+marker_info2->coord_num] = wy[i]; } - marker_info2.x_coord[marker_info2.coord_num] = marker_info2.x_coord[0];//marker_info2->x_coord[marker_info2->coord_num] = marker_info2->x_coord[0]; - marker_info2.y_coord[marker_info2.coord_num] = marker_info2.y_coord[0];//marker_info2->y_coord[marker_info2->coord_num] = marker_info2->y_coord[0]; - marker_info2.coord_num++;//marker_info2->coord_num++; + marker_ref.x_coord[marker_ref.coord_num] = marker_ref.x_coord[0];//marker_info2->x_coord[marker_info2->coord_num] = marker_info2->x_coord[0]; + marker_ref.y_coord[marker_ref.coord_num] = marker_ref.y_coord[0];//marker_info2->y_coord[marker_info2->coord_num] = marker_info2->y_coord[0]; + marker_ref.coord_num++;//marker_info2->coord_num++; - return marker_info2; + return marker_ref; } /** * ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double factor, int *marker_num ) * 関数の代替品 - * ラベリング情報からマーカー一覧を作成して、保持する。 + * ラベリング情報からマーカー一覧を作成して保持します。 + * この関数を実行すると、前回のdetectMarker関数で計算した保持値は破壊されます。 * @param i_labeling * ラベリング済みの情報を持つラベリングオブジェクト - * @param area_max - * 何かの閾値? - * @param area_min - * 何かの閾値? * @param factor * 何かの閾値? * @return @@ -329,7 +338,6 @@ public class NyARDetectMarker { { int xsize, ysize; int marker_num2; - int i, j; double d; int[] warea =i_labeling.getArea(); int label_num =i_labeling.getLabelNum(); @@ -343,7 +351,7 @@ public class NyARDetectMarker { ysize =height; marker_num2 = 0; - for(i=0; i area_max ){ continue; } @@ -354,49 +362,58 @@ public class NyARDetectMarker { continue; } //ret = arGetContour( limage, label_ref, i+1,&(wclip[i*4]), &(marker_info2[marker_num2])); - marker_info2_array[marker_num2]=arGetContour( limage, label_ref, i+1,wclip[i]); + arGetContour(marker_num2,limage, label_ref, i+1,wclip[i]); - boolean ret = check_square( warea[i], marker_info2_array[marker_num2], factor );//ret = check_square( warea[i], &(marker_info2[marker_num2]), factor ); + boolean ret = check_square( warea[i], marker_holder[marker_num2], factor );//ret = check_square( warea[i], &(marker_info2[marker_num2]), factor ); if(!ret){ - marker_info2_array[marker_num2]=null; + //後半で整理するからここはいらない。// marker_holder[marker_num2]=null; continue; } - marker_info2_array[marker_num2].area = warea[i]; - marker_info2_array[marker_num2].pos[0] = wpos[i*2+0]; - marker_info2_array[marker_num2].pos[1] = wpos[i*2+1]; + marker_holder[marker_num2].area = warea[i]; + marker_holder[marker_num2].pos[0] = wpos[i*2+0]; + marker_holder[marker_num2].pos[1] = wpos[i*2+1]; marker_num2++; //マーカーリストが上限に達した - if( marker_num2 == marker_info2_array.length){ + if( marker_num2 == marker_holder.length){ break; } } - for( i=0; i < marker_num2; i++ ) { - for( j=i+1; j < marker_num2; j++ ) { - d = (marker_info2_array[i].pos[0] - marker_info2_array[j].pos[0])* - (marker_info2_array[i].pos[0] - marker_info2_array[j].pos[0])+ - (marker_info2_array[i].pos[1] - marker_info2_array[j].pos[1])* - (marker_info2_array[i].pos[1] - marker_info2_array[j].pos[1]); - if(marker_info2_array[i].area >marker_info2_array[j].area ) { - if( d marker_holder[j].area ) { + if( d m[j*2+0]), &(input->m[j*2+1]) ); - in_array[j][0]=dv1.get(); - in_array[j][1]=dv2.get(); + in_array[j][0]=dv1.value; + in_array[j][1]=dv2.value; } NyARMat.matrixPCA(input, evec, ev, mean); diff --git a/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java b/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java index d649977..5c8f048 100644 --- a/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java +++ b/src/jp/nyatla/nyartoolkit/core/NyARLabeling.java @@ -75,7 +75,7 @@ public class NyARLabeling{ return label_num; } /** - * わからん + * * @return * @throws NyARException */ @@ -87,7 +87,7 @@ public class NyARLabeling{ return work; } /** - * 検出したエリア配列?よくわからぬ + * 検出したエリア配列? * @return * @throws NyARException */ @@ -99,7 +99,7 @@ public class NyARLabeling{ return area; } /** - * 検出したクリップ配列?よくわからぬ + * 検出したクリップ配列? * @return * @throws NyARException */ @@ -111,7 +111,7 @@ public class NyARLabeling{ return clip; } /** - * 検出した位置配列?よくわからぬ + * 検出した位置配列? * @return * @throws NyARException */ diff --git a/src/jp/nyatla/nyartoolkit/core/NyARMat.java b/src/jp/nyatla/nyartoolkit/core/NyARMat.java index 223637e..8a3819c 100644 --- a/src/jp/nyatla/nyartoolkit/core/NyARMat.java +++ b/src/jp/nyatla/nyartoolkit/core/NyARMat.java @@ -105,19 +105,20 @@ public class NyARMat{ } } } + private int[] wk_nos_matrixSelfInv=new int[50]; /** * i_targetを逆行列に変換する。arMatrixSelfInv()と、arMatrixSelfInv_minv()関数を合成してあります。 * @param i_target * 逆行列にする行列 * @throws NyARException */ - public static void matrixSelfInv(NyARMat i_target) throws NyARException + public void matrixSelfInv() throws NyARException { - double[][] ap=i_target.m; + double[][] ap=m; int dimen=ap.length; double[] wcp,wap,wbp; - int i,j,ip,nwork; - int[] nos=new int[50]; + int j,ip,nwork; + int[] nos=wk_nos_matrixSelfInv;//この関数で初期化される。 double epsl; double p,pbuf,work; @@ -146,7 +147,7 @@ public class NyARMat{ wcp =ap[n];//wcp = ap + n * rowa; p=0.0; wap_ptr=0;//wap = DoublePointer.wrap(wcp); - for(i = n; im[0]; @@ -226,7 +242,7 @@ public class NyARTransMat{ // JartkException.trap("未チェックのパス");{ NyARMat.matrixMul( mat_d, mat_b, mat_a ); NyARMat.matrixMul( mat_e, mat_b, mat_c ); - NyARMat.matrixSelfInv(mat_d); + mat_d.matrixSelfInv(); NyARMat.matrixMul( mat_f, mat_d, mat_e ); // } trans[0] = f_array[0][0];//trans[0] = mat_f->m[0]; @@ -258,9 +274,9 @@ public class NyARTransMat{ int i, j; arGetAngle( rot, a, b, c);//arGetAngle( rot, &a, &b, &c ); - a2 = a.get(); - b2 = b.get(); - c2 = c.get(); + a2 = a.value; + b2 = b.value; + c2 = c.value; factor = 10.0*Math.PI/180.0; for( j = 0; j < 10; j++ ) { minerr = 1000000000.0; @@ -303,37 +319,64 @@ public class NyARTransMat{ /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */ return minerr/num; } + private double[][] wk_cpara2_arGetNewMatrix=new double[3][4]; + private double[][] wk_rot_arGetNewMatrix =new double[3][3]; + /** + * + * @param a + * @param b + * @param c + * @param trans + * @param trans2 + * @param ret + * @return + */ private int arGetNewMatrix( double a, double b, double c,double trans[], double trans2[][], double ret[][] ) { double cpara[][]=param.getMat(); - double[][] cpara2=new double[3][4]; - double[][] rot=new double[3][3]; + double[][] cpara2=wk_cpara2_arGetNewMatrix; //この関数で初期化される。 + double[][] rot =wk_rot_arGetNewMatrix; //arGetRotで初期化される。 int i, j; arGetRot( a, b, c, rot ); if( trans2 != null ) { for( j = 0; j < 3; j++ ) { - for( i = 0; i < 4; i++ ) { - cpara2[j][i] = cpara[j][0] * trans2[0][i]+ cpara[j][1] * trans2[1][i]+ cpara[j][2] * trans2[2][i]; - } +// for( i = 0; i < 4; i++ ) { +// cpara2[j][i] = cpara[j][0] * trans2[0][i]+ cpara[j][1] * trans2[1][i]+ cpara[j][2] * trans2[2][i]; +// } +//Optimize + cpara2[j][0] = cpara[j][0] * trans2[0][0]+ cpara[j][1] * trans2[1][0]+ cpara[j][2] * trans2[2][0]; + cpara2[j][1] = cpara[j][0] * trans2[0][1]+ cpara[j][1] * trans2[1][1]+ cpara[j][2] * trans2[2][1]; + cpara2[j][2] = cpara[j][0] * trans2[0][2]+ cpara[j][1] * trans2[1][2]+ cpara[j][2] * trans2[2][2]; + cpara2[j][3] = cpara[j][0] * trans2[0][3]+ cpara[j][1] * trans2[1][3]+ cpara[j][2] * trans2[2][3]; } - }else{ + }else{ for( j = 0; j < 3; j++ ) { - for( i = 0; i < 4; i++ ) { - cpara2[j][i] = cpara[j][i]; - } +// for( i = 0; i < 4; i++ ) { +// cpara2[j][i] = cpara[j][i]; +// } +//Optimize + cpara2[j][0] = cpara[j][0]; + cpara2[j][1] = cpara[j][1]; + cpara2[j][2] = cpara[j][2]; + cpara2[j][3] = cpara[j][3]; } - } + } for( j = 0; j < 3; j++ ) { - for( i = 0; i < 3; i++ ) { - ret[j][i] = cpara2[j][0] * rot[0][i]+ cpara2[j][1] * rot[1][i]+ cpara2[j][2] * rot[2][i]; - } +// for( i = 0; i < 3; i++ ) { +// ret[j][i] = cpara2[j][0] * rot[0][i]+ cpara2[j][1] * rot[1][i]+ cpara2[j][2] * rot[2][i]; +// } +//Optimize + ret[j][0] = cpara2[j][0] * rot[0][0]+ cpara2[j][1] * rot[1][0]+ cpara2[j][2] * rot[2][0]; + ret[j][1] = cpara2[j][0] * rot[0][1]+ cpara2[j][1] * rot[1][1]+ cpara2[j][2] * rot[2][1]; + ret[j][2] = cpara2[j][0] * rot[0][2]+ cpara2[j][1] * rot[1][2]+ cpara2[j][2] * rot[2][2]; +// ret[j][3] = cpara2[j][0] * trans[0]+ cpara2[j][1] * trans[1]+ cpara2[j][2] * trans[2]+ cpara2[j][3]; } return(0); } - private int arGetRot( double a, double b, double c, double rot[][] ) + private void arGetRot( double a, double b, double c, double rot[][] ) { double sina, sinb, sinc; double cosa, cosb, cosc; @@ -344,6 +387,27 @@ public class NyARTransMat{ cosb = Math.cos(b); sinc = Math.sin(c); cosc = Math.cos(c); + //Optimize + double A,B,C,D,E,F,G; + A=sina*cosa; + B=sina*sina; + C=cosa*cosa; + D=cosa*sinb; + F=cosb*cosc; + E=cosb*sinc; + G=sina*sinb; + + rot[0][0] = C*F + B*cosc + A*(E - sinc); + rot[0][1] = -C*E-B*sinc+A*(F-cosc); + rot[0][2] = D; + rot[1][0] = A*(F-cosc)+B*E+C*sinc; + rot[1][1] = A*(-E+sinc)+B*F+C*cosc; + rot[1][2] = G; + rot[2][0] = -D*cosc-G*sinc; + rot[2][1] = D*sinc-G*cosc; + rot[2][2] = cosb; + /* + //49回 rot[0][0] = cosa*cosa*cosb*cosc+sina*sina*cosc+sina*cosa*cosb*sinc-sina*cosa*sinc; rot[0][1] = -cosa*cosa*cosb*sinc-sina*sina*sinc+sina*cosa*cosb*cosc-sina*cosa*cosc; rot[0][2] = cosa*sinb; @@ -353,8 +417,7 @@ public class NyARTransMat{ rot[2][0] = -cosa*sinb*cosc-sina*sinb*sinc; rot[2][1] = cosa*sinb*sinc-sina*sinb*cosc; rot[2][2] = cosb; - - return 0; +*/ } /*int arGetAngle( double rot[3][3], double *wa, double *wb, double *wc )*/ private int arGetAngle( double rot[][], DoubleValue wa, DoubleValue wb, DoubleValue wc ) @@ -462,9 +525,9 @@ public class NyARTransMat{ if( sinc < 0 ) c = -c; } - wa.set(a);//*wa = a; - wb.set(b);//*wb = b; - wc.set(c);//*wc = c; + wa.value=a;//*wa = a; + wb.value=b;//*wb = b; + wc.value=c;//*wc = c; return 0; } @@ -537,52 +600,52 @@ public class NyARTransMat{ } /*static int check_dir( double dir[3], double st[2], double ed[2],double cpara[3][4] )*/ - private static int check_dir( double dir[], double st[], double ed[],double cpara[][]) throws NyARException - { - - double[][] world=new double[2][3]; - double[][] camera=new double[2][2]; - double[][] v=new double[2][2]; - double h; - int i, j; - // JartkException.trap("未チェックパス"); - NyARMat mat_a = new NyARMat( 3, 3 ); - double[][] a_array=mat_a.getArray(); - for(j=0;j<3;j++){ - for(i=0;i<3;i++){ - a_array[j][i]=cpara[j][i];//m[j*3+i] = cpara[j][i]; - } - } - // JartkException.trap("未チェックのパス"); - NyARMat.matrixSelfInv(mat_a); - world[0][0] = a_array[0][0]*st[0]*10.0+ a_array[0][1]*st[1]*10.0+ a_array[0][2]*10.0;//mat_a->m[0]*st[0]*10.0+ mat_a->m[1]*st[1]*10.0+ mat_a->m[2]*10.0; - world[0][1] = a_array[1][0]*st[0]*10.0+ a_array[1][1]*st[1]*10.0+ a_array[1][2]*10.0;//mat_a->m[3]*st[0]*10.0+ mat_a->m[4]*st[1]*10.0+ mat_a->m[5]*10.0; - world[0][2] = a_array[2][0]*st[0]*10.0+ a_array[2][1]*st[1]*10.0+ a_array[2][2]*10.0;//mat_a->m[6]*st[0]*10.0+ mat_a->m[7]*st[1]*10.0+ mat_a->m[8]*10.0; - world[1][0] = world[0][0] + dir[0]; - world[1][1] = world[0][1] + dir[1]; - world[1][2] = world[0][2] + dir[2]; - - for( i = 0; i < 2; i++ ) { - h = cpara[2][0] * world[i][0]+ cpara[2][1] * world[i][1]+ cpara[2][2] * world[i][2]; - if( h == 0.0 ){ - return -1; - } - camera[i][0] = (cpara[0][0] * world[i][0]+ cpara[0][1] * world[i][1]+ cpara[0][2] * world[i][2]) / h; - camera[i][1] = (cpara[1][0] * world[i][0]+ cpara[1][1] * world[i][1]+ cpara[1][2] * world[i][2]) / h; - } + private static int check_dir( double dir[], double st[], double ed[],double cpara[][]) throws NyARException + { - v[0][0] = ed[0] - st[0]; - v[0][1] = ed[1] - st[1]; - v[1][0] = camera[1][0] - camera[0][0]; - v[1][1] = camera[1][1] - camera[0][1]; + double[][] world=new double[2][3]; + double[][] camera=new double[2][2]; + double[][] v=new double[2][2]; + double h; + int i, j; + // JartkException.trap("未チェックパス"); + NyARMat mat_a = new NyARMat( 3, 3 ); + double[][] a_array=mat_a.getArray(); + for(j=0;j<3;j++){ + for(i=0;i<3;i++){ + a_array[j][i]=cpara[j][i];//m[j*3+i] = cpara[j][i]; + } + } + // JartkException.trap("未チェックのパス"); + mat_a.matrixSelfInv(); + world[0][0] = a_array[0][0]*st[0]*10.0+ a_array[0][1]*st[1]*10.0+ a_array[0][2]*10.0;//mat_a->m[0]*st[0]*10.0+ mat_a->m[1]*st[1]*10.0+ mat_a->m[2]*10.0; + world[0][1] = a_array[1][0]*st[0]*10.0+ a_array[1][1]*st[1]*10.0+ a_array[1][2]*10.0;//mat_a->m[3]*st[0]*10.0+ mat_a->m[4]*st[1]*10.0+ mat_a->m[5]*10.0; + world[0][2] = a_array[2][0]*st[0]*10.0+ a_array[2][1]*st[1]*10.0+ a_array[2][2]*10.0;//mat_a->m[6]*st[0]*10.0+ mat_a->m[7]*st[1]*10.0+ mat_a->m[8]*10.0; + world[1][0] = world[0][0] + dir[0]; + world[1][1] = world[0][1] + dir[1]; + world[1][2] = world[0][2] + dir[2]; - if( v[0][0]*v[1][0] + v[0][1]*v[1][1] < 0 ) { - dir[0] = -dir[0]; - dir[1] = -dir[1]; - dir[2] = -dir[2]; - } - return 0; - } + for( i = 0; i < 2; i++ ) { + h = cpara[2][0] * world[i][0]+ cpara[2][1] * world[i][1]+ cpara[2][2] * world[i][2]; + if( h == 0.0 ){ + return -1; + } + camera[i][0] = (cpara[0][0] * world[i][0]+ cpara[0][1] * world[i][1]+ cpara[0][2] * world[i][2]) / h; + camera[i][1] = (cpara[1][0] * world[i][0]+ cpara[1][1] * world[i][1]+ cpara[1][2] * world[i][2]) / h; + } + + v[0][0] = ed[0] - st[0]; + v[0][1] = ed[1] - st[1]; + v[1][0] = camera[1][0] - camera[0][0]; + v[1][1] = camera[1][1] - camera[0][1]; + + if( v[0][0]*v[1][0] + v[0][1]*v[1][1] < 0 ) { + dir[0] = -dir[0]; + dir[1] = -dir[1]; + dir[2] = -dir[2]; + } + return 0; + } /*int check_rotation( double rot[2][3] )*/ private static int check_rotation( double rot[][] ) diff --git a/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java b/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java index 93104e0..23fe38a 100644 --- a/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java +++ b/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java @@ -50,6 +50,7 @@ public class NyARSingleDetectMarker{ private int detected_direction; private double detected_confidence; private NyARSquare detected_square; + private NyARColorPatt patt; public NyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width) { param=i_param; @@ -59,7 +60,8 @@ public class NyARSingleDetectMarker{ //比較コードを保存 code=i_code; marker_width=i_marker_width; - + //評価パターンのホルダを作る + patt=new NyARColorPatt(code.getWidth(),code.getHeight()); } /** @@ -83,8 +85,6 @@ public class NyARSingleDetectMarker{ //コードの一致度を調べる準備 NyARSquare[] squares=square.getSquareArray(); - //パターンホルダを作る - NyARColorPatt patt=new NyARColorPatt(code.getWidth(),code.getHeight()); //評価基準になるパターンをイメージから切り出す patt.pickFromRaster(i_image,squares[0].getMarker()); diff --git a/src/jp/nyatla/nyartoolkit/sample/RawFileTest.java b/src/jp/nyatla/nyartoolkit/sample/RawFileTest.java index d251e11..d1b84f3 100644 --- a/src/jp/nyatla/nyartoolkit/sample/RawFileTest.java +++ b/src/jp/nyatla/nyartoolkit/sample/RawFileTest.java @@ -57,7 +57,7 @@ public class RawFileTest { //AR用のパターンコードを読み出し NyARCode code=new NyARCode(16,16); - code.LoadFromARFile(code_file); + code.loadFromARFile(code_file); //試験イメージの読み出し(320x240 BGRAのRAWデータ) File f=new File(data_file); diff --git a/src/jp/nyatla/util/DoubleValue.java b/src/jp/nyatla/util/DoubleValue.java index 83a26f1..a42bd14 100644 --- a/src/jp/nyatla/util/DoubleValue.java +++ b/src/jp/nyatla/util/DoubleValue.java @@ -1,14 +1,5 @@ package jp.nyatla.util; public class DoubleValue { - private double v; - public void set(double i_v){ - v=i_v; - } - public double get(){ - return v; - } - public void add(double i_v){ - v+=i_v; - } + public double value; } \ No newline at end of file