2 * VFM+ARToolkitテストプログラム
3 * カメラから取り込んだデータからマーカーを検出して、一致度と変換行列を表示します。
5 * airmail(at)ebony.plala.or.jp
8 package jp.nyatla.nyartoolkit.jmf.sample;
12 import javax.media.util.BufferToImage;
13 import javax.media.format.*;
15 import jp.nyatla.nyartoolkit.NyARSingleDetectMarker;
16 import jp.nyatla.nyartoolkit.jmf.utils.*;
20 import jp.nyatla.nyartoolkit.core.*;
21 import jp.nyatla.nyartoolkit.core.transmat.*;
28 public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener
30 private final String CARCODE_FILE ="../../Data/patt.hiro";
31 private final String PARAM_FILE ="../../Data/camera_para.dat";
32 private JmfCameraCapture capture;
33 private NyARSingleDetectMarker nya;
34 private JmfNyARRaster_RGB raster;
35 private NyARTransMatResult trans_mat_result=new NyARTransMatResult();
37 public NyarToolkitLinkTest() throws NyARException,NyARException
39 setTitle("JmfCaptureTest");
40 setBounds(0,0,320+64,240+64);
42 capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
43 capture.setCaptureListener(this);
46 NyARParam ar_param=new NyARParam();
47 NyARCode ar_code =new NyARCode(16,16);
48 ar_param.loadFromARFile(PARAM_FILE);
49 ar_param.changeSize(320,240);
50 nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);
51 ar_code.loadFromARFile(CARCODE_FILE);
53 raster=new JmfNyARRaster_RGB(320,240);
58 public void onUpdateBuffer(Buffer i_buffer)
62 raster.setBuffer(i_buffer);
65 BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
66 Image img=b2i.createImage(i_buffer);
68 Graphics g = getGraphics();
72 boolean is_marker_exist=nya.detectMarkerLite(raster,100);
75 nya.getTransmationMatrix(this.trans_mat_result);
76 atm=this.trans_mat_result.getArray();
79 g.drawImage(img, 32, 32,this);
81 g.drawString("マーカー検出:"+nya.getConfidence(),32,50);
83 for(int i2=0;i2<4;i2++){
84 g.drawString("["+i+"]["+i2+"]"+atm[i][i2],32,50+(1+i2*3+i)*16);
89 g.drawString("マーカー未検出:",32,100);
99 private void startCapture()
107 public static void main(String[] args) {
109 NyarToolkitLinkTest mainwin = new NyarToolkitLinkTest();
110 mainwin.setVisible(true);
111 mainwin.startCapture();