Skip to content
Snippets Groups Projects
Commit d3df3056 authored by Louis James's avatar Louis James
Browse files

multi colour parameters done. added runonly script (no compile)

parent dea9c0de
Branches
No related merge requests found
No preview for this file type
No preview for this file type
make -j7 && make RunRelease
make -j8 && make RunRelease
make RunRelease
......@@ -4,46 +4,71 @@ using namespace ofxCv;
using namespace cv;
void ofApp::setup() {
int wwidth = 640;
int wheight = 480;
ofSetWindowShape(wwidth, wheight);
cam.setup(640, 480);
contourFinder.setMinAreaRadius(10);
contourFinder.setMaxAreaRadius(150);
//contourFinder.setInvert(true); // find black instead of white
gui.setup();
gui.add(threshold.set("Threshold", 128, 0, 255));
gui.add(trackHs.set("Track Hue/Saturation", false));
// camera and window setup
int wwidth = 1920;
int wheight = 1080;
ofSetWindowShape(wwidth, wheight);
cam.setup(640, 480);
//contourFinder.setInvert(true); // find black instead of white
// initialise gui
gui.setup();
// Initialise gui and parameters
for(int i = 0; i < num_colours; i++){
ofParameter<float> t;
ofParameter<bool> b;
ofParameter<bool> cc;
ofxCv::ContourFinder cf;
thresholds.push_back(t);
trackHues.push_back(b);
changeColours.push_back(cc);
contourFinders.push_back(cf);
targetColours.push_back(ofColor(0,0,0));
gui.add(thresholds[i].set("Threshold " + to_string(i), 128,0,255));
gui.add(trackHues[i].set("Track Hue/Sat colour "+to_string(i), false));
gui.add(changeColours[i].set("Change colour "+to_string(i), false));
}
}
void ofApp::update() {
cam.update();
if(cam.isFrameNew()) {
contourFinder.setTargetColor(targetColor, trackHs ? TRACK_COLOR_HS : TRACK_COLOR_RGB);
contourFinder.setThreshold(threshold);
contourFinder.findContours(cam);
// Loop for number of colours and track target colours
for(int i = 0; i < num_colours; i++){
contourFinders[i].setTargetColor(targetColours[i], trackHues[i] ? TRACK_COLOR_HS : TRACK_COLOR_RGB);
contourFinders[i].setThreshold(thresholds[i]);
contourFinders[i].findContours(cam);
}
}
}
void ofApp::draw() {
ofSetColor(255);
// Draw camera
cam.draw(0, 0);
ofSetLineWidth(2);
contourFinder.draw();
// Draw gui
ofPushMatrix();
gui.draw();
ofTranslate(8, 75);
ofFill();
ofSetColor(0);
ofDrawRectangle(-3, -3, 64+6, 64+6);
ofSetColor(targetColor);
ofDrawRectangle(0, 0, 64, 64);
// Draw contours found
for(int i=0; i < num_colours; i ++)
contourFinders[i].draw();
// Draw colours tracking
ofPushMatrix();
ofTranslate(700,10);
for(int i=0; i < num_colours; i ++){
ofTranslate(0, 75);
ofFill();
ofSetColor(0);
ofDrawRectangle(-3, -3, 64+6, 64+6);
ofSetColor(targetColours[i]);
ofDrawRectangle(0, 0, 64, 64);
}
ofPopMatrix();
//cout << targetColours.size() << endl;
}
void ofApp::mousePressed(int x, int y, int button) {
targetColor = cam.getPixels().getColor(x, y);
for(int i = 0; i < num_colours; i++) {
if(changeColours[i]==true) targetColours[i]=cam.getPixels().getColor(x, y);
}
}
......@@ -10,12 +10,21 @@ public:
void update();
void draw();
void mousePressed(int x, int y, int button);
ofVideoGrabber cam;
ofxCv::ContourFinder contourFinder;
ofColor targetColor;
ofxCv::ContourFinder contourFinder1;
ofxCv::ContourFinder contourFinder2;
ofColor targetColor1;
ofColor targetColor2;
ofxPanel gui;
ofParameter<float> threshold;
ofParameter<bool> trackHs;
ofParameter<float> threshold1;
ofParameter<float> threshold2;
ofParameter<bool> trackHs1;
ofParameter<bool> trackHs2;
vector<ofColor> targetColours;
vector<ofParameter<float>> thresholds;
vector<ofParameter<bool>> trackHues;
vector<ofParameter<bool>> changeColours;
vector<ofxCv::ContourFinder> contourFinders;
int num_colours = 5;
};
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment