From: nyatla Date: Sun, 28 Dec 2008 06:41:24 +0000 (+0000) Subject: [更新]NyARToolkit X-Git-Tag: 2.2.0~4 X-Git-Url: http://git.osdn.net/view?p=nyartoolkit-and%2Fnyartoolkit-and.git;a=commitdiff_plain;h=3a9a1dc5d674ac09fab84327dfa7a424c8156a81 [更新]NyARToolkit ・NyARLabeling NyARLabelingImage ラべリングラスタの1次元並列化 ・NyARLabelingImage NyARParamにセット関数追加 ・SingleMarkerDetectorのカスタムクラス追加 ・JmfCaptureの再構築&デバイスリスト化 ・JmfCapture関連のコード切り替え ・その他雑多な修正 --- diff --git a/sample/java3d/.classpath b/sample/java3d/.classpath index c862de1..0a27af9 100644 --- a/sample/java3d/.classpath +++ b/sample/java3d/.classpath @@ -2,7 +2,7 @@ - + diff --git a/sample/java3d/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java b/sample/java3d/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java index a1786c2..9abde51 100644 --- a/sample/java3d/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java +++ b/sample/java3d/jp/nyatla/nyartoolkit/java3d/sample/NyARJava3D.java @@ -47,6 +47,8 @@ import com.sun.j3d.utils.geometry.ColorCube; */ public class NyARJava3D extends JFrame implements NyARSingleMarkerBehaviorListener { + private static final long serialVersionUID = -8472866262481865377L; + private final String CARCODE_FILE = "../../Data/patt.hiro"; private final String PARAM_FILE = "../../Data/camera_para.dat"; diff --git a/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java b/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java index 6a1984a..f19612f 100644 --- a/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java +++ b/sample/jmf/jp/nyatla/nyartoolkit/jmf/sample/NyarToolkitLinkTest.java @@ -47,42 +47,47 @@ import jp.nyatla.nyartoolkit.detector.NyARSingleDetectMarker; */ public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener { + private static final long serialVersionUID = 6471434231970804953L; + private final String CARCODE_FILE = "../../Data/patt.hiro"; private final String PARAM_FILE = "../../Data/camera_para.dat"; - private JmfCameraCapture capture; + private JmfCaptureDevice _capture; - private NyARSingleDetectMarker nya; + private NyARSingleDetectMarker _nya; - private JmfNyARRaster_RGB raster; + private JmfNyARRaster_RGB _raster; - private NyARTransMatResult trans_mat_result = new NyARTransMatResult(); + private NyARTransMatResult _trans_mat_result = new NyARTransMatResult(); public NyarToolkitLinkTest() throws NyARException, NyARException { setTitle("JmfCaptureTest"); setBounds(0, 0, 320 + 64, 240 + 64); //キャプチャの準備 - capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB); - capture.setCaptureListener(this); + JmfCaptureDeviceList devlist=new JmfCaptureDeviceList(); + _capture=devlist.getDevice(0); + _capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,320, 240,15f); + _capture.setOnCapture(this); //NyARToolkitの準備 NyARParam ar_param = new NyARParam(); NyARCode ar_code = new NyARCode(16, 16); ar_param.loadARParamFromFile(PARAM_FILE); ar_param.changeScreenSize(320, 240); - nya = new NyARSingleDetectMarker(ar_param, ar_code, 80.0); + this._nya = new NyARSingleDetectMarker(ar_param, ar_code, 80.0); ar_code.loadARPattFromFile(CARCODE_FILE); //キャプチャイメージ用のラスタを準備 - raster = new JmfNyARRaster_RGB(320, 240); + this._raster = new JmfNyARRaster_RGB(320, 240); + return; } public void onUpdateBuffer(Buffer i_buffer) { try { //キャプチャしたバッファをラスタにセット - raster.setBuffer(i_buffer); + this._raster.setBuffer(i_buffer); //キャプチャしたイメージを表示用に加工 BufferToImage b2i = new BufferToImage((VideoFormat) i_buffer.getFormat()); @@ -91,27 +96,27 @@ public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener Graphics g = getGraphics(); //マーカー検出 - boolean is_marker_exist = nya.detectMarkerLite(raster, 100); + boolean is_marker_exist = this._nya.detectMarkerLite(this._raster, 100); if (is_marker_exist) { //変換行列を取得 - nya.getTransmationMatrix(this.trans_mat_result); + this._nya.getTransmationMatrix(this._trans_mat_result); } //情報を画面に書く g.drawImage(img, 32, 32, this); if (is_marker_exist) { - g.drawString("マーカー検出:" + nya.getConfidence(), 32, 50); - g.drawString("[m00]" +this.trans_mat_result.m00, 32, 50 + 16*1); - g.drawString("[m01]" +this.trans_mat_result.m01, 32, 50 + 16*2); - g.drawString("[m02]" +this.trans_mat_result.m02, 32, 50 + 16*3); - g.drawString("[m03]" +this.trans_mat_result.m03, 32, 50 + 16*4); - g.drawString("[m10]" +this.trans_mat_result.m10, 32, 50 + 16*5); - g.drawString("[m11]" +this.trans_mat_result.m11, 32, 50 + 16*6); - g.drawString("[m12]" +this.trans_mat_result.m12, 32, 50 + 16*7); - g.drawString("[m13]" +this.trans_mat_result.m13, 32, 50 + 16*8); - g.drawString("[m20]" +this.trans_mat_result.m20, 32, 50 + 16*9); - g.drawString("[m21]" +this.trans_mat_result.m21, 32, 50 + 16*10); - g.drawString("[m22]" +this.trans_mat_result.m22, 32, 50 + 16*11); - g.drawString("[m23]" +this.trans_mat_result.m23, 32, 50 + 16*12); + g.drawString("マーカー検出:" + this._nya.getConfidence(), 32, 50); + g.drawString("[m00]" +this._trans_mat_result.m00, 32, 50 + 16*1); + g.drawString("[m01]" +this._trans_mat_result.m01, 32, 50 + 16*2); + g.drawString("[m02]" +this._trans_mat_result.m02, 32, 50 + 16*3); + g.drawString("[m03]" +this._trans_mat_result.m03, 32, 50 + 16*4); + g.drawString("[m10]" +this._trans_mat_result.m10, 32, 50 + 16*5); + g.drawString("[m11]" +this._trans_mat_result.m11, 32, 50 + 16*6); + g.drawString("[m12]" +this._trans_mat_result.m12, 32, 50 + 16*7); + g.drawString("[m13]" +this._trans_mat_result.m13, 32, 50 + 16*8); + g.drawString("[m20]" +this._trans_mat_result.m20, 32, 50 + 16*9); + g.drawString("[m21]" +this._trans_mat_result.m21, 32, 50 + 16*10); + g.drawString("[m22]" +this._trans_mat_result.m22, 32, 50 + 16*11); + g.drawString("[m23]" +this._trans_mat_result.m23, 32, 50 + 16*12); } else { g.drawString("マーカー未検出:", 32, 100); } @@ -124,7 +129,7 @@ public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener private void startCapture() { try { - capture.start(); + this._capture.start(); } catch (Exception e) { e.printStackTrace(); } diff --git a/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java b/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java index c56c5f7..e171113 100644 --- a/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java +++ b/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite.java @@ -57,7 +57,7 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener private GLNyARRaster_RGB _cap_image; - private JmfCameraCapture _capture; + private JmfCaptureDevice _capture; private GL _gl; private NyARGLUtil _glnya; @@ -140,8 +140,10 @@ public class JavaSimpleLite implements GLEventListener, JmfCaptureListener //NyARToolkitの準備 try { //キャプチャの準備 - _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB); - _capture.setCaptureListener(this); + JmfCaptureDeviceList devlist=new JmfCaptureDeviceList(); + _capture=devlist.getDevice(0); + _capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,SCREEN_X, SCREEN_Y,15f); + _capture.setOnCapture(this); //NyARToolkitの準備 _ar_param = new NyARParam(); NyARCode ar_code = new NyARCode(16, 16); diff --git a/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java b/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java index 9f65915..19ce1e3 100644 --- a/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java +++ b/sample/jogl/jp/nyatla/nyartoolkit/jogl/sample/JavaSimpleLite2.java @@ -59,7 +59,7 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener private GLNyARRaster_RGB _cap_image; - private JmfCameraCapture _capture; + private JmfCaptureDevice _capture; private GL _gl; @@ -142,8 +142,10 @@ public class JavaSimpleLite2 implements GLEventListener, JmfCaptureListener //NyARToolkitの準備 try { //キャプチャの準備 - _capture = new JmfCameraCapture(SCREEN_X, SCREEN_Y, 15f, JmfCameraCapture.PIXEL_FORMAT_RGB); - _capture.setCaptureListener(this); + JmfCaptureDeviceList devlist=new JmfCaptureDeviceList(); + _capture=devlist.getDevice(0); + _capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,SCREEN_X, SCREEN_Y,15f); + _capture.setOnCapture(this); //NyARToolkitの準備 _ar_param = new NyARParam(); _ar_param.loadARParamFromFile(PARAM_FILE); diff --git a/sample/qt/jp/nyatla/nyartoolkit/qt/sample/NyarToolkitLinkTest.java b/sample/qt/jp/nyatla/nyartoolkit/qt/sample/NyarToolkitLinkTest.java index 79489c5..83d95c5 100644 --- a/sample/qt/jp/nyatla/nyartoolkit/qt/sample/NyarToolkitLinkTest.java +++ b/sample/qt/jp/nyatla/nyartoolkit/qt/sample/NyarToolkitLinkTest.java @@ -41,6 +41,8 @@ import jp.nyatla.nyartoolkit.detector.NyARSingleDetectMarker; */ public class NyarToolkitLinkTest extends Frame implements QtCaptureListener { + private static final long serialVersionUID = 6154831884117789648L; + private final String CARCODE_FILE = "../../Data/patt.hiro"; private final String PARAM_FILE = "../../Data/camera_para.dat"; diff --git a/sample/qt/jp/nyatla/nyartoolkit/qt/sample/QtCaptureTest.java b/sample/qt/jp/nyatla/nyartoolkit/qt/sample/QtCaptureTest.java index 4631c23..6deac55 100644 --- a/sample/qt/jp/nyatla/nyartoolkit/qt/sample/QtCaptureTest.java +++ b/sample/qt/jp/nyatla/nyartoolkit/qt/sample/QtCaptureTest.java @@ -36,6 +36,8 @@ import java.awt.*; */ public class QtCaptureTest extends Frame implements QtCaptureListener { + private static final long serialVersionUID = -734697739607654631L; + public QtCaptureTest() throws NyARException { setTitle("QtCaptureTest"); diff --git a/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARRasterFilter_QrAreaAverage.java b/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARRasterFilter_QrAreaAverage.java index 7e96ffb..629b8f5 100644 --- a/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARRasterFilter_QrAreaAverage.java +++ b/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/qrcode/NyARRasterFilter_QrAreaAverage.java @@ -47,8 +47,8 @@ public class NyARRasterFilter_QrAreaAverage implements INyARRasterFilter_GsToBin public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException { final NyARIntSize size = i_output.getSize(); - final int[][] out_buf = (int[][]) i_output.getBufferReader().getBuffer(); - final int[][] in_buf = (int[][]) i_input.getBufferReader().getBuffer(); + final int[] out_buf = (int[]) i_output.getBufferReader().getBuffer(); + final int[] in_buf = (int[]) i_input.getBufferReader().getBuffer(); assert (i_input.getSize().isEqualSize(i_output.getSize()) == true); assert (size.h % 8 == 0 && size.w % 8 == 0);//暫定実装なので。 @@ -63,7 +63,7 @@ public class NyARRasterFilter_QrAreaAverage implements INyARRasterFilter_GsToBin sum = nn = 0; for (int yy = y - area; yy < y + area + 1; yy++) { for (int xx = x1 - area; xx < x1 + area; xx++) { - sum += in_buf[yy][xx]; + sum += in_buf[yy*size.w+xx]; nn++; } } @@ -73,14 +73,14 @@ public class NyARRasterFilter_QrAreaAverage implements INyARRasterFilter_GsToBin for (int x = area; x < x2; x++) { if (!first) { for (int yy = y - area; yy < y + area; yy++) { - sum += in_buf[yy][x + area]; - sum -= in_buf[yy][x - area]; + sum += in_buf[yy*size.w+x + area]; + sum -= in_buf[yy*size.w+x - area]; } } first = false; th = (sum / nn); - int g = in_buf[y][x]; - out_buf[y][x] = th < g ? 1 : 0; + int g = in_buf[y*size.w+x]; + out_buf[y*size.w+x] = th < g ? 1 : 0; } } return; diff --git a/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARRasterFilter_ARTTh_Quad.java b/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARRasterFilter_ARTTh_Quad.java index adb5090..ce312cb 100644 --- a/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARRasterFilter_ARTTh_Quad.java +++ b/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/quadx2/NyARRasterFilter_ARTTh_Quad.java @@ -62,11 +62,11 @@ public class NyARRasterFilter_ARTTh_Quad implements INyARRasterFilter_RgbToBin int in_buf_type=in_buffer_reader.getBufferType(); NyARIntSize size = i_output.getSize(); - assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8)); + assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8)); assert (checkInputType(in_buf_type)==true); assert (i_input.getSize().isEqualSize(size.w*2,size.h*2) == true); - int[][] out_buf = (int[][]) out_buffer_reader.getBuffer(); + int[] out_buf = (int[]) out_buffer_reader.getBuffer(); byte[] in_buf = (byte[]) in_buffer_reader.getBuffer(); switch (in_buffer_reader.getBufferType()) { @@ -83,7 +83,7 @@ public class NyARRasterFilter_ARTTh_Quad implements INyARRasterFilter_RgbToBin return; } - private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size) + private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size) { final int size_w=i_size.w*2; final int x_mod_end= size_w-(size_w%8); @@ -93,37 +93,37 @@ public class NyARRasterFilter_ARTTh_Quad implements INyARRasterFilter_RgbToBin int x; for (int y =i_size.h-1; y>=0 ; y--){ //端数分 - final int[] row_ptr=i_out[y]; + final int row_ptr=y*i_size.w; for (x = i_size.w-1;x>=x_mod_end;x--) { w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x]=w<=th?0:1; + i_out[row_ptr+x]=w<=th?0:1; bp -= 6; } //タイリング for (;x>=0;x-=8) { w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x]=w<=th?0:1; + i_out[row_ptr+x]=w<=th?0:1; bp -= 6; w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-1]=w<=th?0:1; + i_out[row_ptr+x-1]=w<=th?0:1; bp -= 6; w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-2]=w<=th?0:1; + i_out[row_ptr+x-2]=w<=th?0:1; bp -= 6; w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-3]=w<=th?0:1; + i_out[row_ptr+x-3]=w<=th?0:1; bp -= 6; w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-4]=w<=th?0:1; + i_out[row_ptr+x-4]=w<=th?0:1; bp -= 6; w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-5]=w<=th?0:1; + i_out[row_ptr+x-5]=w<=th?0:1; bp -= 6; w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-6]=w<=th?0:1; + i_out[row_ptr+x-6]=w<=th?0:1; bp -= 6; w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-7]=w<=th?0:1; + i_out[row_ptr+x-7]=w<=th?0:1; bp -= 6; } //1行飛ばし @@ -131,7 +131,7 @@ public class NyARRasterFilter_ARTTh_Quad implements INyARRasterFilter_RgbToBin } return; } - private void convert32BitRgbx(byte[] i_in, int[][] i_out, NyARIntSize i_size) + private void convert32BitRgbx(byte[] i_in, int[] i_out, NyARIntSize i_size) { final int size_w=i_size.w; final int x_mod_end= size_w-(size_w%8); @@ -140,39 +140,39 @@ public class NyARRasterFilter_ARTTh_Quad implements INyARRasterFilter_RgbToBin int w; int x; for (int y =i_size.h-1; y>=0 ; y--){ - final int[] row_ptr=i_out[y]; + final int row_ptr=y*i_size.w; //端数分 for (x = size_w-1;x>=x_mod_end;x--) { w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x]=w<=th?0:1; + i_out[row_ptr+x]=w<=th?0:1; bp -= 4; } //タイリング for (;x>=0;x-=8) { w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x]=w<=th?0:1; + i_out[row_ptr+x]=w<=th?0:1; bp -= 4; w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-1]=w<=th?0:1; + i_out[row_ptr+x-1]=w<=th?0:1; bp -= 4; w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-2]=w<=th?0:1; + i_out[row_ptr+x-2]=w<=th?0:1; bp -= 4; w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-3]=w<=th?0:1; + i_out[row_ptr+x-3]=w<=th?0:1; bp -= 4; w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-4]=w<=th?0:1; + i_out[row_ptr+x-4]=w<=th?0:1; bp -= 4; w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-5]=w<=th?0:1; + i_out[row_ptr+x-5]=w<=th?0:1; bp -= 4; w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-6]=w<=th?0:1; + i_out[row_ptr+x-6]=w<=th?0:1; bp -= 4; w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-7]=w<=th?0:1; + i_out[row_ptr+x-7]=w<=th?0:1; bp -= 4; } } diff --git a/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java b/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java index f5fb7c3..42afd75 100644 --- a/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java +++ b/sample/sandbox/jp/nyatla/nyartoolkit/sandbox/x2/NyARLabeling_ARToolKit_X2.java @@ -59,18 +59,20 @@ public class NyARLabeling_ARToolKit_X2 implements INyARLabeling this._out_image = i_destination_image; // NyLabelingImageのイメージ初期化(枠書き) - int[][] img = (int[][]) i_destination_image.getBufferReader().getBuffer(); + int[] img = (int[])i_destination_image.getBufferReader().getBuffer(); + int bottom_ptr=(size.h - 1)*size.w; for (int i = 0; i < size.w; i++) { - img[0][i] = 0; - img[size.h - 1][i] = 0; + img[i] = 0; + img[bottom_ptr+i] = 0; } for (int i = 0; i < size.h; i++) { - img[i][0] = 0; - img[i][size.w - 1] = 0; + img[i*size.w] = 0; + img[(i+1)*size.w - 1] = 0; } // サイズ(参照値)を保存 this._dest_size = size; + return; } public INyARLabelingImage getAttachedDestination() @@ -97,43 +99,43 @@ public class NyARLabeling_ARToolKit_X2 implements INyARLabeling final int lxsize = in_size.w;// lxsize = arUtil_c.arImXsize; final int lysize = in_size.h;// lysize = arUtil_c.arImYsize; - int[][] label_img = (int[][]) out_image.getBufferReader().getBuffer(); + int[] label_img = (int[])out_image.getBufferReader().getBuffer(); // 枠作成はインスタンスを作った直後にやってしまう。 - - // ラベリング情報のリセット(ラベリングインデックスを使用) + + //ラベリング情報のリセット(ラベリングインデックスを使用) out_image.reset(true); - - int[] label_idxtbl = out_image.getIndexArray(); + + int[] label_idxtbl=out_image.getIndexArray(); int[] work2_pt; int wk_max = 0; int label_pixel; - int[][] raster_buf = (int[][]) i_raster.getBufferReader().getBuffer(); - int[] line_ptr; + int[] raster_buf=(int[])i_raster.getBufferReader().getBuffer(); + int line_ptr; int[][] work2 = this.work_holder.work2; - int[] label_img_pt0, label_img_pt1; + int label_img_ptr0, label_img_ptr1; for (j = 1; j < lysize - 1; j++) {// for (int j = 1; j < lysize - 1;j++, pnt += poff*2, pnt2 += 2) { - line_ptr = raster_buf[j]; - label_img_pt0 = label_img[j]; - label_img_pt1 = label_img[j - 1]; + line_ptr=j*lxsize; + label_img_ptr0=j*lxsize;//label_img_pt0 = label_img[j]; + label_img_ptr1=label_img_ptr0-lxsize;//label_img_pt1 = label_img[j - 1]; for (i = 1; i < lxsize - 1; i++) {// for(int i = 1; i < lxsize-1;i++, pnt+=poff, pnt2++) { // RGBの合計値が閾値より小さいかな? - if (line_ptr[i] == 0) { + if (raster_buf[line_ptr+i]==0) { // pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 =&(pnt2[-lxsize]); - if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) { - label_pixel = label_img_pt1[i];// *pnt2 = *pnt1; + if (label_img[label_img_ptr1+i] > 0) {//if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) { + label_pixel = label_img[label_img_ptr1+i];//label_pixel = label_img_pt1[i];// *pnt2 = *pnt1; work2_pt = work2[label_pixel - 1]; work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++; work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i; work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j; work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j; - } else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) { - if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) { - m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1]; - n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1]; + } else if (label_img[label_img_ptr1+i + 1] > 0) {//} else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) { + if (label_img[label_img_ptr1+i - 1] > 0) {//if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) { + m = label_idxtbl[label_img[label_img_ptr1+i + 1] - 1];//m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1]; + n = label_idxtbl[label_img[label_img_ptr1+i - 1] - 1];//n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1]; if (m > n) { label_pixel = n;// *pnt2 = n; // wk=IntPointer.wrap(work, 0);//wk = @@ -159,9 +161,9 @@ public class NyARLabeling_ARToolKit_X2 implements INyARLabeling work2_pt[1] += i; work2_pt[2] += j; work2_pt[6] = j; - } else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) { - m = label_idxtbl[(label_img_pt1[i + 1]) - 1];// m =work[*(pnt1+1)-1]; - n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1]; + } else if ((label_img[label_img_ptr0+i - 1]) > 0) {//} else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) { + m = label_idxtbl[label_img[label_img_ptr1+i + 1] - 1];//m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1]; + n = label_idxtbl[label_img[label_img_ptr0+i - 1] - 1];//n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1]; if (m > n) { label_pixel = n;// *pnt2 = n; @@ -186,24 +188,24 @@ public class NyARLabeling_ARToolKit_X2 implements INyARLabeling work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j; } else { - label_pixel = label_img_pt1[i + 1];// *pnt2 = - // *(pnt1+1); + label_pixel = label_img[label_img_ptr1+i + 1];//label_pixel = label_img_pt1[i + 1];// *pnt2 = + // *(pnt1+1); work2_pt = work2[label_pixel - 1]; work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++; work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i; work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j; if (work2_pt[3] > i) {// if( - // work2[((*pnt2)-1)*7+3] > - // i ){ + // work2[((*pnt2)-1)*7+3] > + // i ){ work2_pt[3] = i;// work2[((*pnt2)-1)*7+3] = i; } work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j; } - } else if ((label_img_pt1[i - 1]) > 0) {// }else if( - // *(pnt1-1) > 0 ) { - label_pixel = label_img_pt1[i - 1];// *pnt2 = - // *(pnt1-1); + } else if ((label_img[label_img_ptr1+i - 1]) > 0) {//} else if ((label_img_pt1[i - 1]) > 0) {// }else if( + // *(pnt1-1) > 0 ) { + label_pixel = label_img[label_img_ptr1+i - 1];//label_pixel = label_img_pt1[i - 1];// *pnt2 = + // *(pnt1-1); work2_pt = work2[label_pixel - 1]; work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++; @@ -213,8 +215,8 @@ public class NyARLabeling_ARToolKit_X2 implements INyARLabeling work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i; } work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j; - } else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) { - label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1); + } else if (label_img[label_img_ptr0+i - 1] > 0) {//} else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) { + label_pixel = label_img[label_img_ptr0+i - 1];//label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1); work2_pt = work2[label_pixel - 1]; work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++; @@ -238,9 +240,9 @@ public class NyARLabeling_ARToolKit_X2 implements INyARLabeling work2_pt[5] = j; work2_pt[6] = j; } - label_img_pt0[i] = label_pixel; + label_img[label_img_ptr0+i] = label_pixel;//label_img_pt0[i] = label_pixel; } else { - label_img_pt0[i] = 0;// *pnt2 = 0; + label_img[label_img_ptr0+i] = 0;//label_img_pt0[i] = 0;// *pnt2 = 0; } } } diff --git a/src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java b/src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java index fb76546..0fa6532 100644 --- a/src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java +++ b/src.utils/java3d/jp/nyatla/nyartoolkit/java3d/utils/NyARSingleMarkerBehaviorHolder.java @@ -33,8 +33,7 @@ import javax.media.j3d.*; import javax.vecmath.*; import jp.nyatla.nyartoolkit.NyARException; -import jp.nyatla.nyartoolkit.jmf.utils.JmfCameraCapture; -import jp.nyatla.nyartoolkit.jmf.utils.JmfCaptureListener; +import jp.nyatla.nyartoolkit.jmf.utils.*; import jp.nyatla.nyartoolkit.core.*; import jp.nyatla.nyartoolkit.core.param.NyARParam; import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult; @@ -48,32 +47,35 @@ import jp.nyatla.nyartoolkit.core.types.*; */ public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener { - private NyARParam cparam; + private NyARParam _cparam; - private JmfCameraCapture capture; + private JmfCaptureDevice _capture; - private J3dNyARRaster_RGB nya_raster;//最大3スレッドで共有されるので、排他制御かけること。 + private J3dNyARRaster_RGB _nya_raster;//最大3スレッドで共有されるので、排他制御かけること。 - private NyARSingleDetectMarker nya; + private NyARSingleDetectMarker _nya; //Behaviorホルダ - private NyARBehavior nya_behavior; + private NyARBehavior _nya_behavior; public NyARSingleMarkerBehaviorHolder(NyARParam i_cparam, float i_rate, NyARCode i_ar_code, double i_marker_width) throws NyARException { - nya_behavior = null; + this._nya_behavior = null; final NyARIntSize scr_size = i_cparam.getScreenSize(); - cparam = i_cparam; - capture = new JmfCameraCapture(scr_size.w, scr_size.h, i_rate, JmfCameraCapture.PIXEL_FORMAT_RGB); - capture.setCaptureListener(this); - nya_raster = new J3dNyARRaster_RGB(cparam); - nya = new NyARSingleDetectMarker(cparam, i_ar_code, i_marker_width); - nya_behavior = new NyARBehavior(nya, nya_raster, i_rate); + this._cparam = i_cparam; + //キャプチャの準備 + JmfCaptureDeviceList devlist=new JmfCaptureDeviceList(); + this._capture=devlist.getDevice(0); + this._capture.setCaptureFormat(JmfCaptureDevice.PIXEL_FORMAT_RGB,scr_size.w, scr_size.h,15f); + this._capture.setOnCapture(this); + this._nya_raster = new J3dNyARRaster_RGB(this._cparam); + this._nya = new NyARSingleDetectMarker(this._cparam, i_ar_code, i_marker_width); + this._nya_behavior = new NyARBehavior(this._nya, this._nya_raster, i_rate); } public Behavior getBehavior() { - return nya_behavior; + return this._nya_behavior; } /** @@ -85,7 +87,7 @@ public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener public void setBackGround(Background i_back_ground) { //コール先で排他制御 - nya_behavior.setRelatedBackGround(i_back_ground); + this._nya_behavior.setRelatedBackGround(i_back_ground); } /** @@ -95,7 +97,7 @@ public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener public void setTransformGroup(TransformGroup i_trgroup) { //コール先で排他制御 - nya_behavior.setRelatedTransformGroup(i_trgroup); + this._nya_behavior.setRelatedTransformGroup(i_trgroup); } /** @@ -105,7 +107,7 @@ public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener public void setUpdateListener(NyARSingleMarkerBehaviorListener i_listener) { //コール先で排他制御 - nya_behavior.setUpdateListener(i_listener); + this._nya_behavior.setUpdateListener(i_listener); } /** @@ -114,8 +116,8 @@ public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener public void onUpdateBuffer(Buffer i_buffer) { try { - synchronized (nya_raster) { - nya_raster.setBuffer(i_buffer); + synchronized (this._nya_raster) { + this._nya_raster.setBuffer(i_buffer); } } catch (Exception e) { e.printStackTrace(); @@ -125,12 +127,12 @@ public class NyARSingleMarkerBehaviorHolder implements JmfCaptureListener public void start() throws NyARException { //開始 - capture.start(); + this._capture.start(); } public void stop() { - capture.stop(); + this._capture.stop(); } } diff --git a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java index 8f41946..8f6939d 100644 --- a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java +++ b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCameraCapture.java @@ -35,12 +35,15 @@ import java.util.*; import javax.media.protocol.DataSource; import jp.nyatla.nyartoolkit.NyARException; + /** * 簡易JMFキャプチャクラス - * @author atla + * @deprecated このクラスは近い将来削除します。 + * JmfCaptureDeviceList/JmfCaptureDeviceを使用してください。 + * {@link #JmfCaptureDeviceList()} * */ -public class JmfCameraCapture +@Deprecated public class JmfCameraCapture { private Dimension image_size; @@ -84,7 +87,8 @@ public class JmfCameraCapture public void setCaptureListener(JmfCaptureListener i_listener) throws NyARException { - if (jmf_processor != null) { + if (jmf_processor != null) + { throw new NyARException(); } capture_listener = i_listener; diff --git a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDevice.java b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDevice.java new file mode 100644 index 0000000..12cea7f --- /dev/null +++ b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDevice.java @@ -0,0 +1,177 @@ +package jp.nyatla.nyartoolkit.jmf.utils; + +import java.awt.Dimension; + +import javax.media.CaptureDeviceInfo; +import javax.media.Format; +import javax.media.IncompatibleSourceException; +import javax.media.Manager; +import javax.media.MediaLocator; +import javax.media.Processor; +import javax.media.ProcessorModel; +import javax.media.control.FormatControl; +import javax.media.format.VideoFormat; +import javax.media.protocol.CaptureDevice; +import javax.media.protocol.DataSource; + +import jp.nyatla.nyartoolkit.NyARException; + +public class JmfCaptureDevice +{ + private JmfCaptureListener _capture_listener; + private MonitorStream _jmf_monitor_stream; + private Processor _jmf_processor; + private CaptureDeviceInfo _info; + private Format _capture_format; + public static final String PIXEL_FORMAT_RGB = "RGB"; + public static final String PIXEL_FORMAT_YUV = "YUV"; + + + public JmfCaptureDevice(CaptureDeviceInfo i_capinfo) throws NyARException + { + this._info = i_capinfo; + this._capture_format = null; + return; + } + + public Format[] getSupportFormats() + { + return this._info.getFormats(); + } + + public final Format getCaptureFormat() + { + return this._capture_format; + } + + /** + * このキャプチャデバイスの提供する、i_index番目のフォーマットをキャプチャフォーマットに指定します。 + * @param i_index + */ + public void setCaptureFormat(int i_index) + { + this._capture_format = this._info.getFormats()[i_index]; + return; + } + /** + * キャプチャ画像のフォーマットを指定した形式にしようと試みます。 + * @param i_encode + * キャプチャする画像フォーマットを指定します。フォーマットはこのクラスに宣言される定数値を使ってください。 + * @param i_size + * キャプチャ画像サイズを指定します。 + * @param i_rate + * キャプチャレートをFPS単位で指定します。 + * @return + * 指定に成功するとTRUEを返します。失敗するとFALSEを返します。 + */ + public boolean setCaptureFormat(String i_encode, Dimension i_size, float i_rate) throws NyARException + { + if (this._jmf_processor != null) { + throw new NyARException(); + } + Format[] formats = this._info.getFormats(); + Format f = new VideoFormat(i_encode, i_size, Format.NOT_SPECIFIED, null, i_rate); + for (int i = 0; i < formats.length; i++) { + if (formats[i].matches(f)) { + f = formats[i].intersects(f); + this._capture_format = null; + this._capture_format = f; + return true; + } + } + //ない。 + return false; + } + public boolean setCaptureFormat(String i_encode,int i_size_x,int i_size_y, float i_rate) throws NyARException + { + return setCaptureFormat(i_encode,new Dimension(i_size_x,i_size_y),i_rate); + } + /** + * 画像のキャプチャイベントを受信するリスナクラスを指定します。 + * @param i_listener + * リスナークラス + * @throws NyARException + */ + public void setOnCapture(JmfCaptureListener i_listener) throws NyARException + { + if (this._jmf_processor != null) { + throw new NyARException(); + } + this._capture_listener = i_listener; + return; + } + /** + * キャプチャーを開始します。stop関数を呼び出すまでの間、setOnCaptureで指定したリスナークラスに、 + * フォーマットで指定したキャプチャ画像が通知されます。 + * @throws NyARException + */ + public void start() throws NyARException + { + // startしていたらエラー + if (this._jmf_processor != null) { + throw new NyARException(); + } + DataSource ds; + final MediaLocator ml = this._info.getLocator(); + try { + ds = Manager.createDataSource(ml); + ds.connect(); + // ここでフォーマットを作成 + if (ds instanceof CaptureDevice) { + FormatControl[] fcs = ((CaptureDevice) ds).getFormatControls(); + if (fcs.length < 1) { + return; + } + FormatControl fc = fcs[0]; + fc.setFormat(this._capture_format); + } + } catch (Exception e) { + throw new NyARException(e); + } + try{ + if(ds==null){ + //Merge the data sources, if both audio and video are available + ds = Manager.createMergingDataSource(new DataSource[] { null }); + }else{ + // Create the monitoring datasource wrapper + ds = new MonitorCDS(ds); + } + }catch(IncompatibleSourceException e){ + throw new NyARException(e); + } + + // データソース完成 + try { + // Merge the data sources, if both audio and video are available + VideoFormat[] formats = new VideoFormat[] { new VideoFormat(null) }; + ProcessorModel pm = new ProcessorModel(ds, formats, null);// , + Processor processor; + processor = Manager.createRealizedProcessor(pm); + this._jmf_monitor_stream = (MonitorStream) ds.getControl("jmfsample.MonitorStream"); + this._jmf_monitor_stream.setCaptureListener(this._capture_listener); + this._jmf_processor = processor; + this._jmf_processor.start(); + } catch (Exception e) { + ds.disconnect(); + throw new NyARException(e); + } + return; + } + + public void stop() + { + this._jmf_processor.stop(); + this._jmf_processor.close(); + this._jmf_processor = null; + return; + } + protected void finalize() + { + if (this._jmf_processor != null) { + this._jmf_processor.stop(); + this._jmf_processor.close(); + this._jmf_processor = null; + } + return; + } +} \ No newline at end of file diff --git a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDeviceList.java b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDeviceList.java new file mode 100644 index 0000000..85d7eb0 --- /dev/null +++ b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureDeviceList.java @@ -0,0 +1,100 @@ +package jp.nyatla.nyartoolkit.jmf.utils; + +import java.awt.Dimension; +import java.util.Vector; + +import javax.media.CaptureDeviceInfo; +import javax.media.CaptureDeviceManager; +import javax.media.Format; +import javax.media.format.*; +import jp.nyatla.nyartoolkit.*; + + + +/** + * JMFキャプチャデバイスのリストを保持します。 + * 複数のカメラが接続された環境では、最も初めに認識したカメラの実がアクティブになるため、 + * このクラスで実際に認識できるカメラは1個だけです。 + * + */ +public class JmfCaptureDeviceList +{ + private Vector _devices; + + public JmfCaptureDeviceList() throws NyARException + { + this._devices = (Vector) CaptureDeviceManager.getDeviceList(null).clone(); + // ビデオソースのデバイスだけ残す + try { + + for (int i = 0; i < this._devices.size();) { + CaptureDeviceInfo cdi = (CaptureDeviceInfo) this._devices.elementAt(i); + // VideoFormatもってるかな? + if (!isCaptureDevice(cdi)) { + this._devices.remove(i); + continue; + } + i++; + } + } catch (Exception e) { + throw new NyARException(e); + } + return; + } + + /** + * i_cdiがビデオキャプチャデバイスかを調べる。ようなことをする。 + * + * @param i_cdi + * @return + */ + private static boolean isCaptureDevice(CaptureDeviceInfo i_cdi) + { + Format[] fms = i_cdi.getFormats(); + for (int i = 0; i < fms.length; i++) { + Format f = fms[i]; + if (f instanceof VideoFormat) { + return true; + } + } + return false; + } + + /** + * 使用できるキャプチャデバイスの数を数える + * @return + */ + public int getCount() + { + return this._devices.size(); + } + /** + * i_index番目のキャプチャデバイスを得る。 + * @param i_index + * @return + * @throws NyARException + */ + public JmfCaptureDevice getDevice(int i_index) throws NyARException + { + return new JmfCaptureDevice((CaptureDeviceInfo) this._devices.elementAt(i_index)); + } + + public static void main(String[] args) + { + //テストケース + try { + JmfCaptureDeviceList j = new JmfCaptureDeviceList(); + System.out.println(j.getCount()); + JmfCaptureDevice d = j.getDevice(0); + d.setCaptureFormat("YUV", new Dimension(320, 240), 15.0f); +// YUVFormat f=(YUVFormat)d.getCaptureFormat(); + d.start(); + d.stop(); + + } catch (Exception e) { + e.printStackTrace(); + } + return; + } + +} diff --git a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java index 2e9ff02..69dff72 100644 --- a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java +++ b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/JmfCaptureListener.java @@ -33,5 +33,4 @@ import javax.media.Buffer; */ public interface JmfCaptureListener{ public void onUpdateBuffer(Buffer i_buffer); - } \ No newline at end of file diff --git a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java index 8a05e37..16c60bd 100644 --- a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java +++ b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorCDS.java @@ -27,110 +27,114 @@ */ package jp.nyatla.nyartoolkit.jmf.utils; - import javax.media.*; import javax.media.protocol.*; import javax.media.control.*; import java.io.IOException; +public class MonitorCDS extends PushBufferDataSource +{ + + private PushBufferDataSource delegate = null; + + private PushBufferStream[] delStreams = null; + + private MonitorStream monitorStream = null; + + private PushBufferStream[] monitorStreams = null; + + boolean delStarted = false; // variable used by MonitorStream also + + private Control[] controls; + + public MonitorCDS(DataSource ds) + { + // Get the stream from the actual datasource + // and create a MonitorStream from it + // Export the MonitorControl interface of the MonitorStream + if (ds instanceof PushBufferDataSource) { + delegate = (PushBufferDataSource) ds; + delStreams = delegate.getStreams(); + monitorStream = new MonitorStream(delStreams[0], this); + monitorStreams = new PushBufferStream[] { monitorStream }; + } + } + + public Object[] getControls() + { + return controls; + } + + public Object getControl(String value) + { + if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl")){ + return monitorStream; + }else{ + return null; + } + } + + public javax.media.CaptureDeviceInfo getCaptureDeviceInfo() + { + return ((CaptureDevice) delegate).getCaptureDeviceInfo(); + } + + public FormatControl[] getFormatControls() + { + return ((CaptureDevice) delegate).getFormatControls(); + } + + public String getContentType() + { + return delegate.getContentType(); + } + public void connect() throws IOException + { + if (delegate == null) + throw new IOException("Incompatible DataSource"); + // Delegate is already connected + } -public class MonitorCDS extends PushBufferDataSource{ + public void disconnect() + { + monitorStream.setEnabled(false); + delegate.disconnect(); + } - private PushBufferDataSource delegate = null; - private PushBufferStream [] delStreams = null; - private MonitorStream monitorStream = null; - private PushBufferStream [] monitorStreams = null; - boolean delStarted = false; // variable used by MonitorStream also - private Control [] controls; + public synchronized void start() throws IOException + { + startDelegate(); + delStarted = true; + } - public MonitorCDS(DataSource ds) - { - // Get the stream from the actual datasource - // and create a MonitorStream from it - // Export the MonitorControl interface of the MonitorStream - if (ds instanceof PushBufferDataSource) + public synchronized void stop() throws IOException { - delegate = (PushBufferDataSource) ds; - delStreams = delegate.getStreams(); - monitorStream = new MonitorStream(delStreams[0], this); - monitorStreams = new PushBufferStream[] {monitorStream}; + if (!monitorStream.isEnabled()) { + stopDelegate(); + } + delStarted = false; } - } - - public Object [] getControls() - { - return controls; - } - - public Object getControl(String value) { - if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl")) - return monitorStream; - else - return null; - } - - public javax.media.CaptureDeviceInfo getCaptureDeviceInfo() - { - return ((CaptureDevice)delegate).getCaptureDeviceInfo(); - } - - public FormatControl[] getFormatControls() - { - return ((CaptureDevice)delegate).getFormatControls(); - } - - public String getContentType() - { - return delegate.getContentType(); - } - - public void connect() throws IOException - { - if (delegate == null) - throw new IOException("Incompatible DataSource"); - // Delegate is already connected - } - - public void disconnect() - { - monitorStream.setEnabled(false); - delegate.disconnect(); - } - - public synchronized void start() throws IOException - { - startDelegate(); - delStarted = true; - } - - public synchronized void stop() throws IOException - { - if (!monitorStream.isEnabled()) { - stopDelegate(); + + public Time getDuration() + { + return delegate.getDuration(); + } + + public PushBufferStream[] getStreams() + { + return monitorStreams; + } + + void startDelegate() throws IOException + { + delegate.start(); + } + + void stopDelegate() throws IOException + { + delegate.stop(); } - delStarted = false; - } - - public Time getDuration() - { - return delegate.getDuration(); - } - - public PushBufferStream [] getStreams() - { - return monitorStreams; - } - - void startDelegate() throws IOException - { - delegate.start(); - } - - void stopDelegate() throws IOException - { - delegate.stop(); - } } diff --git a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java index 28d6b86..e714240 100644 --- a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java +++ b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/MonitorStream.java @@ -27,8 +27,6 @@ */ package jp.nyatla.nyartoolkit.jmf.utils; - - import javax.media.*; import javax.media.protocol.*; @@ -36,161 +34,177 @@ import javax.media.util.BufferToImage; import java.io.IOException; import java.awt.*; -public class MonitorStream implements PushBufferStream, BufferTransferHandler { - - JmfCaptureListener img_listener; - PushBufferStream actual = null; - boolean dataAvailable = false; - boolean terminate = false; - boolean enabled = false; - Object bufferLock = new Object(); - Buffer cbuffer = new Buffer(); - BufferTransferHandler transferHandler = null; - Component component = null; - MonitorCDS cds; - BufferToImage bti = null; - - MonitorStream(PushBufferStream actual, MonitorCDS cds) { - this.actual = actual; - actual.setTransferHandler(this); - this.cds = cds; - } - - public javax.media.Format getFormat() - { - return actual.getFormat(); - } - /** - * 非同期READ - */ - public void read(Buffer buffer) throws IOException - { - // Wait for data to be available - // Doesn't get used much because the transferData - // call is made when data IS available. And most - // Processors/Players read the data in the same - // thread that called transferData, although that's - // not a safe assumption to make - if (!dataAvailable) { - synchronized (bufferLock) { - while (!dataAvailable && !terminate) { - try { - bufferLock.wait(100); - } catch (InterruptedException ie) { - } - } - } - } +public class MonitorStream implements PushBufferStream, BufferTransferHandler +{ + + JmfCaptureListener img_listener; + + PushBufferStream actual = null; + + boolean dataAvailable = false; + + boolean terminate = false; + + boolean enabled = false; - if (dataAvailable) { - synchronized (bufferLock) { - // Copy the buffer attributes, but swap the data - // attributes so that no extra copy is made. - buffer.copy(cbuffer, true); - //dataAvailable = false; - } + Object bufferLock = new Object(); + + Buffer cbuffer = new Buffer(); + + BufferTransferHandler transferHandler = null; + + Component component = null; + + MonitorCDS cds; + + BufferToImage bti = null; + + MonitorStream(PushBufferStream actual, MonitorCDS cds) + { + this.actual = actual; + actual.setTransferHandler(this); + this.cds = cds; } -// return; - } - public void setCaptureListener(JmfCaptureListener i_listener) - { - img_listener=i_listener; - } - - public void transferData(PushBufferStream pbs) - { - // Get the data from the original source stream - synchronized (bufferLock) { - try { - pbs.read(cbuffer); - } catch (IOException ioe) { - return; - } - dataAvailable = true; - bufferLock.notifyAll(); + + public javax.media.Format getFormat() + { + return actual.getFormat(); } - if(img_listener!=null){ - img_listener.onUpdateBuffer(cbuffer); + + /** + * 非同期READ + */ + public void read(Buffer buffer) throws IOException + { + // Wait for data to be available + // Doesn't get used much because the transferData + // call is made when data IS available. And most + // Processors/Players read the data in the same + // thread that called transferData, although that's + // not a safe assumption to make + if (!dataAvailable) { + synchronized (bufferLock) { + while (!dataAvailable && !terminate) { + try { + bufferLock.wait(100); + } catch (InterruptedException ie) { + } + } + } + } + + if (dataAvailable) { + synchronized (bufferLock) { + // Copy the buffer attributes, but swap the data + // attributes so that no extra copy is made. + buffer.copy(cbuffer, true); + //dataAvailable = false; + } + } + // return; } - -/* - // Display data if monitor is active - if (isEnabled()) { - if (bti == null) { - VideoFormat vf = (VideoFormat) cbuffer.getFormat(); - bti = new BufferToImage(vf); - } - if (bti != null && component != null) { - Image im = bti.createImage(cbuffer); - Graphics g = component.getGraphics(); - Dimension size = component.getSize(); - if (g != null) - g.drawImage(im, 0, 0, component); - } + + public void setCaptureListener(JmfCaptureListener i_listener) + { + img_listener = i_listener; } -*/ - // Maybe synchronize this with setTransferHandler() ? - if (transferHandler != null && cds.delStarted) - transferHandler.transferData(this); - } - - public void setTransferHandler(BufferTransferHandler transferHandler) { - this.transferHandler = transferHandler; - } - - public boolean setEnabled(boolean value) { - enabled = value; - if (value == false) { - if (!cds.delStarted) { - try { - cds.stopDelegate(); - } catch (IOException ioe) { + + public void transferData(PushBufferStream pbs) + { + // Get the data from the original source stream + synchronized (bufferLock) { + try { + pbs.read(cbuffer); + } catch (IOException ioe) { + return; + } + dataAvailable = true; + bufferLock.notifyAll(); } - } - } else { - // Start the capture datasource if the monitor is enabled - try { - cds.startDelegate(); - }catch (IOException ioe) { - } + if (img_listener != null) { + img_listener.onUpdateBuffer(cbuffer); + } + + /* + // Display data if monitor is active + if (isEnabled()) { + if (bti == null) { + VideoFormat vf = (VideoFormat) cbuffer.getFormat(); + bti = new BufferToImage(vf); + } + if (bti != null && component != null) { + Image im = bti.createImage(cbuffer); + Graphics g = component.getGraphics(); + Dimension size = component.getSize(); + if (g != null) + g.drawImage(im, 0, 0, component); + } + } + */ + // Maybe synchronize this with setTransferHandler() ? + if (transferHandler != null && cds.delStarted) + transferHandler.transferData(this); } - return enabled; - } - public boolean isEnabled() - { - return enabled; - } + public void setTransferHandler(BufferTransferHandler transferHandler) + { + this.transferHandler = transferHandler; + } + public boolean setEnabled(boolean value) + { + enabled = value; + if (value == false) { + if (!cds.delStarted) { + try { + cds.stopDelegate(); + } catch (IOException ioe) { + } + } + } else { + // Start the capture datasource if the monitor is enabled + try { + cds.startDelegate(); + } catch (IOException ioe) { + } + } + return enabled; + } + public boolean isEnabled() + { + return enabled; + } - public float setPreviewFrameRate(float rate) - { - System.err.println("TODO"); - return rate; - } - - public ContentDescriptor getContentDescriptor() - { - return actual.getContentDescriptor(); - } + public float setPreviewFrameRate(float rate) + { + System.err.println("TODO"); + return rate; + } - public long getContentLength() - { - return actual.getContentLength(); - } + public ContentDescriptor getContentDescriptor() + { + return actual.getContentDescriptor(); + } - public boolean endOfStream() { - return actual.endOfStream(); - } + public long getContentLength() + { + return actual.getContentLength(); + } - public Object [] getControls() { - return new Object[0]; - } + public boolean endOfStream() + { + return actual.endOfStream(); + } - public Object getControl(String str) { - return null; - } + public Object[] getControls() + { + return new Object[0]; + } + public Object getControl(String str) + { + return null; + } } diff --git a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/sample/JmfCaptureTest.java b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/sample/JmfCaptureTest.java index aa8e435..b7437e3 100644 --- a/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/sample/JmfCaptureTest.java +++ b/src.utils/jmf/jp/nyatla/nyartoolkit/jmf/utils/sample/JmfCaptureTest.java @@ -40,15 +40,17 @@ import java.awt.*; */ public class JmfCaptureTest extends Frame implements JmfCaptureListener { + private static final long serialVersionUID = -2110888320986446576L; + private JmfCaptureDevice _capture; public JmfCaptureTest() throws NyARException { setTitle("JmfCaptureTest"); setBounds(0, 0, 320 + 64, 240 + 64); - capture = new JmfCameraCapture(320, 240, 30f, JmfCameraCapture.PIXEL_FORMAT_RGB); - capture.setCaptureListener(this); + JmfCaptureDeviceList dl=new JmfCaptureDeviceList(); + this._capture=dl.getDevice(0); + this._capture.setOnCapture(this); } - private JmfCameraCapture capture; public void onUpdateBuffer(Buffer i_buffer) { @@ -61,7 +63,7 @@ public class JmfCaptureTest extends Frame implements JmfCaptureListener private void startCapture() { try { - capture.start(); + this._capture.start(); } catch (Exception e) { e.printStackTrace(); } diff --git a/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java b/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java index 1d28f27..0c63560 100644 --- a/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java +++ b/src.utils/jogl/jp/nyatla/nyartoolkit/jogl/utils/GLNyARRaster_RGB.java @@ -64,8 +64,8 @@ public class GLNyARRaster_RGB extends JmfNyARRaster_RGB if (i_is_reverse) { final int length = this._size.w * 3; int src_idx = 0; - int dest_idx = (this._size.h - 1) * length; - for (int i = 0; i < this._size.h; i++) { + int dest_idx = (this._size.h - 1) * length; + for (int i = 0; i < this._size.h; i++){ System.arraycopy(src_buf, src_idx, this._gl_buf, dest_idx, length); src_idx += length; dest_idx -= length; diff --git a/src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java b/src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java index 4d96f7d..09440bc 100644 --- a/src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java +++ b/src/jp/nyatla/nyartoolkit/core/NyARSquareDetector.java @@ -119,7 +119,6 @@ public class NyARSquareDetector implements INyARSquareDetector */ public final void detectMarker(NyARBinRaster i_raster, NyARSquareStack o_square_stack) throws NyARException { - final INyARLabeling labeling_proc = this._labeling; final NyARLabelingImage limage = this._limage; // 初期化 @@ -128,7 +127,7 @@ public class NyARSquareDetector implements INyARSquareDetector o_square_stack.clear(); // ラベリング - labeling_proc.labeling(i_raster); + this._labeling.labeling(i_raster); // ラベル数が0ならここまで final int label_num = limage.getLabelStack().getLength(); diff --git a/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingImage.java b/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingImage.java index e5b4ac2..916e610 100644 --- a/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingImage.java +++ b/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabelingImage.java @@ -43,7 +43,7 @@ import jp.nyatla.nyartoolkit.core.types.*; public class NyARLabelingImage extends NyARRaster_BasicClass implements INyARLabelingImage { private final static int MAX_LABELS = 1024*32; - protected int[][] _ref_buf; + protected int[] _ref_buf; private INyARBufferReader _buffer_reader; protected NyARLabelingLabelStack _label_list; protected int[] _index_table; @@ -51,11 +51,11 @@ public class NyARLabelingImage extends NyARRaster_BasicClass implements INyARLab public NyARLabelingImage(int i_width, int i_height) { super(new NyARIntSize(i_width,i_height)); - this._ref_buf =new int[i_height][i_width]; + this._ref_buf =new int[i_height*i_width]; this._label_list = new NyARLabelingLabelStack(MAX_LABELS); this._index_table=new int[MAX_LABELS]; this._is_index_table_enable=false; - this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT2D); + this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D); return; } @@ -102,15 +102,16 @@ public class NyARLabelingImage extends NyARRaster_BasicClass implements INyARLab */ protected int getTopClipTangentX(NyARLabelingLabel i_label) throws NyARException { - int w; + int pix; int i_label_id=i_label.id; int[] index_table=this._index_table; - int[] limage_j=this._ref_buf[i_label.clip_t]; + int[] limage=this._ref_buf; + int limage_ptr=i_label.clip_t*this._size.w; final int clip1 = i_label.clip_r; // p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 =&(limage[j*xsize+clip[0]]); for (int i = i_label.clip_l; i <= clip1; i++) {// for( i = clip[0]; i <=clip[1]; i++, p1++ ) { - w = limage_j[i]; - if (w > 0 && index_table[w-1] == i_label_id){ + pix = limage[limage_ptr+i]; + if (pix > 0 && index_table[pix-1] == i_label_id){ return i; } } @@ -129,6 +130,7 @@ public class NyARLabelingImage extends NyARRaster_BasicClass implements INyARLab */ public int getContour(int i_index,int i_array_size,int[] o_coord_x,int[] o_coord_y) throws NyARException { + final int width=this._size.w; final int[] xdir = this._getContour_xdir;// static int xdir[8] = { 0,1, 1, 1, 0,-1,-1,-1}; final int[] ydir = this._getContour_ydir;// static int ydir[8] = {-1,-1,0, 1, 1, 1, 0,-1}; final NyARLabelingLabel label=(NyARLabelingLabel)this._label_list.getItem(i_index); @@ -142,13 +144,13 @@ public class NyARLabelingImage extends NyARRaster_BasicClass implements INyARLab o_coord_y[0] = sy; int dir = 5; - int[][] limage=this._ref_buf; + int[] limage=this._ref_buf; int c = o_coord_x[0]; int r = o_coord_y[0]; for (;;) { dir = (dir + 5) % 8; for (i = 0; i < 8; i++) { - if (limage[r + ydir[dir]][c + xdir[dir]] > 0) { + if (limage[(r + ydir[dir])*width+(c + xdir[dir])] > 0) { break; } dir = (dir + 1) % 8; diff --git a/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabeling_ARToolKit.java b/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabeling_ARToolKit.java index 76bf91e..8951fd9 100644 --- a/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabeling_ARToolKit.java +++ b/src/jp/nyatla/nyartoolkit/core/labeling/NyARLabeling_ARToolKit.java @@ -31,8 +31,6 @@ */ package jp.nyatla.nyartoolkit.core.labeling; - - import jp.nyatla.nyartoolkit.NyARException; import jp.nyatla.nyartoolkit.core.raster.*; import jp.nyatla.nyartoolkit.core.types.*; @@ -44,34 +42,41 @@ import jp.nyatla.nyartoolkit.core.types.*; public class NyARLabeling_ARToolKit implements INyARLabeling { private static final int WORK_SIZE = 1024 * 32;// #define WORK_SIZE 1024*32 + private final NyARWorkHolder work_holder = new NyARWorkHolder(WORK_SIZE); + private NyARIntSize _dest_size; + private INyARLabelingImage _out_image; - public void attachDestination(INyARLabelingImage i_destination_image)throws NyARException + public void attachDestination(INyARLabelingImage i_destination_image) throws NyARException { // サイズチェック NyARIntSize size = i_destination_image.getSize(); this._out_image = i_destination_image; // NyLabelingImageのイメージ初期化(枠書き) - int[][] img = (int[][])i_destination_image.getBufferReader().getBuffer(); + int[] img = (int[]) i_destination_image.getBufferReader().getBuffer(); + int bottom_ptr = (size.h - 1) * size.w; for (int i = 0; i < size.w; i++) { - img[0][i] = 0; - img[size.h - 1][i] = 0; + img[i] = 0; + img[bottom_ptr + i] = 0; } for (int i = 0; i < size.h; i++) { - img[i][0] = 0; - img[i][size.w - 1] = 0; + img[i * size.w] = 0; + img[(i + 1) * size.w - 1] = 0; } // サイズ(参照値)を保存 this._dest_size = size; + return; } + public INyARLabelingImage getAttachedDestination() { return this._out_image; } + /** * static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR ) 関数の代替品 * ラスタimageをラベリングして、結果を保存します。 Optimize:STEP[1514->1493] @@ -81,9 +86,9 @@ public class NyARLabeling_ARToolKit implements INyARLabeling */ public void labeling(NyARBinRaster i_raster) throws NyARException { - int m, n; /* work */ - int i, j, k; - INyARLabelingImage out_image = this._out_image; + int label_img_ptr1, label_pixel; + int i, j; + int n, k; /* work */ // サイズチェック NyARIntSize in_size = i_raster.getSize(); @@ -91,88 +96,82 @@ public class NyARLabeling_ARToolKit implements INyARLabeling final int lxsize = in_size.w;// lxsize = arUtil_c.arImXsize; final int lysize = in_size.h;// lysize = arUtil_c.arImYsize; - int[][] label_img = (int[][])out_image.getBufferReader().getBuffer(); + final int[] label_img = (int[]) this._out_image.getBufferReader().getBuffer(); // 枠作成はインスタンスを作った直後にやってしまう。 - - //ラベリング情報のリセット(ラベリングインデックスを使用) - out_image.reset(true); - - int[] label_idxtbl=out_image.getIndexArray(); + + // ラベリング情報のリセット(ラベリングインデックスを使用) + this._out_image.reset(true); + + int[] label_idxtbl = this._out_image.getIndexArray(); + int[] raster_buf = (int[]) i_raster.getBufferReader().getBuffer(); int[] work2_pt; int wk_max = 0; - int label_pixel; - int[][] raster_buf=(int[][])i_raster.getBufferReader().getBuffer(); - int[] line_ptr; + int pixel_index; int[][] work2 = this.work_holder.work2; - int[] label_img_pt0, label_img_pt1; + + // [1,1](ptr0)と、[0,1](ptr1)のインデクス値を計算する。 for (j = 1; j < lysize - 1; j++) {// for (int j = 1; j < lysize - 1;j++, pnt += poff*2, pnt2 += 2) { - line_ptr=raster_buf[j]; - label_img_pt0 = label_img[j]; - label_img_pt1 = label_img[j - 1]; - for (i = 1; i < lxsize - 1; i++) {// for(int i = 1; i < lxsize-1;i++, pnt+=poff, pnt2++) { + pixel_index = j * lxsize + 1; + label_img_ptr1 = pixel_index - lxsize;// label_img_pt1 = label_img[j - 1]; + for (i = 1; i < lxsize - 1; i++, pixel_index++, label_img_ptr1++) {// for(int i = 1; i < lxsize-1;i++, pnt+=poff, pnt2++) { // RGBの合計値が閾値より小さいかな? - if (line_ptr[i]==0) { + if (raster_buf[pixel_index] != 0) { + label_img[pixel_index] = 0;// label_img_pt0[i] = 0;// *pnt2 = 0; + } else { // pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 =&(pnt2[-lxsize]); - if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) { - label_pixel = label_img_pt1[i];// *pnt2 = *pnt1; + if (label_img[label_img_ptr1] > 0) {// if (label_img_pt1[i] > 0) {// if( *pnt1 > 0 ) { + label_pixel = label_img[label_img_ptr1];// label_pixel = label_img_pt1[i];// *pnt2 = *pnt1; work2_pt = work2[label_pixel - 1]; work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++; work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i; work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j; work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j; - } else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) { - if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) { - m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1]; - n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1]; - if (m > n) { - label_pixel = n;// *pnt2 = n; - // wk=IntPointer.wrap(work, 0);//wk = - // &(work[0]); + } else if (label_img[label_img_ptr1 + 1] > 0) {// } else if (label_img_pt1[i + 1] > 0) {// }else if(*(pnt1+1) > 0 ) { + if (label_img[label_img_ptr1 - 1] > 0) {// if (label_img_pt1[i - 1] > 0) {// if( *(pnt1-1) > 0 ) { + label_pixel = label_idxtbl[label_img[label_img_ptr1 + 1] - 1];// m = label_idxtbl[label_img_pt1[i + 1] - 1];// m + // =work[*(pnt1+1)-1]; + n = label_idxtbl[label_img[label_img_ptr1 - 1] - 1];// n = label_idxtbl[label_img_pt1[i - 1] - 1];// n =work[*(pnt1-1)-1]; + if (label_pixel > n) { + // wk=IntPointer.wrap(work, 0);//wk = &(work[0]); for (k = 0; k < wk_max; k++) { - if (label_idxtbl[k] == m) {// if( *wk == m ) + if (label_idxtbl[k] == label_pixel) {// if( *wk == m ) label_idxtbl[k] = n;// *wk = n; } } - } else if (m < n) { - label_pixel = m;// *pnt2 = m; + label_pixel = n;// *pnt2 = n; + } else if (label_pixel < n) { // wk=IntPointer.wrap(work,0);//wk = &(work[0]); for (k = 0; k < wk_max; k++) { if (label_idxtbl[k] == n) {// if( *wk == n ){ - label_idxtbl[k] = m;// *wk = m; + label_idxtbl[k] = label_pixel;// *wk = m; } } - } else { - label_pixel = m;// *pnt2 = m; } work2_pt = work2[label_pixel - 1]; work2_pt[0]++; work2_pt[1] += i; work2_pt[2] += j; work2_pt[6] = j; - } else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) { - m = label_idxtbl[(label_img_pt1[i + 1]) - 1];// m =work[*(pnt1+1)-1]; - n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1]; - if (m > n) { - - label_pixel = n;// *pnt2 = n; + } else if ((label_img[pixel_index - 1]) > 0) {// } else if ((label_img_pt0[i - 1]) > 0) {// }else if(*(pnt2-1) > 0) { + label_pixel = label_idxtbl[label_img[label_img_ptr1 + 1] - 1];// m = label_idxtbl[label_img_pt1[i + 1] - 1];// m =work[*(pnt1+1)-1]; + n = label_idxtbl[label_img[pixel_index - 1] - 1];// n = label_idxtbl[label_img_pt0[i - 1] - 1];// n =work[*(pnt2-1)-1]; + if (label_pixel > n) { for (k = 0; k < wk_max; k++) { - if (label_idxtbl[k] == m) {// if( *wk == m ){ + if (label_idxtbl[k] == label_pixel) {// if( *wk == m ){ label_idxtbl[k] = n;// *wk = n; } } - } else if (m < n) { - label_pixel = m;// *pnt2 = m; + label_pixel = n;// *pnt2 = n; + } else if (label_pixel < n) { for (k = 0; k < wk_max; k++) { if (label_idxtbl[k] == n) {// if( *wk == n ){ - label_idxtbl[k] = m;// *wk = m; + label_idxtbl[k] = label_pixel;// *wk = m; } } - } else { - label_pixel = m;// *pnt2 = m; } work2_pt = work2[label_pixel - 1]; work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++; @@ -180,24 +179,22 @@ public class NyARLabeling_ARToolKit implements INyARLabeling work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j; } else { - label_pixel = label_img_pt1[i + 1];// *pnt2 = - // *(pnt1+1); + label_pixel = label_img[label_img_ptr1 + 1];// label_pixel = label_img_pt1[i + 1];// *pnt2 = + // *(pnt1+1); work2_pt = work2[label_pixel - 1]; work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++; work2_pt[1] += i;// work2[((*pnt2)-1)*7+1] += i; work2_pt[2] += j;// work2[((*pnt2)-1)*7+2] += j; - if (work2_pt[3] > i) {// if( - // work2[((*pnt2)-1)*7+3] > - // i ){ + if (work2_pt[3] > i) {// if(work2[((*pnt2)-1)*7+3] > i ){ work2_pt[3] = i;// work2[((*pnt2)-1)*7+3] = i; } work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j; } - } else if ((label_img_pt1[i - 1]) > 0) {// }else if( - // *(pnt1-1) > 0 ) { - label_pixel = label_img_pt1[i - 1];// *pnt2 = - // *(pnt1-1); + } else if ((label_img[label_img_ptr1 - 1]) > 0) {// } else if ((label_img_pt1[i - 1]) > 0) {// }else if( + // *(pnt1-1) > 0 ) { + label_pixel = label_img[label_img_ptr1 - 1];// label_pixel = label_img_pt1[i - 1];// *pnt2 = + // *(pnt1-1); work2_pt = work2[label_pixel - 1]; work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++; @@ -207,8 +204,8 @@ public class NyARLabeling_ARToolKit implements INyARLabeling work2_pt[4] = i;// work2[((*pnt2)-1)*7+4] = i; } work2_pt[6] = j;// work2[((*pnt2)-1)*7+6] = j; - } else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) { - label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1); + } else if (label_img[pixel_index - 1] > 0) {// } else if (label_img_pt0[i - 1] > 0) {// }else if(*(pnt2-1) > 0) { + label_pixel = label_img[pixel_index - 1];// label_pixel = label_img_pt0[i - 1];// *pnt2 =*(pnt2-1); work2_pt = work2[label_pixel - 1]; work2_pt[0]++;// work2[((*pnt2)-1)*7+0] ++; @@ -232,11 +229,10 @@ public class NyARLabeling_ARToolKit implements INyARLabeling work2_pt[5] = j; work2_pt[6] = j; } - label_img_pt0[i] = label_pixel; - } else { - label_img_pt0[i] = 0;// *pnt2 = 0; + label_img[pixel_index] = label_pixel;// label_img_pt0[i] = label_pixel; } } + } // インデックステーブルとラベル数の計算 int wlabel_num = 1;// *label_num = *wlabel_num = j - 1; @@ -247,26 +243,26 @@ public class NyARLabeling_ARToolKit implements INyARLabeling wlabel_num -= 1;// *label_num = *wlabel_num = j - 1; if (wlabel_num == 0) {// if( *label_num == 0 ) { // 発見数0 - out_image.getLabelStack().clear(); + this._out_image.getLabelStack().clear(); return; } // ラベル情報の保存等 - NyARLabelingLabelStack label_list = out_image.getLabelStack(); + NyARLabelingLabelStack label_list = this._out_image.getLabelStack(); // ラベルバッファを予約 label_list.reserv(wlabel_num); // エリアと重心、クリップ領域を計算 NyARLabelingLabel label_pt; - NyARLabelingLabel[] labels = (NyARLabelingLabel[])label_list.getArray(); + NyARLabelingLabel[] labels = (NyARLabelingLabel[]) label_list.getArray(); for (i = 0; i < wlabel_num; i++) { - label_pt =labels[i]; - label_pt.id =i+1; + label_pt = labels[i]; + label_pt.id = i + 1; label_pt.area = 0; - label_pt.pos_x =label_pt.pos_y = 0; + label_pt.pos_x = label_pt.pos_y = 0; label_pt.clip_l = lxsize;// wclip[i*4+0] = lxsize; label_pt.clip_t = lysize;// wclip[i*4+2] = lysize; - label_pt.clip_r =label_pt.clip_b = 0;// wclip[i*4+3] = 0; + label_pt.clip_r = label_pt.clip_b = 0;// wclip[i*4+3] = 0; } for (i = 0; i < wk_max; i++) { diff --git a/src/jp/nyatla/nyartoolkit/core/param/NyARParam.java b/src/jp/nyatla/nyartoolkit/core/param/NyARParam.java index 4267207..0030b4d 100644 --- a/src/jp/nyatla/nyartoolkit/core/param/NyARParam.java +++ b/src/jp/nyatla/nyartoolkit/core/param/NyARParam.java @@ -62,6 +62,19 @@ public class NyARParam { return this._dist; } + /** + * + * @param i_factor + * NyARCameraDistortionFactorにセットする配列を指定する。要素数は4であること。 + * @param i_projection + * NyARPerspectiveProjectionMatrixセットする配列を指定する。要素数は12であること。 + */ + public void setValue(double[] i_factor,double[] i_projection) + { + this._dist.setValue(i_factor); + this._projection_matrix.setValue(i_projection); + return; + } /** * ARToolKit標準ファイルから1個目の設定をロードする。 @@ -93,13 +106,6 @@ public class NyARParam //スケールを変更 this._dist.changeScale(scale); this._projection_matrix.changeScale(scale); - //for (int i = 0; i < 4; i++) { - // array34[0 * 4 + i] = array34[0 * 4 + i] * scale;// newparam->mat[0][i]=source->mat[0][i]* scale; - // array34[1 * 4 + i] = array34[1 * 4 + i] * scale;// newparam->mat[1][i]=source->mat[1][i]* scale; - // array34[2 * 4 + i] = array34[2 * 4 + i];// newparam->mat[2][i] = source->mat[2][i]; - //} - - this._screen_size.w = i_xsize;// newparam->xsize = xsize; this._screen_size.h = i_ysize;// newparam->ysize = ysize; return; diff --git a/src/jp/nyatla/nyartoolkit/core/pca2d/INyARPca2d.java b/src/jp/nyatla/nyartoolkit/core/pca2d/INyARPca2d.java index c7f583b..be9f494 100644 --- a/src/jp/nyatla/nyartoolkit/core/pca2d/INyARPca2d.java +++ b/src/jp/nyatla/nyartoolkit/core/pca2d/INyARPca2d.java @@ -32,7 +32,6 @@ package jp.nyatla.nyartoolkit.core.pca2d; import jp.nyatla.nyartoolkit.NyARException; -import jp.nyatla.nyartoolkit.core.param.*; import jp.nyatla.nyartoolkit.core.types.NyARDoublePoint2d; import jp.nyatla.nyartoolkit.core.types.matrix.NyARDoubleMatrix22; diff --git a/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java b/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java index 418017e..9a13ec2 100644 --- a/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java +++ b/src/jp/nyatla/nyartoolkit/core/raster/NyARBinRaster.java @@ -37,13 +37,13 @@ import jp.nyatla.nyartoolkit.core.types.*; public final class NyARBinRaster extends NyARRaster_BasicClass { private INyARBufferReader _buffer_reader; - protected int[][] _ref_buf; + protected int[] _ref_buf; public NyARBinRaster(int i_width, int i_height) { super(new NyARIntSize(i_width,i_height)); - this._ref_buf = new int[i_height][i_width]; - this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8); + this._ref_buf = new int[i_height*i_width]; + this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8); } public INyARBufferReader getBufferReader() { diff --git a/src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java b/src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java index 314c9c3..03809d3 100644 --- a/src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java +++ b/src/jp/nyatla/nyartoolkit/core/raster/NyARGrayscaleRaster.java @@ -38,14 +38,14 @@ import jp.nyatla.nyartoolkit.core.types.*; public final class NyARGrayscaleRaster extends NyARRaster_BasicClass { - protected int[][] _ref_buf; + protected int[] _ref_buf; private INyARBufferReader _buffer_reader; public NyARGrayscaleRaster(int i_width, int i_height) { super(new NyARIntSize(i_width,i_height)); - this._ref_buf = new int[i_height][i_width]; - this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8); + this._ref_buf = new int[i_height*i_width]; + this._buffer_reader=new NyARBufferReader(this._ref_buf,INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8); } public INyARBufferReader getBufferReader() { diff --git a/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java b/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java index ca4e973..d2149aa 100644 --- a/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java +++ b/src/jp/nyatla/nyartoolkit/core/rasterfilter/rgb2bin/NyARRasterFilter_ARToolkitThreshold.java @@ -60,11 +60,11 @@ public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_Rg INyARBufferReader out_buffer_reader=i_output.getBufferReader(); int in_buf_type=in_buffer_reader.getBufferType(); - assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8)); + assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8)); assert (checkInputType(in_buf_type)==true); assert (i_input.getSize().isEqualSize(i_output.getSize()) == true); - int[][] out_buf = (int[][]) out_buffer_reader.getBuffer(); + int[] out_buf = (int[]) out_buffer_reader.getBuffer(); byte[] in_buf = (byte[]) in_buffer_reader.getBuffer(); NyARIntSize size = i_output.getSize(); @@ -82,96 +82,103 @@ public class NyARRasterFilter_ARToolkitThreshold implements INyARRasterFilter_Rg return; } - private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size) + private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size) { - final int size_w=i_size.w; - final int x_mod_end= size_w-(size_w%8); final int th=this._threshold*3; - int bp =(size_w*i_size.h-1)*3; + int bp =(i_size.w*i_size.h-1)*3; int w; - int x; - for (int y =i_size.h-1; y>=0 ; y--){ - //端数分 - final int[] row_ptr=i_out[y]; - for (x = size_w-1;x>=x_mod_end;x--) { - w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x]=w<=th?0:1; - bp -= 3; - } - //タイリング - for (;x>=0;x-=8) { - w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x]=w<=th?0:1; - bp -= 3; - w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-1]=w<=th?0:1; - bp -= 3; - w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-2]=w<=th?0:1; - bp -= 3; - w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-3]=w<=th?0:1; - bp -= 3; - w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-4]=w<=th?0:1; - bp -= 3; - w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-5]=w<=th?0:1; - bp -= 3; - w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-6]=w<=th?0:1; - bp -= 3; - w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-7]=w<=th?0:1; - bp -= 3; - } + int xy; + final int pix_count =i_size.h*i_size.w; + final int pix_mod_part=pix_count-(pix_count%8); + for(xy=pix_count-1;xy>=pix_mod_part;xy--){ + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 3; + } + //タイリング + for (;xy>=0;) { + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 3; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 3; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 3; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 3; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 3; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 3; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 3; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 3; + xy--; } return; } - private void convert32BitRgbx(byte[] i_in, int[][] i_out, NyARIntSize i_size) + private void convert32BitRgbx(byte[] i_in, int[] i_out, NyARIntSize i_size) { - final int size_w=i_size.w; - final int x_mod_end= size_w-(size_w%8); final int th=this._threshold*3; - int bp =(size_w*i_size.h-1)*4; + int bp =(i_size.w*i_size.h-1)*4; int w; - int x; - for (int y =i_size.h-1; y>=0 ; y--){ - final int[] row_ptr=i_out[y]; - - //端数分 - for (x = size_w-1;x>=x_mod_end;x--) { - w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x]=w<=th?0:1; - bp -= 4; - } - //タイリング - for (;x>=0;x-=8) { - w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x]=w<=th?0:1; - bp -= 4; - w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-1]=w<=th?0:1; - bp -= 4; - w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-2]=w<=th?0:1; - bp -= 4; - w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-3]=w<=th?0:1; - bp -= 4; - w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-4]=w<=th?0:1; - bp -= 4; - w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-5]=w<=th?0:1; - bp -= 4; - w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-6]=w<=th?0:1; - bp -= 4; - w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); - row_ptr[x-7]=w<=th?0:1; - bp -= 4; - } + int xy; + final int pix_count =i_size.h*i_size.w; + final int pix_mod_part=pix_count-(pix_count%8); + for(xy=pix_count-1;xy>=pix_mod_part;xy--){ + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 4; + } + //タイリング + for (;xy>=0;) { + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 4; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 4; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 4; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 4; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 4; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 4; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 4; + xy--; + w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)); + i_out[xy]=w<=th?0:1; + bp -= 4; + xy--; } return; } diff --git a/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java b/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java index 1b4423c..c419366 100644 --- a/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java +++ b/src/jp/nyatla/nyartoolkit/core/rasterreader/INyARBufferReader.java @@ -30,18 +30,25 @@ * */ package jp.nyatla.nyartoolkit.core.rasterreader; - +/** + * このインタフェイスは、画素データを格納するバッファオブジェクト + * へのアクセス方法と、その形式を定義します。 + * + */ public interface INyARBufferReader { + public static final int BYTE1D =0x00010000; + public static final int INT2D =0x00020000; + public static final int SHORT1D=0x00030000; + public static final int INT1D =0x00040000; // ID規約 - // 00-07(8)型番号 - // 08-15(8)ビットフォーマットID - // 00:24bit/01:32bit/02:16bit + // 24-31(8)予約 // 16-27(8)型ID // 00:無効/01:byte[]/02:int[][]/03:short[] - // 24-31(8)予約 + // 08-15(8)ビットフォーマットID + // 00:24bit/01:32bit/02:16bit + // 00-07(8)型番号 // - /** * RGB24フォーマットで、全ての画素が0 */ @@ -50,46 +57,73 @@ public interface INyARBufferReader /** * byte[]で、R8G8B8の24ビットで画素が格納されている。 */ - public static final int BUFFERFORMAT_BYTE1D_R8G8B8_24 = 0x00010001; - + public static final int BUFFERFORMAT_BYTE1D_R8G8B8_24 = BYTE1D|0x0001; /** * byte[]で、B8G8R8の24ビットで画素が格納されている。 */ - public static final int BUFFERFORMAT_BYTE1D_B8G8R8_24 = 0x00010002; - + public static final int BUFFERFORMAT_BYTE1D_B8G8R8_24 = BYTE1D|0x0002; /** * byte[]で、R8G8B8X8の32ビットで画素が格納されている。 */ - public static final int BUFFERFORMAT_BYTE1D_B8G8R8X8_32 = 0x00010101; + public static final int BUFFERFORMAT_BYTE1D_B8G8R8X8_32 = BYTE1D|0x0101; /** * byte[]で、RGB565の16ビット(little/big endian)で画素が格納されている。 */ - public static final int BUFFERFORMAT_BYTE1D_R5G6B5_16LE = 0x00010201; - public static final int BUFFERFORMAT_BYTE1D_R5G6B5_16BE = 0x00010202; + public static final int BUFFERFORMAT_BYTE1D_R5G6B5_16LE = BYTE1D|0x0201; + public static final int BUFFERFORMAT_BYTE1D_R5G6B5_16BE = BYTE1D|0x0202; /** * short[]で、RGB565の16ビット(little/big endian)で画素が格納されている。 */ - public static final int BUFFERFORMAT_WORD1D_R5G6B5_16LE = 0x00030201; - public static final int BUFFERFORMAT_WORD1D_R5G6B5_16BE = 0x00030202; + public static final int BUFFERFORMAT_WORD1D_R5G6B5_16LE = SHORT1D|0x0201; + public static final int BUFFERFORMAT_WORD1D_R5G6B5_16BE = SHORT1D|0x0202; /** * int[][]で特に値範囲を定めない */ - public static final int BUFFERFORMAT_INT2D = 0x00020000; - + public static final int BUFFERFORMAT_INT2D = INT2D|0x0000; /** * int[][]で0-255のグレイスケール画像 */ - public static final int BUFFERFORMAT_INT2D_GLAY_8 = 0x00020001; - + public static final int BUFFERFORMAT_INT2D_GLAY_8 = INT2D|0x0001; /** * int[][]で0/1の2値画像 */ - public static final int BUFFERFORMAT_INT2D_BIN_8 = 0x00020002; + public static final int BUFFERFORMAT_INT2D_BIN_8 = INT2D|0x0002; + /** + * int[]で特に値範囲を定めない + */ + public static final int BUFFERFORMAT_INT1D = INT1D|0x0000; + /** + * int[]で0-255のグレイスケール画像 + */ + public static final int BUFFERFORMAT_INT1D_GLAY_8 = INT1D|0x0001; + /** + * int[]で特に値範囲を定めない + */ + public static final int BUFFERFORMAT_INT1D_BIN_8 = INT1D|0x0002; + /** + * int[]で、XRGB32の32ビットで画素が格納されている。 + */ + public static final int BUFFERFORMAT_INT1D_X8R8G8B8_32 = INT1D|0x0102; + + + /** + * バッファオブジェクトを返します。 + * @return + */ public Object getBuffer(); + /** + * バッファオブジェクトの形式を返します。 + * @return + */ public int getBufferType(); + /** + * バッファオブジェクトの形式が、i_type_valueにが一致するか返します。 + * @param i_type_value + * @return + */ public boolean isEqualBufferType(int i_type_value); } diff --git a/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java b/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java index dbbc5d1..d1cd080 100644 --- a/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java +++ b/src/jp/nyatla/nyartoolkit/core/rasterreader/NyARBufferReader.java @@ -35,10 +35,15 @@ public class NyARBufferReader implements INyARBufferReader { protected Object _buffer; protected int _buffer_type; + protected NyARBufferReader() + { + return; + } public NyARBufferReader(Object i_buffer,int i_buffer_type) { this._buffer=i_buffer; this._buffer_type=i_buffer_type; + return; } public Object getBuffer() { diff --git a/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java b/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java index 7338df2..b678fff 100644 --- a/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java +++ b/src/jp/nyatla/nyartoolkit/core/transmat/rotmatrix/NyARRotMatrix_ARToolKit.java @@ -54,6 +54,7 @@ public class NyARRotMatrix_ARToolKit extends NyARRotMatrix } final private NyARRotVector __initRot_vec1; final private NyARRotVector __initRot_vec2; + @@ -126,11 +127,12 @@ public class NyARRotMatrix_ARToolKit extends NyARRotMatrix double sina, cosa, sinb,cosb,sinc, cosc; if (this.m22 > 1.0) {// if( rot[2][2] > 1.0 ) { - this.m22 = 1.0;// rot[2][2] = 1.0; + cosb = 1.0;// rot[2][2] = 1.0; } else if (this.m22 < -1.0) {// }else if( rot[2][2] < -1.0 ) { - this.m22 = -1.0;// rot[2][2] = -1.0; + cosb = -1.0;// rot[2][2] = -1.0; + }else{ + cosb =this.m22;// cosb = rot[2][2]; } - cosb =this.m22;// cosb = rot[2][2]; b = Math.acos(cosb); sinb =Math.sin(b); final double rot02=this.m02; diff --git a/src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint.java b/src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint.java index 13ada74..7ac8d4a 100644 --- a/src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint.java +++ b/src/jp/nyatla/nyartoolkit/core/types/NyARIntPoint.java @@ -50,4 +50,13 @@ public class NyARIntPoint } return ret; } + public static void copyArray(final NyARIntPoint[] i_from,NyARIntPoint[] i_to) + { + for(int i=i_from.length-1;i>=0;i--) + { + i_to[i].x=i_from[i].x; + i_to[i].y=i_from[i].y; + } + return; + } } diff --git a/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntPointStack.java b/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntPointStack.java index e0c5b93..40c9dec 100644 --- a/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntPointStack.java +++ b/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntPointStack.java @@ -31,7 +31,7 @@ */ package jp.nyatla.nyartoolkit.core.types.stack; -import jp.nyatla.nyartoolkit.NyARException; + import jp.nyatla.nyartoolkit.core.types.*; import jp.nyatla.utils.NyObjectStack; diff --git a/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntRectStack.java b/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntRectStack.java index ae8ce84..079d21d 100644 --- a/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntRectStack.java +++ b/src/jp/nyatla/nyartoolkit/core/types/stack/NyARIntRectStack.java @@ -31,7 +31,7 @@ */ package jp.nyatla.nyartoolkit.core.types.stack; -import jp.nyatla.nyartoolkit.NyARException; + import jp.nyatla.nyartoolkit.core.types.NyARIntRect; import jp.nyatla.utils.NyObjectStack; diff --git a/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/NyARRasterDetector_QrCodeEdge.java b/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/NyARRasterDetector_QrCodeEdge.java index 53cf6f7..4d786c3 100644 --- a/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/NyARRasterDetector_QrCodeEdge.java +++ b/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/NyARRasterDetector_QrCodeEdge.java @@ -89,7 +89,7 @@ public class NyARRasterDetector_QrCodeEdge public void analyzeRaster(INyARRaster i_input) throws NyARException { INyARBufferReader buffer_reader=i_input.getBufferReader(); - assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8)); + assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8)); // 結果をクリア this._result.clear(); @@ -100,11 +100,12 @@ public class NyARRasterDetector_QrCodeEdge w1 = b1 = w2 = b2 = w3 = b3 = 0; NyARIntRect item; - int[] line; + int[] raster_buf=(int[])buffer_reader.getBuffer(); + int line_ptr; int s_pos, b2_spos,b3_spos; b2_spos=0; for (int y = size.h - 1-8; y >= 8; y--) { - line = ((int[][]) buffer_reader.getBuffer())[y]; + line_ptr = y*size.w; x = size.w - 1; s_pos=0; int token_id=0; @@ -114,7 +115,7 @@ public class NyARRasterDetector_QrCodeEdge // w1の特定 w1 = 0; for (; x >= 0; x--) { - if (line[x] == 0) { + if (raster_buf[line_ptr+x] == 0) { // 検出条件確認:w1は2以上欲しいな。 if (!check_w1(w1)) { // 条件不十分 @@ -133,7 +134,7 @@ public class NyARRasterDetector_QrCodeEdge b1 = 0; s_pos = x; for (; x >= 0; x--) { - if (line[x] > 0) { + if (raster_buf[line_ptr+x] > 0) { // 検出条件確認:b1は1以上欲しいな。 if (!check_b1(b1)){ //条件不十分→白検出からやり直し @@ -151,7 +152,7 @@ public class NyARRasterDetector_QrCodeEdge // w2の特定 w2 = 0; for (; x >= 0; x--) { - if (line[x] == 0) { + if (raster_buf[line_ptr+x] == 0) { // 検出条件確認:w2*10/b1は80-120以上欲しいな。 if (!check_w2(b1,w2)) { //条件不十分→w2→w1として、b1を解析 @@ -173,7 +174,7 @@ public class NyARRasterDetector_QrCodeEdge b2 = 0; b2_spos=x; for (; x >= 0; x--) { - if (line[x] > 0){ + if (raster_buf[line_ptr+x] > 0){ //条件:(w1+b1)/2の2~4倍 if (!check_b2(b1,b2)) { @@ -201,7 +202,7 @@ public class NyARRasterDetector_QrCodeEdge // w3の特定 w3 = 0; for (; x >= 0; x--) { - if (line[x] == 0){ + if (raster_buf[line_ptr+x] == 0){ if (!check_w3(w2,w3)) { //w2→w1,b2->b1として解析しなおす。 if(check_w1(w2) && check_b1(b2)){ @@ -228,7 +229,7 @@ public class NyARRasterDetector_QrCodeEdge b3 = 0; b3_spos=x; for (; x >= 0; x--) { - if (line[x] > 0) { + if (raster_buf[line_ptr+x] > 0) { // 検出条件確認 if (!check_b3(b3,b1)) { if(check_w1(w2) && check_b1(b2)){ diff --git a/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_DiffHistgram.java b/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_DiffHistgram.java index 38f1ee1..9fcc294 100644 --- a/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_DiffHistgram.java +++ b/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_DiffHistgram.java @@ -48,7 +48,7 @@ public class NyARRasterThresholdAnalyzer_DiffHistgram implements INyARRasterThre { } - private int createHistgram(int[][] in_buf,NyARIntSize i_size, int[] o_histgram) throws NyARException + private int createHistgram(int[] in_buf,NyARIntSize i_size, int[] o_histgram) throws NyARException { int[][] fil1={ {-1,-2,-1}, @@ -63,11 +63,11 @@ public class NyARRasterThresholdAnalyzer_DiffHistgram implements INyARRasterThre int sam1,sam2; for (int y = 1; y < i_size.h-1; y++) { for (int x = 1; x < i_size.w-1; x++) { - int v = in_buf[y][x]; + int v = in_buf[y* i_size.w+x]; sam1=sam2=0; for(int yy=0;yy<3;yy++){ for(int xx=0;xx<3;xx++){ - int v2=in_buf[y+yy-1][x+xx-1]; + int v2=in_buf[(y+yy-1)* i_size.w+(x+xx-1)]; sam1+=v2*fil1[xx][yy]; sam2+=v2*fil1[yy][xx]; } @@ -90,9 +90,9 @@ public class NyARRasterThresholdAnalyzer_DiffHistgram implements INyARRasterThre public void analyzeRaster(INyARRaster i_input) throws NyARException { final INyARBufferReader buffer_reader=i_input.getBufferReader(); - assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); + assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); int[] histgram = new int[256]; - this._threshold = createHistgram((int[][])buffer_reader.getBuffer(),i_input.getSize(), histgram); + this._threshold = createHistgram((int[])buffer_reader.getBuffer(),i_input.getSize(), histgram); } /** @@ -105,20 +105,20 @@ public class NyARRasterThresholdAnalyzer_DiffHistgram implements INyARRasterThre { INyARBufferReader in_buffer_reader=i_input.getBufferReader(); INyARBufferReader out_buffer_reader=i_output.getBufferReader(); - assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); - assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); + assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); + assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); NyARIntSize size = i_output.getSize(); - int[][] out_buf = (int[][]) out_buffer_reader.getBuffer(); + int[] out_buf = (int[]) out_buffer_reader.getBuffer(); // 0で塗りつぶし for (int y = 0; y < size.h; y++) { for (int x = 0; x < size.w; x++) { - out_buf[y][x] = 0; + out_buf[y* size.w+x] = 0; } } // ヒストグラムを計算 int[] histgram = new int[256]; - int threshold = createHistgram((int[][])in_buffer_reader.getBuffer(),i_input.getSize(), histgram); + int threshold = createHistgram((int[])in_buffer_reader.getBuffer(),i_input.getSize(), histgram); // ヒストグラムの最大値を出す int max_v = 0; @@ -129,17 +129,17 @@ public class NyARRasterThresholdAnalyzer_DiffHistgram implements INyARRasterThre } // 目盛り for (int i = 0; i < size.h; i++) { - out_buf[i][0] = 128; - out_buf[i][128] = 128; - out_buf[i][255] = 128; + out_buf[i* size.w+0] = 128; + out_buf[i* size.w+128] = 128; + out_buf[i* size.w+255] = 128; } // スケーリングしながら描画 for (int i = 0; i < 255; i++) { - out_buf[histgram[i] * (size.h - 1) / max_v][i] = 255; + out_buf[(histgram[i] * (size.h - 1) / max_v)* size.w+i] = 255; } // 値 for (int i = 0; i < size.h; i++) { - out_buf[i][threshold] = 255; + out_buf[i* size.w+threshold] = 255; } return; } diff --git a/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_PTile.java b/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_PTile.java index 5808614..e1f9198 100644 --- a/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_PTile.java +++ b/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_PTile.java @@ -59,7 +59,7 @@ public class NyARRasterThresholdAnalyzer_PTile implements INyARRasterThresholdAn private int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram) throws NyARException { - int[][] in_buf = (int[][]) i_reader.getBuffer(); + int[] in_buf = (int[]) i_reader.getBuffer(); int[] histgram = o_histgram; // ヒストグラムを作成 @@ -70,7 +70,7 @@ public class NyARRasterThresholdAnalyzer_PTile implements INyARRasterThresholdAn for (int y = 0; y < i_size.h; y++) { int sum2 = 0; for (int x = 0; x < i_size.w; x++) { - int v = in_buf[y][x]; + int v = in_buf[y* i_size.w+x]; histgram[v]++; sum2 += v; } @@ -105,7 +105,7 @@ public class NyARRasterThresholdAnalyzer_PTile implements INyARRasterThresholdAn public void analyzeRaster(INyARRaster i_input) throws NyARException { final INyARBufferReader buffer_reader=i_input.getBufferReader(); - assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); + assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); int[] histgram = new int[256]; this._threshold = createHistgram(buffer_reader,i_input.getSize(), histgram); } @@ -120,15 +120,15 @@ public class NyARRasterThresholdAnalyzer_PTile implements INyARRasterThresholdAn { INyARBufferReader in_buffer_reader=i_input.getBufferReader(); INyARBufferReader out_buffer_reader=i_output.getBufferReader(); - assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); - assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); + assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); + assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); NyARIntSize size = i_output.getSize(); - int[][] out_buf = (int[][]) out_buffer_reader.getBuffer(); + int[] out_buf = (int[]) out_buffer_reader.getBuffer(); // 0で塗りつぶし for (int y = 0; y < size.h; y++) { for (int x = 0; x < size.w; x++) { - out_buf[y][x] = 0; + out_buf[y* size.w+x] = 0; } } // ヒストグラムを計算 @@ -144,17 +144,17 @@ public class NyARRasterThresholdAnalyzer_PTile implements INyARRasterThresholdAn } // 目盛り for (int i = 0; i < size.h; i++) { - out_buf[i][0] = 128; - out_buf[i][128] = 128; - out_buf[i][255] = 128; + out_buf[i* size.w+0] = 128; + out_buf[i* size.w+128] = 128; + out_buf[i* size.w+255] = 128; } // スケーリングしながら描画 for (int i = 0; i < 255; i++) { - out_buf[histgram[i] * (size.h - 1) / max_v][i] = 255; + out_buf[(histgram[i] * (size.h - 1) / max_v)* size.w+i] = 255; } // 値 for (int i = 0; i < size.h; i++) { - out_buf[i][threshold] = 255; + out_buf[i* size.w+threshold] = 255; } return; } diff --git a/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_SlidePTile.java b/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_SlidePTile.java index 09676da..eba8ad6 100644 --- a/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_SlidePTile.java +++ b/src/jp/nyatla/nyartoolkit/core2/rasteranalyzer/threshold/NyARRasterThresholdAnalyzer_SlidePTile.java @@ -61,7 +61,7 @@ public class NyARRasterThresholdAnalyzer_SlidePTile implements INyARRasterThresh private int createHistgram(INyARBufferReader i_reader,NyARIntSize i_size, int[] o_histgram) throws NyARException { - int[][] in_buf = (int[][]) i_reader.getBuffer(); + int[] in_buf = (int[]) i_reader.getBuffer(); int[] histgram = o_histgram; // ヒストグラムを作成 @@ -72,7 +72,7 @@ public class NyARRasterThresholdAnalyzer_SlidePTile implements INyARRasterThresh for (int y = 0; y < i_size.h; y++) { int sum2 = 0; for (int x = 0; x < i_size.w; x++) { - int v = in_buf[y][x]; + int v = in_buf[y* i_size.w+x]; histgram[v]++; sum2 += v; } @@ -106,7 +106,7 @@ public class NyARRasterThresholdAnalyzer_SlidePTile implements INyARRasterThresh public void analyzeRaster(INyARRaster i_input) throws NyARException { final INyARBufferReader buffer_reader=i_input.getBufferReader(); - assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); + assert (buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); int[] histgram = new int[256]; // 閾値の基準値を出す。 @@ -123,16 +123,16 @@ public class NyARRasterThresholdAnalyzer_SlidePTile implements INyARRasterThresh { INyARBufferReader in_buffer_reader=i_input.getBufferReader(); INyARBufferReader out_buffer_reader=i_output.getBufferReader(); - assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); - assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); + assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); + assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); NyARIntSize size = i_output.getSize(); - int[][] out_buf = (int[][]) out_buffer_reader.getBuffer(); + int[] out_buf = (int[]) out_buffer_reader.getBuffer(); // 0で塗りつぶし for (int y = 0; y < size.h; y++) { for (int x = 0; x < size.w; x++) { - out_buf[y][x] = 0; + out_buf[y* size.w+x] = 0; } } // ヒストグラムを計算 @@ -151,17 +151,17 @@ public class NyARRasterThresholdAnalyzer_SlidePTile implements INyARRasterThresh } // 目盛り for (int i = 0; i < size.h; i++) { - out_buf[i][0] = 128; - out_buf[i][128] = 128; - out_buf[i][255] = 128; + out_buf[i* size.w+0] = 128; + out_buf[i* size.w+128] = 128; + out_buf[i* size.w+255] = 128; } // スケーリングしながら描画 for (int i = 0; i < 255; i++) { - out_buf[histgram[i] * (size.h - 1) / max_v][i] = 255; + out_buf[(histgram[i] * (size.h - 1) / max_v)* size.w+i] = 255; } // 値 for (int i = 0; i < size.h; i++) { - out_buf[i][threshold] = 255; + out_buf[i* size.w+threshold] = 255; } return; } diff --git a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/NyARRasterFilter_Edge.java b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/NyARRasterFilter_Edge.java index 5f22fb4..2fe5abb 100644 --- a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/NyARRasterFilter_Edge.java +++ b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/NyARRasterFilter_Edge.java @@ -46,20 +46,20 @@ public class NyARRasterFilter_Edge implements INyARRasterFilter { INyARBufferReader in_buffer_reader=i_input.getBufferReader(); INyARBufferReader out_buffer_reader=i_output.getBufferReader(); - assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); - assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8)); + assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); + assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8)); assert (i_input.getSize().isEqualSize(i_output.getSize()) == true); - int[][] out_buf = (int[][]) out_buffer_reader.getBuffer(); - int[][] in_buf = (int[][]) in_buffer_reader.getBuffer(); + int[] out_buf = (int[]) out_buffer_reader.getBuffer(); + int[] in_buf = (int[]) in_buffer_reader.getBuffer(); int bp = 0; NyARIntSize size = i_output.getSize(); for (int y = 1; y < size.h; y++) { int prev = 128; for (int x = 1; x < size.w; x++) { - int w = in_buf[y][x]; - out_buf[y][x] = (Math.abs(w - prev) + Math.abs(w - in_buf[y - 1][x])) / 2; + int w = in_buf[y* size.w+x]; + out_buf[y* size.w+x] = (Math.abs(w - prev) + Math.abs(w - in_buf[(y - 1)* size.w+x])) / 2; prev = w; bp += 3; } diff --git a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_AreaAverage.java b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_AreaAverage.java index 58f73d8..12bb1a0 100644 --- a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_AreaAverage.java +++ b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_AreaAverage.java @@ -47,8 +47,8 @@ public class NyARRasterFilter_AreaAverage implements INyARRasterFilter_GsToBin public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException { final NyARIntSize size = i_output.getSize(); - final int[][] out_buf = (int[][]) i_output.getBufferReader().getBuffer(); - final int[][] in_buf = (int[][]) i_input.getBufferReader().getBuffer(); + final int[] out_buf = (int[]) i_output.getBufferReader().getBuffer(); + final int[] in_buf = (int[]) i_input.getBufferReader().getBuffer(); assert (i_input.getSize().isEqualSize(i_output.getSize()) == true); assert (size.h % 8 == 0 && size.w % 8 == 0);//暫定実装なので。 @@ -63,7 +63,7 @@ public class NyARRasterFilter_AreaAverage implements INyARRasterFilter_GsToBin sum = nn = 0; for (int yy = y - area; yy < y + area + 1; yy++) { for (int xx = x1 - area; xx < x1 + area; xx++) { - sum += in_buf[yy][xx]; + sum += in_buf[yy*size.w+xx]; nn++; } } @@ -71,15 +71,15 @@ public class NyARRasterFilter_AreaAverage implements INyARRasterFilter_GsToBin for (int x = area; x < x2; x++) { if (!first) { for (int yy = y - area; yy < y + area; yy++) { - sum += in_buf[yy][x + area]; - sum -= in_buf[yy][x - area]; + sum += in_buf[yy*size.w+x + area]; + sum -= in_buf[yy*size.w+x - area]; } } first = false; int th = (sum / nn); - int g = in_buf[y][x]; - out_buf[y][x] = th < g ? 1 : 0; + int g = in_buf[y*size.w+x]; + out_buf[y*size.w+x] = th < g ? 1 : 0; } } return; diff --git a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_Threshold.java b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_Threshold.java index 6992d21..29b0974 100644 --- a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_Threshold.java +++ b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/gs2bin/NyARRasterFilter_Threshold.java @@ -54,14 +54,14 @@ public class NyARRasterFilter_Threshold implements INyARRasterFilter_GsToBin { assert (i_input.getSize().isEqualSize(i_output.getSize()) == true); - final int[][] out_buf = (int[][]) i_output.getBufferReader().getBuffer(); - final int[][] in_buf = (int[][]) i_input.getBufferReader().getBuffer(); + final int[] out_buf = (int[]) i_output.getBufferReader().getBuffer(); + final int[] in_buf = (int[]) i_input.getBufferReader().getBuffer(); int bp = 0; NyARIntSize size = i_output.getSize(); for (int y = 0; y < size.h - 1; y++) { for (int x = 0; x < size.w; x++) { - out_buf[y][x] = in_buf[y][x] >= this._threshold ? 1 : 0; + out_buf[y*size.w+x] = in_buf[y*size.w+x] >= this._threshold ? 1 : 0; bp += 3; } } diff --git a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbAve.java b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbAve.java index f349e12..4ae85a8 100644 --- a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbAve.java +++ b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbAve.java @@ -46,7 +46,7 @@ public class NyARRasterFilter_RgbAve implements INyARRasterFilter_RgbToGs INyARBufferReader out_buffer_reader=i_output.getBufferReader(); assert (i_input.getSize().isEqualSize(i_output.getSize()) == true); - int[][] out_buf = (int[][]) out_buffer_reader.getBuffer(); + int[] out_buf = (int[]) out_buffer_reader.getBuffer(); byte[] in_buf = (byte[]) in_buffer_reader.getBuffer(); NyARIntSize size = i_output.getSize(); @@ -64,23 +64,23 @@ public class NyARRasterFilter_RgbAve implements INyARRasterFilter_RgbToGs return; } - private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size) + private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size) { int bp = 0; for (int y = 0; y < i_size.h; y++) { for (int x = 0; x < i_size.w; x++) { - i_out[y][x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3; + i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3; bp += 3; } } return; } - private void convert32BitRgbx(byte[] i_in, int[][] i_out, NyARIntSize i_size) + private void convert32BitRgbx(byte[] i_in, int[] i_out, NyARIntSize i_size) { int bp = 0; for (int y = 0; y < i_size.h; y++) { for (int x = 0; x < i_size.w; x++) { - i_out[y][x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3; + i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff)) / 3; bp += 4; } } diff --git a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbMul.java b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbMul.java index 5f11bc0..74f3e40 100644 --- a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbMul.java +++ b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbMul.java @@ -46,7 +46,7 @@ public class NyARRasterFilter_RgbMul implements INyARRasterFilter_RgbToGs INyARBufferReader out_buffer_reader=i_output.getBufferReader(); assert (i_input.getSize().isEqualSize(i_output.getSize()) == true); - int[][] out_buf = (int[][]) out_buffer_reader.getBuffer(); + int[] out_buf = (int[]) out_buffer_reader.getBuffer(); byte[] in_buf = (byte[]) in_buffer_reader.getBuffer(); NyARIntSize size = i_output.getSize(); @@ -61,12 +61,12 @@ public class NyARRasterFilter_RgbMul implements INyARRasterFilter_RgbToGs return; } - private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size) + private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size) { int bp = 0; for (int y = 0; y < i_size.h; y++) { for (int x = 0; x < i_size.w; x++) { - i_out[y][x] = ((i_in[bp] & 0xff) * (i_in[bp + 1] & 0xff) * (i_in[bp + 2] & 0xff)) >> 16; + i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) * (i_in[bp + 1] & 0xff) * (i_in[bp + 2] & 0xff)) >> 16; bp += 3; } } diff --git a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbOr.java b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbOr.java index 742133b..e639a54 100644 --- a/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbOr.java +++ b/src/jp/nyatla/nyartoolkit/core2/rasterfilter/rgb2gs/NyARRasterFilter_RgbOr.java @@ -46,7 +46,7 @@ public class NyARRasterFilter_RgbOr implements INyARRasterFilter_RgbToGs INyARBufferReader out_buffer_reader=i_output.getBufferReader(); assert (i_input.getSize().isEqualSize(i_output.getSize()) == true); - final int[][] out_buf = (int[][]) out_buffer_reader.getBuffer(); + final int[] out_buf = (int[]) out_buffer_reader.getBuffer(); final byte[] in_buf = (byte[]) in_buffer_reader.getBuffer(); NyARIntSize size = i_output.getSize(); @@ -61,12 +61,12 @@ public class NyARRasterFilter_RgbOr implements INyARRasterFilter_RgbToGs return; } - private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size) + private void convert24BitRgb(byte[] i_in, int[] i_out, NyARIntSize i_size) { int bp = 0; for (int y = 0; y < i_size.h; y++) { for (int x = 0; x < i_size.w; x++) { - i_out[y][x] = ((i_in[bp] & 0xff) | (i_in[bp + 1] & 0xff) | (i_in[bp + 2] & 0xff)); + i_out[y*i_size.w+x] = ((i_in[bp] & 0xff) | (i_in[bp + 1] & 0xff) | (i_in[bp + 2] & 0xff)); bp += 3; } } diff --git a/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java b/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java new file mode 100644 index 0000000..1e27263 --- /dev/null +++ b/src/jp/nyatla/nyartoolkit/detector/NyARCustomSingleDetectMarker.java @@ -0,0 +1,247 @@ +/* + * 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.detector; + +import jp.nyatla.nyartoolkit.NyARException; +import jp.nyatla.nyartoolkit.core.*; +import jp.nyatla.nyartoolkit.core.match.*; +import jp.nyatla.nyartoolkit.core.param.NyARParam; +import jp.nyatla.nyartoolkit.core.pickup.*; +import jp.nyatla.nyartoolkit.core.raster.rgb.*; +import jp.nyatla.nyartoolkit.core.raster.*; +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.*; + +/** + * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。 + * + */ +public class NyARCustomSingleDetectMarker +{ + private static final int AR_SQUARE_MAX = 100; + + private boolean _is_continue = false; + private NyARMatchPatt_Color_WITHOUT_PCA _match_patt; + private INyARSquareDetector _square_detect; + + private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX); + + private NyARCode _code; + + protected INyARTransMat _transmat; + + private double _marker_width; + // 検出結果の保存用 + private int _detected_direction; + private double _detected_confidence; + private NyARSquare _detected_square; + private INyARColorPatt _patt; + //画処理用 + private NyARBinRaster _bin_raster; + protected INyARRasterFilter_RgbToBin _tobin_filter; + + /** + * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。 + * + * @param i_param + * カメラパラメータを指定します。 + * @param i_code + * 検出するARCodeを指定します。 + * @param i_marker_width + * ARコードの物理サイズを、ミリメートルで指定します。 + * @param i_filter + * RGB→BIN変換フィルタを指定します。 + * @throws NyARException + */ + public NyARCustomSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width,INyARRasterFilter_RgbToBin i_filter) 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._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(); + //2値画像バッファを作る + this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h); + this._tobin_filter=i_filter; + } + + + /** + * i_imageにマーカー検出処理を実行し、結果を記録します。 + * + * @param i_raster + * マーカーを検出するイメージを指定します。イメージサイズは、カメラパラメータ + * と一致していなければなりません。 + * @return マーカーが検出できたかを真偽値で返します。 + * @throws NyARException + */ + public boolean detectMarkerLite(INyARRgbRaster i_raster) throws NyARException + { + //サイズチェック + if(!this._bin_raster.getSize().isEqualSize(i_raster.getSize())){ + throw new NyARException(); + } + + //ラスタを2値イメージに変換する. + this._tobin_filter.doFilter(i_raster,this._bin_raster); + + + this._detected_square = null; + NyARSquareStack l_square_list = this._square_list; + // スクエアコードを探す + this._square_detect.detectMarker(this._bin_raster, l_square_list); + + + int number_of_square = l_square_list.getLength(); + // コードは見つかった? + 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); + 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(); + if (confidence > c2) { + continue; + } + // もっと一致するマーカーがあったぽい + square_index = i; + direction = this._match_patt.getDirection(); + confidence = c2; + } + // マーカー情報を保存 + this._detected_square = (NyARSquare)l_square_list.getItem(square_index); + this._detected_direction = direction; + this._detected_confidence = confidence; + return true; + } + + /** + * 検出したマーカーの変換行列を計算して、o_resultへ値を返します。 + * 直前に実行したdetectMarkerLiteが成功していないと使えません。 + * + * @param o_result + * 変換行列を受け取るオブジェクトを指定します。 + * @throws NyARException + */ + public void getTransmationMatrix(NyARTransMatResult o_result) throws NyARException + { + // 一番一致したマーカーの位置とかその辺を計算 + if (this._is_continue) { + this._transmat.transMatContinue(this._detected_square,this._detected_direction,this._marker_width, o_result); + } else { + this._transmat.transMat(this._detected_square,this._detected_direction,this._marker_width, o_result); + } + return; + } + /** + * 画面上のマーカ頂点情報を配列へ取得します。 + * @param o_point + * 4要素以上の配列を指定して下さい。先頭の4要素に値がコピーされます。 + */ + public void getSquarePosition(NyARIntPoint[] o_point) + { + NyARIntPoint.copyArray(this._detected_square.imvertex,o_point); + return; + } + /** + * 画面上のマーカ頂点情報を配列へのリファレンスを返します。 + * 返されたオブジェクトはクラスに所有し続けられています。クラスのメンバ関数を実行すると内容が書き変わります。 + * 外部でデータをストックする場合は、getSquarePositionで複製して下さい。 + * @return + */ + public NyARIntPoint[] refSquarePosition() + { + return this._detected_square.imvertex; + } + + + /** + * 検出したマーカーの一致度を返します。 + * + * @return マーカーの一致度を返します。0~1までの値をとります。 一致度が低い場合には、誤認識の可能性が高くなります。 + * @throws NyARException + */ + public double getConfidence() + { + return this._detected_confidence; + } + + /** + * 検出したマーカーの方位を返します。 + * + * @return 0,1,2,3の何れかを返します。 + */ + public int getDirection() + { + return this._detected_direction; + } + + /** + * getTransmationMatrixの計算モードを設定します。 初期値はTRUEです。 + * + * @param i_is_continue + * TRUEなら、transMatCont互換の計算をします。 FALSEなら、transMat互換の計算をします。 + */ + public void setContinueMode(boolean i_is_continue) + { + this._is_continue = i_is_continue; + } +} diff --git a/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java b/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java index 91c09a9..2545bb6 100644 --- a/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java +++ b/src/jp/nyatla/nyartoolkit/detector/NyARSingleDetectMarker.java @@ -33,44 +33,16 @@ package jp.nyatla.nyartoolkit.detector; import jp.nyatla.nyartoolkit.NyARException; import jp.nyatla.nyartoolkit.core.*; -import jp.nyatla.nyartoolkit.core.match.*; import jp.nyatla.nyartoolkit.core.param.NyARParam; -import jp.nyatla.nyartoolkit.core.pickup.*; import jp.nyatla.nyartoolkit.core.raster.rgb.*; -import jp.nyatla.nyartoolkit.core.raster.*; -import jp.nyatla.nyartoolkit.core.transmat.*; -import jp.nyatla.nyartoolkit.core.types.NyARIntSize; import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.NyARRasterFilter_ARToolkitThreshold; /** * 画像からARCodeに最も一致するマーカーを1個検出し、その変換行列を計算するクラスです。 * */ -public class NyARSingleDetectMarker +public class NyARSingleDetectMarker extends NyARCustomSingleDetectMarker { - private static final int AR_SQUARE_MAX = 100; - - private boolean _is_continue = false; - private NyARMatchPatt_Color_WITHOUT_PCA _match_patt; - private INyARSquareDetector _square_detect; - - private final NyARSquareStack _square_list = new NyARSquareStack(AR_SQUARE_MAX); - - private NyARCode _code; - - protected INyARTransMat _transmat; - - private double _marker_width; - - // 検出結果の保存用 - private int _detected_direction; - - private double _detected_confidence; - - private NyARSquare _detected_square; - - private INyARColorPatt _patt; - /** * 検出するARCodeとカメラパラメータから、1個のARCodeを検出するNyARSingleDetectMarkerインスタンスを作ります。 * @@ -84,23 +56,9 @@ public class NyARSingleDetectMarker */ public NyARSingleDetectMarker(NyARParam i_param, NyARCode i_code, double i_marker_width) 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._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(); - //2値画像バッファを作る - this._bin_raster=new NyARBinRaster(scr_size.w,scr_size.h); + super(i_param,i_code,i_marker_width,new NyARRasterFilter_ARToolkitThreshold(100)); } - NyARBinRaster _bin_raster; - NyARRasterFilter_ARToolkitThreshold _tobin_filter=new NyARRasterFilter_ARToolkitThreshold(100); /** * i_imageにマーカー検出処理を実行し、結果を記録します。 @@ -113,114 +71,7 @@ public class NyARSingleDetectMarker */ public boolean detectMarkerLite(INyARRgbRaster i_raster,int i_threshold) throws NyARException { - //サイズチェック - if(!this._bin_raster.getSize().isEqualSize(i_raster.getSize())){ - throw new NyARException(); - } - - //ラスタを2値イメージに変換する. - this._tobin_filter.setThreshold(i_threshold); - this._tobin_filter.doFilter(i_raster,this._bin_raster); - - - this._detected_square = null; - NyARSquareStack l_square_list = this._square_list; - // スクエアコードを探す - this._square_detect.detectMarker(this._bin_raster, l_square_list); - - - int number_of_square = l_square_list.getLength(); - // コードは見つかった? - 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); - 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(); - if (confidence > c2) { - continue; - } - // もっと一致するマーカーがあったぽい - square_index = i; - direction = this._match_patt.getDirection(); - confidence = c2; - } - // マーカー情報を保存 - this._detected_square = (NyARSquare)l_square_list.getItem(square_index); - this._detected_direction = direction; - this._detected_confidence = confidence; - return true; - } - - /** - * 検出したマーカーの変換行列を計算して、o_resultへ値を返します。 - * 直前に実行したdetectMarkerLiteが成功していないと使えません。 - * - * @param o_result - * 変換行列を受け取るオブジェクトを指定します。 - * @throws NyARException - */ - public void getTransmationMatrix(NyARTransMatResult o_result) throws NyARException - { - // 一番一致したマーカーの位置とかその辺を計算 - if (this._is_continue) { - this._transmat.transMatContinue(this._detected_square,this._detected_direction,this._marker_width, o_result); - } else { - this._transmat.transMat(this._detected_square,this._detected_direction,this._marker_width, o_result); - } - return; - } - - /** - * 検出したマーカーの一致度を返します。 - * - * @return マーカーの一致度を返します。0~1までの値をとります。 一致度が低い場合には、誤認識の可能性が高くなります。 - * @throws NyARException - */ - public double getConfidence() - { - return this._detected_confidence; - } - - /** - * 検出したマーカーの方位を返します。 - * - * @return 0,1,2,3の何れかを返します。 - */ - public int getDirection() - { - return this._detected_direction; - } - - /** - * getTransmationMatrixの計算モードを設定します。 初期値はTRUEです。 - * - * @param i_is_continue - * TRUEなら、transMatCont互換の計算をします。 FALSEなら、transMat互換の計算をします。 - */ - public void setContinueMode(boolean i_is_continue) - { - this._is_continue = i_is_continue; + ((NyARRasterFilter_ARToolkitThreshold)this._tobin_filter).setThreshold(i_threshold); + return super.detectMarkerLite(i_raster); } } diff --git a/src/jp/nyatla/utils/NyObjectStack.java b/src/jp/nyatla/utils/NyObjectStack.java index ccb4998..734e754 100644 --- a/src/jp/nyatla/utils/NyObjectStack.java +++ b/src/jp/nyatla/utils/NyObjectStack.java @@ -52,7 +52,7 @@ public abstract class NyObjectStack * * @param i_array */ - public NyObjectStack(Object[] i_array) + protected NyObjectStack(Object[] i_array) { // ポインタだけははじめに確保しておく this._items = i_array; diff --git a/src/jp/nyatla/utils/j2se/LabelingBufferdImage.java b/src/jp/nyatla/utils/j2se/LabelingBufferdImage.java index ebc4988..f8e065d 100644 --- a/src/jp/nyatla/utils/j2se/LabelingBufferdImage.java +++ b/src/jp/nyatla/utils/j2se/LabelingBufferdImage.java @@ -122,7 +122,7 @@ public class LabelingBufferdImage extends BufferedImage public void drawImage(NyARGrayscaleRaster i_raster) throws NyARException { - assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8); + assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8); int w = this.getWidth(); int h = this.getHeight(); @@ -132,12 +132,12 @@ public class LabelingBufferdImage extends BufferedImage throw new NyARException(); } - int[][] limg; + int[] limg; // イメージの描画 - limg = (int[][]) i_raster.getBufferReader().getBuffer(); + limg = (int[]) i_raster.getBufferReader().getBuffer(); for (int i = 0; i < h; i++) { for (int i2 = 0; i2 < w; i2++) { - this.setRGB(i2, i,limg[i][i2]); + this.setRGB(i2, i,limg[i*w+i2]); } } return; @@ -149,7 +149,7 @@ public class LabelingBufferdImage extends BufferedImage */ public void drawImage(NyARBinRaster i_raster) throws NyARException { - assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8); + assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8); int w = this.getWidth(); int h = this.getHeight(); @@ -159,12 +159,12 @@ public class LabelingBufferdImage extends BufferedImage throw new NyARException(); } - int[][] limg; + int[] limg; // イメージの描画 - limg = (int[][]) i_raster.getBufferReader().getBuffer(); + limg = (int[]) i_raster.getBufferReader().getBuffer(); for (int i = 0; i < h; i++) { for (int i2 = 0; i2 < w; i2++) { - this.setRGB(i2, i, limg[i][i2] > 0 ? 255 : 0); + this.setRGB(i2, i, limg[i*w+i2] > 0 ? 255 : 0); } } return; @@ -186,12 +186,12 @@ public class LabelingBufferdImage extends BufferedImage } int[] index_array=i_image.getIndexArray(); - int[][] limg; + int[] limg; // イメージの描画 - limg = (int[][]) i_image.getBufferReader().getBuffer(); + limg = (int[]) i_image.getBufferReader().getBuffer(); for (int i = 0; i < h; i++) { for (int i2 = 0; i2 < w; i2++) { - int t=limg[i][i2]-1; + int t=limg[i*w+i2]-1; if(t<0){ t=0; }else{