OSDN Git Service

[更新]NyARToolkit/nyatlaブランチ
[nyartoolkit-and/nyartoolkit-and.git] / sample / qt / jp / nyatla / nyartoolkit / qt / sample / NyarToolkitLinkTest.java
1 /**
2  * VFM+ARToolkitテストプログラム
3  * カメラから取り込んだデータからマーカーを検出して、一致度と変換行列を表示します。
4  * (c)2008 A虎@nyatla.jp
5  * airmail(at)ebony.plala.or.jp
6  * http://nyatla.jp/
7  */
8 package jp.nyatla.nyartoolkit.qt.sample;
9
10 import jp.nyatla.nyartoolkit.NyARSingleDetectMarker;
11 import jp.nyatla.nyartoolkit.qt.utils.*;
12 import java.awt.*;
13 import jp.nyatla.nyartoolkit.core.*;
14 import jp.nyatla.nyartoolkit.core.transmat.NyARTransMatResult;
15
16
17
18 public class NyarToolkitLinkTest extends Frame implements QtCaptureListener
19 {
20     private final String CARCODE_FILE ="../../Data/patt.hiro";
21     private final String PARAM_FILE   ="../../Data/camera_para.dat";
22     private QtCameraCapture capture;
23     private NyARSingleDetectMarker nya;
24     private QtNyARRaster_RGB raster;
25     private NyARTransMatResult trans_mat_result=new NyARTransMatResult();
26     
27     public NyarToolkitLinkTest() throws NyARException,NyARException
28     {
29         setTitle("QtCaptureTest");
30         setBounds(0,0,320+64,240+64);     
31         //キャプチャの準備
32         capture=new QtCameraCapture(320,240,30f);
33         capture.setCaptureListener(this);
34         
35         //NyARToolkitの準備
36         NyARParam ar_param=new NyARParam();
37         NyARCode ar_code  =new NyARCode(16,16);
38         ar_param.loadFromARFile(PARAM_FILE);
39         ar_param.changeSize(320,240);
40         nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);
41         ar_code.loadFromARFile(CARCODE_FILE);
42         //キャプチャイメージ用のラスタを準備
43         raster=new QtNyARRaster_RGB(320,240);
44     }
45
46
47     
48     public void onUpdateBuffer(byte[] pixels)
49     {
50         try{
51             //キャプチャしたバッファをラスタにセット
52             raster.setBuffer(pixels);
53
54             //キャプチャしたイメージを表示用に加工
55             Image img= raster.createImage();
56
57             Graphics g = getGraphics();            
58             double[][] atm=null;
59
60             //マーカー検出
61             boolean is_marker_exist=nya.detectMarkerLite(raster,100);
62             if(is_marker_exist){
63                 //変換行列を取得
64                 nya.getTransmationMatrix(this.trans_mat_result);
65                 atm=this.trans_mat_result.getArray();
66             }
67             //情報を画面に書く       
68             g.drawImage(img, 32, 32,this);
69             if(is_marker_exist){
70                 g.drawString("マーカー検出:"+nya.getConfidence(),32,50);
71                 for(int i=0;i<3;i++){
72                     for(int i2=0;i2<4;i2++){
73                         g.drawString("["+i+"]["+i2+"]"+atm[i][i2],32,50+(1+i2*3+i)*16);
74                     }
75                     
76                 }
77             }else{
78                 g.drawString("マーカー未検出:",32,100);
79             }
80         }catch(Exception e){
81             e.printStackTrace();
82         }
83        
84         
85         
86         
87     }
88     private void startCapture()
89     {
90         try{
91             capture.start();
92         }catch(Exception e){
93             e.printStackTrace();
94         }
95     }
96     public static void main(String[] args) {
97         try{
98             NyarToolkitLinkTest mainwin = new NyarToolkitLinkTest();
99             mainwin.setVisible(true);
100             mainwin.startCapture();
101         }catch(Exception e){
102             e.printStackTrace();
103         }
104         
105     }
106
107 }