Browse Subversion Repository
Contents of /nyar4psg/trunk/examples/test/MultiMarkerTest/MultiMarkerTest.pde
Parent Directory
| Revision Log
Revision 1158 -
( show annotations)
( download)
Tue Jan 6 07:38:11 2015 UTC
(9 years, 2 months ago)
by nyatla
File size: 3208 byte(s)
パッケージ構成をProcessing2.0向けに更新
| 1 |
/* |
| 2 |
MultiMarker class function test program |
| 3 |
|
| 4 |
*/ |
| 5 |
import processing.video.*; |
| 6 |
import jp.nyatla.nyar4psg.*; |
| 7 |
import processing.opengl.*; |
| 8 |
|
| 9 |
PFont font=createFont("FFScala", 32); |
| 10 |
Capture cam; |
| 11 |
MultiMarker nya; |
| 12 |
|
| 13 |
void setup() { |
| 14 |
size(640,480,P3D); |
| 15 |
colorMode(RGB, 100); |
| 16 |
cam=new Capture(this,width,height); |
| 17 |
nya=new MultiMarker(this,width,height,"camera_para.dat",new NyAR4PsgConfig(NyAR4PsgConfig.CS_RIGHT_HAND,NyAR4PsgConfig.TM_NYARTK)); |
| 18 |
nya.setARClipping(100,1000); |
| 19 |
nya.setConfidenceThreshold(0.6); |
| 20 |
nya.addARMarker("patt.hiro",80); |
| 21 |
nya.addARMarker("patt.kanji",80); |
| 22 |
nya.addNyIdMarker(31,80); |
| 23 |
println(nya.VERSION); //バージョンの表示 |
| 24 |
cam.start(); |
| 25 |
} |
| 26 |
int c=0; |
| 27 |
void draw() { |
| 28 |
c++; |
| 29 |
if (cam.available() !=true) { |
| 30 |
return; |
| 31 |
} |
| 32 |
background(255); |
| 33 |
cam.read(); |
| 34 |
//バックグラウンドを描画 |
| 35 |
nya.drawBackground(cam); |
| 36 |
nya.detect(cam); |
| 37 |
if(nya.isExistMarker(0)){ |
| 38 |
nya.beginTransform(0);//マーカ座標系に設定 |
| 39 |
{ |
| 40 |
drawBox(255,0,0); |
| 41 |
drawMarkerXYPos(0); |
| 42 |
} |
| 43 |
nya.endTransform(); //マーカ座標系を終了 |
| 44 |
drawMarkerPatt(0); |
| 45 |
drawVertex(0); |
| 46 |
//マーカのスクリーン座標を中心に円を書く |
| 47 |
PVector p=nya.marker2ScreenCoordSystem(0,0,0,0); |
| 48 |
noFill(); |
| 49 |
ellipse(p.x,p.y,200,200); |
| 50 |
} |
| 51 |
if(nya.isExistMarker(1)){ |
| 52 |
nya.beginTransform(1);//マーカ座標系に設定 |
| 53 |
{ |
| 54 |
drawBox(0,255,0); |
| 55 |
drawMarkerXYPos(1); |
| 56 |
} |
| 57 |
nya.endTransform(); //マーカ座標系を終了 |
| 58 |
drawMarkerPatt(1); |
| 59 |
drawVertex(1); |
| 60 |
} |
| 61 |
if(nya.isExistMarker(2)){ |
| 62 |
nya.beginTransform(2);//マーカ座標系に設定 |
| 63 |
{ |
| 64 |
drawBox(0,0,255); |
| 65 |
drawMarkerXYPos(2); |
| 66 |
println(nya.getLife(2)); |
| 67 |
} |
| 68 |
nya.endTransform(); //マーカ座標系を終了 |
| 69 |
drawMarkerPatt(2); |
| 70 |
drawVertex(2); |
| 71 |
} |
| 72 |
|
| 73 |
} |
| 74 |
void drawBox(int ir,int ig,int ib) |
| 75 |
{ |
| 76 |
pushMatrix(); |
| 77 |
drawgrid(); |
| 78 |
fill(ir,ig,ib); |
| 79 |
stroke(255,200,0); |
| 80 |
translate(0,0,20); |
| 81 |
box(40); |
| 82 |
noFill(); |
| 83 |
translate(0,0,-20); |
| 84 |
rect(-40,-40,80,80); |
| 85 |
popMatrix(); |
| 86 |
} |
| 87 |
|
| 88 |
//この関数は、マーカパターンを描画します。 |
| 89 |
void drawMarkerPatt(int id) |
| 90 |
{ |
| 91 |
PImage p=nya.pickupMarkerImage(id, |
| 92 |
40,40, |
| 93 |
-40,40, |
| 94 |
-40,-40, |
| 95 |
40,-40, |
| 96 |
100,100); |
| 97 |
// PImage p=nya.pickupRectMarkerImage(id,-40,-40,80,80,100,100); |
| 98 |
image(p,id*100,0); |
| 99 |
} |
| 100 |
|
| 101 |
//この関数は、マーカ平面上の点を描画します。 |
| 102 |
void drawMarkerXYPos(int id) |
| 103 |
{ |
| 104 |
pushMatrix(); |
| 105 |
PVector pos=nya.screen2MarkerCoordSystem(id,mouseX,mouseY); |
| 106 |
translate(pos.x,pos.y,0); |
| 107 |
noFill(); |
| 108 |
stroke(0,0,100); |
| 109 |
ellipse(0,0,20-c%20,20-c%20); |
| 110 |
popMatrix(); |
| 111 |
} |
| 112 |
|
| 113 |
//この関数は、マーカ頂点の情報を描画します。 |
| 114 |
void drawVertex(int id) |
| 115 |
{ |
| 116 |
PVector[] i_v=nya.getMarkerVertex2D(id); |
| 117 |
textFont(font,10.0); |
| 118 |
stroke(100,0,0); |
| 119 |
for(int i=0;i<4;i++){ |
| 120 |
fill(100,0,0); |
| 121 |
ellipse(i_v[i].x,i_v[i].y,6,6); |
| 122 |
fill(0,0,0); |
| 123 |
text("("+i_v[i].x+","+i_v[i].y+")",i_v[i].x,i_v[i].y); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
void drawgrid() |
| 128 |
{ |
| 129 |
pushMatrix(); |
| 130 |
stroke(0); |
| 131 |
strokeWeight(2); |
| 132 |
line(0,0,0,100,0,0); |
| 133 |
textFont(font,20.0); text("X",100,0,0); |
| 134 |
line(0,0,0,0,100,0); |
| 135 |
textFont(font,20.0); text("Y",0,100,0); |
| 136 |
line(0,0,0,0,0,100); |
| 137 |
textFont(font,20.0); text("Z",0,0,100); |
| 138 |
popMatrix(); |
| 139 |
} |
| 140 |
|
| |