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.NyARException;
16 import jp.nyatla.nyartoolkit.jmf.utils.*;
20 import jp.nyatla.nyartoolkit.core.*;
21 import jp.nyatla.nyartoolkit.detector.*;
22 import jp.nyatla.nyartoolkit.core.transmat.*;
29 public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener
31 private final String CARCODE_FILE ="../../Data/patt.hiro";
32 private final String PARAM_FILE ="../../Data/camera_para.dat";
33 private JmfCameraCapture capture;
34 private NyARSingleDetectMarker nya;
35 private JmfNyARRaster_RGB raster;
36 private NyARTransMatResult trans_mat_result=new NyARTransMatResult();
38 public NyarToolkitLinkTest() throws NyARException,NyARException
40 setTitle("JmfCaptureTest");
41 setBounds(0,0,320+64,240+64);
43 capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXEL_FORMAT_RGB);
44 capture.setCaptureListener(this);
47 NyARParam ar_param=new NyARParam();
48 NyARCode ar_code =new NyARCode(16,16);
49 ar_param.loadFromARFile(PARAM_FILE);
50 ar_param.changeSize(320,240);
51 nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);
52 ar_code.loadFromARFile(CARCODE_FILE);
54 raster=new JmfNyARRaster_RGB(320,240);
59 public void onUpdateBuffer(Buffer i_buffer)
63 raster.setBuffer(i_buffer);
66 BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
67 Image img=b2i.createImage(i_buffer);
69 Graphics g = getGraphics();
73 boolean is_marker_exist=nya.detectMarkerLite(raster,100);
76 nya.getTransmationMatrix(this.trans_mat_result);
77 atm=this.trans_mat_result.getArray();
80 g.drawImage(img, 32, 32,this);
82 g.drawString("マーカー検出:"+nya.getConfidence(),32,50);
84 for(int i2=0;i2<4;i2++){
85 g.drawString("["+i+"]["+i2+"]"+atm[i][i2],32,50+(1+i2*3+i)*16);
90 g.drawString("マーカー未検出:",32,100);
100 private void startCapture()
108 public static void main(String[] args) {
110 NyarToolkitLinkTest mainwin = new NyarToolkitLinkTest();
111 mainwin.setVisible(true);
112 mainwin.startCapture();