Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /nyar4psg/trunk/examples/test/SingleARTKMarkerTest/SingleARTKMarkerTest.pde

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (hide annotations) (download)
Tue Jan 6 07:38:11 2015 UTC (9 years, 3 months ago) by nyatla
File size: 2209 byte(s)
パッケージ構成をProcessing2.0向けに更新

1 nyatla 1158 /*
2     SingleARTKMarker class function test program
3    
4     */
5     import processing.video.*;
6     import jp.nyatla.nyar4psg.*;
7    
8     PFont font=createFont("FFScala", 32);
9     Capture cam;
10     SingleARTKMarker nya;
11    
12     void setup() {
13     size(640,480,P3D);
14     colorMode(RGB, 100);
15     cam=new Capture(this,width,height);
16     nya=new SingleARTKMarker(this,width,height,"camera_para.dat"); //SingleMarker検出インスタンス
17     nya.setARCodes("patt.hiro",80);
18     print(nya.VERSION); //バージョンの表示
19     cam.start();
20     }
21     int c=0;
22     void draw() {
23     c++;
24     if (cam.available() !=true) {
25     return;
26     }
27     background(255);
28     cam.read();
29     nya.drawBackground(cam);//frustumを考慮した背景描画
30     switch(nya.detect(cam)){
31     case SingleARTKMarker.ST_NOMARKER:
32     return;
33     case SingleARTKMarker.ST_NEWMARKER:
34     println("Marker found.");
35     return;
36     case SingleARTKMarker.ST_UPDATEMARKER:
37     break;
38     case SingleARTKMarker.ST_REMOVEMARKER:
39     println("Marker removed.");
40     return;
41     default:
42     return;
43     }
44     nya.beginTransform();//マーカ座標系に設定
45     {
46     setMatrix(nya.getMarkerMatrix());//マーカ姿勢をセット
47     drawBox();
48     drawMarkerXYPos();
49     }
50     nya.endTransform(); //マーカ座標系を終了
51     drawMarkerPatt();
52     drawVertex();
53    
54     }
55     void drawBox()
56     {
57     pushMatrix();
58     fill(0);
59     stroke(255,200,0);
60     translate(0,0,20);
61     box(40);
62     noFill();
63     translate(0,0,-20);
64     rect(-40,-40,80,80);
65     popMatrix();
66     }
67    
68     //この関数は、マーカパターンを描画します。
69     void drawMarkerPatt()
70     {
71     PImage p=nya.pickupMarkerImage(40,40,-40,40,-40,-40,40,-40,100,100);
72     image(p,0,0);
73     }
74    
75     //この関数は、マーカ平面上の点を描画します。
76     void drawMarkerXYPos()
77     {
78     pushMatrix();
79     PVector pos=nya.screen2MarkerCoordSystem(mouseX,mouseY);
80     translate(pos.x,pos.y,0);
81     noFill();
82     stroke(0,0,100);
83     ellipse(0,0,20-c%20,20-c%20);
84     popMatrix();
85     }
86    
87     //この関数は、マーカ頂点の情報を描画します。
88     void drawVertex()
89     {
90     PVector[] i_v=nya.getMarkerVertex2D();
91     textFont(font,10.0);
92     stroke(100,0,0);
93     for(int i=0;i<4;i++){
94     fill(100,0,0);
95     ellipse(i_v[i].x,i_v[i].y,6,6);
96     fill(0,0,0);
97     text("("+i_v[i].x+","+i_v[i].y+")",i_v[i].x,i_v[i].y);
98     }
99     }
100    
101    
102    

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26