Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for setup without calibrationFile to track and draw 2d #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "ofMain.h"
#include "testApp.h"
#include "ofApp.h"
#include "ofAppGlutWindow.h"

//========================================================================
Expand All @@ -11,6 +11,6 @@ int main( ){
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp( new testApp());
ofRunApp( new ofApp());

}
28 changes: 14 additions & 14 deletions example/src/testApp.cpp → example/src/ofApp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "testApp.h"
#include "ofApp.h"
#include "ofxCv.h"
#include "ofBitmapFont.h"

Expand All @@ -18,7 +18,7 @@ void drawMarker(float size, const ofColor & color){
}

//--------------------------------------------------------------
void testApp::setup(){
void ofApp::setup(){
ofSetVerticalSync(true);
useVideo = false;
string boardName = "boardConfiguration.yml";
Expand All @@ -28,7 +28,7 @@ void testApp::setup(){
player.play();
video = &player;
}else{
grabber.setDeviceID(1);
//grabber.setDeviceID(1);
grabber.initGrabber(640,480);
video = &grabber;
}
Expand All @@ -50,15 +50,15 @@ void testApp::setup(){
}

//--------------------------------------------------------------
void testApp::update(){
void ofApp::update(){
video->update();
if(video->isFrameNew()){
aruco.detectBoards(video->getPixelsRef());
}
}

//--------------------------------------------------------------
void testApp::draw(){
void ofApp::draw(){
ofSetColor(255);
video->draw(0,0);

Expand Down Expand Up @@ -96,7 +96,7 @@ void testApp::draw(){
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){
void ofApp::keyPressed(int key){
if(key=='m') showMarkers = !showMarkers;
if(key=='b') showBoard = !showBoard;
if(key=='i') showBoardImage = !showBoardImage;
Expand All @@ -110,41 +110,41 @@ void testApp::keyPressed(int key){
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
void ofApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
void ofApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
void ofApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){
void ofApp::dragEvent(ofDragInfo dragInfo){

}
2 changes: 1 addition & 1 deletion example/src/testApp.h → example/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "ofMain.h"
#include "ofxAruco.h"

class testApp : public ofBaseApp{
class ofApp : public ofBaseApp{

public:
void setup();
Expand Down
72 changes: 70 additions & 2 deletions src/ofxAruco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void ofxAruco::setupXML(string calibrationXML,float w, float h, string boardConf
size.height = h;
markerSize = _markerSize;
detector.setThresholdMethod(aruco::MarkerDetector::ADPT_THRES);
maxAge = 7;

camParams.readFromXMLFile(ofToDataPath(calibrationXML));
camParams.resize(cv::Size(w,h));
Expand All @@ -67,6 +68,23 @@ void ofxAruco::setupXML(string calibrationXML,float w, float h, string boardConf
if(threaded) startThread();
}

//setup without calibration to work on 2d
void ofxAruco::setup2d(float w, float h, string boardConfigFile, float _markerSize){

size.width = w;
size.height = h;
markerSize = _markerSize;

detector.setThresholdMethod(aruco::MarkerDetector::ADPT_THRES);

maxAge = 7;

// bgraf
addBoardConf(boardConfigFile);

if(threaded) startThread();
}

void ofxAruco::addBoardConf(string boardConfigFile) {
if(boardConfigFile!="") {
aruco::BoardConfiguration boardConfig;
Expand Down Expand Up @@ -200,7 +218,43 @@ void ofxAruco::findBoards(ofPixels & pixels){
}
}

void ofxAruco::draw(){
void ofxAruco::draw()
{
if ( camParams.isValid() )
draw3d();
else draw2d();
}

void ofxAruco::draw2d()
{
ofSetColor(255,0,0);

for( int i = 0; i < markers.size(); i++ )
{
cv::Point2f p0,p1;
ofPoint ctr(0,0);

for ( int j = 0; j < 4; j++ )
{
p0 = markers[i][j];
p1 = markers[i][ (j+1)%4 ];

ofLine( p0.x, p0.y, p1.x, p1.y );

ctr.x += p0.x;
ctr.y += p0.y;
}

ctr.x /= 4.;
ctr.y /= 4.;

ofDrawBitmapString( ofToString(markers[i].idMarker), ctr );
}

ofSetColor(255);
}

void ofxAruco::draw3d(){
glMatrixMode( GL_PROJECTION );
glPushMatrix();

Expand Down Expand Up @@ -266,7 +320,14 @@ vector<float> ofxAruco::getBoardProbabilities() {
return boardProbabilities;
}

void ofxAruco::begin(int marker){
void ofxAruco::begin(int marker)
{
if ( ! camParams.isValid() )
{
ofLogError("ofxAruco::begin add some camera parameters on setup to use this method");
return;
}

glMatrixMode( GL_PROJECTION );
glPushMatrix();

Expand Down Expand Up @@ -296,6 +357,13 @@ void ofxAruco::begin(int marker){
}

void ofxAruco::end(){

if ( ! camParams.isValid() )
{
ofLogError("ofxAruco::end add some camera parameters on setup to use this method");
return;
}

glMatrixMode( GL_MODELVIEW );
glPopMatrix();

Expand Down
10 changes: 6 additions & 4 deletions src/ofxAruco.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ class ofxAruco: public ofThread {
void setThreaded(bool threaded); // defaults to true
void setup(string calibrationFile,float w, float h, string boardConfig="", float markerSize=.15);
void setupXML(string calibrationXML,float w, float h, string boardConfig="", float markerSize=.15);
void setup2d(float w, float h, string boardConfig="", float markerSize=.15);

void addBoardConf(string boardConfig="");

void detectMarkers(ofPixels & pixels);
void detectBoards(ofPixels & pixels);

void draw();

void draw3d();
void draw2d();

vector<aruco::Marker> & getMarkers();
// bgraf
// aruco::Board & getBoard();
Expand Down Expand Up @@ -106,8 +109,7 @@ class ofxAruco: public ofThread {

double projMatrix[16];
float projfMatrix[16];
ofMatrix4x4 ofprojMatrix;

ofMatrix4x4 ofprojMatrix;

aruco::Marker * findMarker(int id);
TrackedMarker * findTrackedMarker(int id);
Expand Down