「ofxARToolkitPlusを使う」の編集履歴(バックアップ)一覧はこちら
追加された行は緑色になります。
削除された行は赤色になります。
以下exampleのコメントを意訳してみた。
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
width = 640;
height = 480;
//データフォルダの中に入ってるAllBchThinMarkers.pngからマーカーを印刷しておいて
#ifdef CAMERA_CONNECTED
vidGrabber.initGrabber(width, height);
#else
vidPlayer.loadMovie("marker.mov");
vidPlayer.play();
#endif
colorImage.allocate(width, height);
grayImage.allocate(width, height);
grayThres.allocate(width, height);
// This uses the default camera calibration and marker file
artk.setup(width, height);
//winなら下からカメラキャリブレーションソフトが使えるよ
// The camera calibration file can be created using GML:
// http://graphics.cs.msu.ru/en/science/research/calibration/cpp
// and these instructions:
// http://studierstube.icg.tu-graz.ac.at/doc/pdf/Stb_CamCal.pdf
// This only needs to be done once and will aid with detection
// for the specific camera you are using
// Put that file in the data folder and then call setup like so:
// artk.setup(width, height, "myCamParamFile.cal", "markerboard_480-499.cfg");
// しきい値をセット/Set the threshold
// ARTK+ does the thresholding for us
// We also do it in OpenCV so we can see what it looks like for debugging
threshold = 85;
artk.setThreshold(threshold);
ofBackground(127,127,127);
}
//--------------------------------------------------------------
void testApp::update(){
#ifdef CAMERA_CONNECTED
vidGrabber.grabFrame();
bool bNewFrame = vidGrabber.isFrameNew();
#else
vidPlayer.idleMovie();
bool bNewFrame = vidPlayer.isFrameNew();
#endif
if(bNewFrame) {
#ifdef CAMERA_CONNECTED
colorImage.setFromPixels(vidGrabber.getPixels(), width, height);
#else
colorImage.setFromPixels(vidPlayer.getPixels(), width, height);
#endif
// グレースケールに変換
grayImage = colorImage;
// しきい値を適用して2値化画像をつくる
grayThres = grayImage;
grayThres.threshold(threshold);
// ARtoolにgrayImageを渡す Pass in the new image pixels to artk
artk.update(grayImage.getPixels());
}
}
//--------------------------------------------------------------
void testApp::draw(){
//左のウインドウ/ARウインドウにgrayImageを描画
ofSetColor(0xffffff);
grayImage.draw(0, 0);
ofSetColor(0x666666);
ofDrawBitmapString(ofToString(artk.getNumDetectedMarkers()) + " marker(s) found", 10, 20);
//右のウインドウ/しきい値2値化画像を描画
ofSetColor(0xffffff);
grayThres.draw(640, 0);
ofSetColor(0x666666);
ofDrawBitmapString("Threshold: " + ofToString(threshold), 650, 20);
ofDrawBitmapString("Use the Up/Down keys to adjust the threshold", 650, 40);
// ARTK による描画
// マーカーの位置とIDナンバーを簡単に表示
artk.draw(640, 0);
// ARTK 2D stuff
// ID '0' のマーカーが見つかった場合
// 青いコーナーを指定IDのに描画(条件分岐のサンプル)
int myIndex = artk.getMarkerIndex(0);
if(myIndex >= 0) {
// コーナーの座標を取得
vector<ofPoint> corners;
artk.getDetectedMarkerBorderCorners(myIndex, corners);
// 以下で中心座標もとれる get the center like this:
//
ofPoint center = artk.getDetectedMarkerCenter(myIndex);
ofSetColor(0x0000ff);
for(int i=0;i<corners.size();i++) {
ofCircle(corners[i].x, corners[i].y, 10);
}
}
// ARTK 3D stuff
// First apply the projection matrix once
//まずプロジェクション座標に貼付ける
artk.applyProjectionMatrix();
//見つけられたマーカーの数を確かめる
int numDetected = artk.getNumDetectedMarkers();
ofEnableAlphaBlending();
//検出したマーカーの数だけ描画を繰り返す
for(int i=0; i<numDetected; i++) {
//このマーカーのパースにあわせて座標をセットSet the matrix to the perspective of this marker
//原点はマーカーの中央とするThe origin is in the middle of the marker
artk.applyModelMatrix(i);
//マーカーの中心から線をのばす
ofNoFill();
ofSetLineWidth(5);
ofSetColor(0xffffff);
glBegin(GL_LINES);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, 50);
glEnd();
//z軸上に四角形を描画
ofFill();
ofSetColor(255, 255, 0, 50);
for(int i=0; i<10; i++) {
ofRect(-25, -25, 50, 50);//黄色い四角を書いているところ
ofTranslate(0, 0, i*1);
}
}
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
if(key == OF_KEY_UP) {
artk.setThreshold(++threshold);
} else if(key == OF_KEY_DOWN) {
artk.setThreshold(--threshold);
}
#ifdef CAMERA_CONNECTED
if(key == 's') {
vidGrabber.videoSettings();
}
#endif
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}
ofxARToolkitPlusが用意しているメソッドは以下のようなものみたい
setup(int w, int h)
setup(int w, int h, string camParamFile, string multiFile)
setThreshold(int threshold)
activateAutoThreshold(bool state)
update(unsigned char *pixels)
applyProjectionMatrix()
applyModelMatrix(int markerIndex)
draw(int x, int y)
getDetectedMarkerDirection(int markerIndex)
getDetectedMarkerCorners(int markerIndex, vector<ofPoint> &corners)
getDetectedMarkerOrderedCorners(int markerIndex, vector<ofPoint> &corners)
getDetectedMarkerBorderCorners(int markerIndex, vector<ofPoint> &corners)
getDetectedMarkerOrderedBorderCorners(int markerIndex, vector<ofPoint> &corners)
以下exampleのコメントを意訳してみた。
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
width = 640;
height = 480;
//データフォルダの中に入ってるAllBchThinMarkers.pngからマーカーを印刷しておいて
#ifdef CAMERA_CONNECTED
vidGrabber.initGrabber(width, height);
#else
vidPlayer.loadMovie("marker.mov");
vidPlayer.play();
#endif
colorImage.allocate(width, height);
grayImage.allocate(width, height);
grayThres.allocate(width, height);
// This uses the default camera calibration and marker file
artk.setup(width, height);
//winなら下からカメラキャリブレーションソフトが使えるよ
// The camera calibration file can be created using GML:
// http://graphics.cs.msu.ru/en/science/research/calibration/cpp
// and these instructions:
// http://studierstube.icg.tu-graz.ac.at/doc/pdf/Stb_CamCal.pdf
// This only needs to be done once and will aid with detection
// for the specific camera you are using
// Put that file in the data folder and then call setup like so:
// artk.setup(width, height, "myCamParamFile.cal", "markerboard_480-499.cfg");
// しきい値をセット/Set the threshold
// ARTK+ does the thresholding for us
// We also do it in OpenCV so we can see what it looks like for debugging
threshold = 85;
artk.setThreshold(threshold);
ofBackground(127,127,127);
}
//--------------------------------------------------------------
void testApp::update(){
#ifdef CAMERA_CONNECTED
vidGrabber.grabFrame();
bool bNewFrame = vidGrabber.isFrameNew();
#else
vidPlayer.idleMovie();
bool bNewFrame = vidPlayer.isFrameNew();
#endif
if(bNewFrame) {
#ifdef CAMERA_CONNECTED
colorImage.setFromPixels(vidGrabber.getPixels(), width, height);
#else
colorImage.setFromPixels(vidPlayer.getPixels(), width, height);
#endif
// グレースケールに変換
grayImage = colorImage;
// しきい値を適用して2値化画像をつくる
grayThres = grayImage;
grayThres.threshold(threshold);
// ARtoolにgrayImageを渡す Pass in the new image pixels to artk
artk.update(grayImage.getPixels());
}
}
//--------------------------------------------------------------
void testApp::draw(){
//左のウインドウ/ARウインドウにgrayImageを描画
ofSetColor(0xffffff);
grayImage.draw(0, 0);
ofSetColor(0x666666);
ofDrawBitmapString(ofToString(artk.getNumDetectedMarkers()) + " marker(s) found", 10, 20);
//右のウインドウ/しきい値2値化画像を描画
ofSetColor(0xffffff);
grayThres.draw(640, 0);
ofSetColor(0x666666);
ofDrawBitmapString("Threshold: " + ofToString(threshold), 650, 20);
ofDrawBitmapString("Use the Up/Down keys to adjust the threshold", 650, 40);
// ARTK による描画
// マーカーの位置とIDナンバーを簡単に表示
artk.draw(640, 0);
// ARTK 2D stuff
// ID '0' のマーカーが見つかった場合
// 青いコーナーを指定IDのに描画(条件分岐のサンプル)
int myIndex = artk.getMarkerIndex(0);
if(myIndex >= 0) {
// コーナーの座標を取得
vector<ofPoint> corners;
artk.getDetectedMarkerBorderCorners(myIndex, corners);
// 以下で中心座標もとれる get the center like this:
//
ofPoint center = artk.getDetectedMarkerCenter(myIndex);
ofSetColor(0x0000ff);
for(int i=0;i<corners.size();i++) {
ofCircle(corners[i].x, corners[i].y, 10);
}
}
// ARTK 3D stuff
// First apply the projection matrix once
//まずプロジェクション座標に貼付ける
artk.applyProjectionMatrix();
//見つけられたマーカーの数を確かめる
int numDetected = artk.getNumDetectedMarkers();
ofEnableAlphaBlending();
//検出したマーカーの数だけ描画を繰り返す
for(int i=0; i<numDetected; i++) {
//このマーカーのパースにあわせて座標をセットSet the matrix to the perspective of this marker
//原点はマーカーの中央とするThe origin is in the middle of the marker
artk.applyModelMatrix(i);
//マーカーの中心から線をのばす
ofNoFill();
ofSetLineWidth(5);
ofSetColor(0xffffff);
glBegin(GL_LINES);
glVertex3f(0, 0, 0);
glVertex3f(0, 0, 50);
glEnd();
//z軸上に四角形を描画
ofFill();
ofSetColor(255, 255, 0, 50);
for(int i=0; i<10; i++) {
ofRect(-25, -25, 50, 50);//黄色い四角を書いているところ
ofTranslate(0, 0, i*1);
}
}
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
if(key == OF_KEY_UP) {
artk.setThreshold(++threshold);
} else if(key == OF_KEY_DOWN) {
artk.setThreshold(--threshold);
}
#ifdef CAMERA_CONNECTED
if(key == 's') {
vidGrabber.videoSettings();
}
#endif
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}