Newer
Older
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));
}
void ofApp::update() {
cam.update();
if(cam.isFrameNew()) {
contourFinder.setTargetColor(targetColor, trackHs ? TRACK_COLOR_HS : TRACK_COLOR_RGB);
contourFinder.setThreshold(threshold);
contourFinder.findContours(cam);
void ofApp::draw() {
ofSetColor(255);
cam.draw(0, 0);
ofSetLineWidth(2);
contourFinder.draw();
gui.draw();
ofTranslate(8, 75);
ofFill();
ofSetColor(0);
ofDrawRectangle(-3, -3, 64+6, 64+6);
ofSetColor(targetColor);
ofDrawRectangle(0, 0, 64, 64);
}
void ofApp::mousePressed(int x, int y, int button) {
targetColor = cam.getPixels().getColor(x, y);