Hi,
I am currently working on a step sequencer project with ofxCv and webcam .
But this code is don’t build…
I’ll appreciate any advice you can give me…
testApp.cpp//
#include “testApp.h”
using namespace ofxCv;
using namespace cv;
//--------------------------------------------------------------
void testApp::setup(){
ofSetVerticalSync(true);
ofBackground(0);
cam.initGrabber(ofGetWidth(), ofGetHeight());
contourFinder.setMinAreaRadius(1);
contourFinder.setMaxAreaRadius(100);
contourFinder.setThreshold(15);
contourFinder.getTracker().setMaximumDistance(32);
showLabels = true;
}
//--------------------------------------------------------------
void testApp::update(){
cam.update();
if (cam.isFrameNew()) {
contourFinder.findContours(cam);
}
}
//--------------------------------------------------------------
void testApp::draw(){
ofSetBackgroundAuto(showLabels);
RectTracker& tracker = contourFinder.getTracker();
if(showLabels){
ofSetColor(255);
cam.draw(0,0);contourFinder.draw();
for(int i = 0;i < contourFinder.size(); i++){
ofPoint center = to0f(contourFinder.getVelocity(i));
ofPushMatrix();
int label = contourFinder.getLabel(i);
string msg = ofToString(label) + “:” + ofToString(tracker.getAge(label));
ofDrawBitmapString(msg,0,0);
ofVec2f velocity = to0(contourFinder.getVelocity(i));
ofScale(5,5);
ofLine(0, 0, velocity.x, velocity.y);
ofPopMatrix();
}
}else{
for(int i = 0; i < contourFinder.getsize(); i++){
unsigned int label = contourFinder.getLabel(i);
if(tracker.exsistsPrevious(label));{
ofSeedRandom(label << 24);
ofSetColor(ofColor::fromHsb(ofRandom(255), 255, 255));
// get the tracked object (cv::Rect) at current and previous position
const cv::Rect& previous = tracker.getPrevious(label);
const cv::Rect& current = tracker.getCurrent(label);
// get the centers of the rectangles
ofVec2f previousPosition(previous.x + previous.width / 2, previous.y + previous.height / 2);
ofVec2f currentPosition(current.x + current.width / 2, current.y + current.height / 2);
ofLine(previousPosition, currentPosition);
}
}
}
// this chunk of code visualizes the creation and destruction of labels
const vector<unsigned int>& currentLabels = tracker.getCurrentLabels();
const vector<unsigned int>& previousLabels = tracker.getPreviousLabels();
const vector<unsigned int>& newLabels = tracker.getNewLabels();
const vector<unsigned int>& deadLabels = tracker.getDeadLabels();
ofSetColor(cyanPrint);
for(int i = 0; i < currentLabels.size(); i++) {
int j = currentLabels[i];
ofLine(j, 0, j, 4);
}
ofSetColor(magentaPrint);
for(int i = 0; i < previousLabels.size(); i++) {
int j = previousLabels[i];
ofLine(j, 4, j, 8);
}
ofSetColor(yellowPrint);
for(int i = 0; i < newLabels.size(); i++) {
int j = newLabels[i];
ofLine(j, 8, j, 12);
}
ofSetColor(ofColor::white);
for(int i = 0; i < deadLabels.size(); i++) {
int j = deadLabels[i];
ofLine(j, 12, j, 16);
}
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
if(key == ' ') {
showLabels = !showLabels;
}
}
testApp.h//
#pragma once
#include “ofMain.h”
#include “ofxCv.h”
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
float threshold;
ofVideoGrabber cam;
ofxCv::ContourFinder contourFinder;
bool showLabels;
};
This is an example of the type of thing I’d like to do…