예제 #1
0
	void setup() {
#ifndef INSTALL
		useSharedData();
#endif
		loadSettings();
		
		tracker.setup();
		tracker.setHaarMinSize(175);
		tracker.setRescale(.25);
		tracker.setIterations(3);
		tracker.setTolerance(2);
		tracker.setClamp(3);
		tracker.setAttempts(4);
		
#ifdef INSTALL
		cam.setup(camWidth, camHeight, 30);
#else
		cam.initGrabber(camWidth, camHeight, false);
#endif
		if(rotate) {
			data.setup(camHeight, camWidth, binSize);
		} else {
			data.setup(camWidth, camHeight, binSize);
		}
		loadMetadata(data);
		presence.setDelay(0, 4);
		presenceFade.setLength(4, .1);
		presenceFade.start();
		shader.load("shaders/colorbalance.vs", "shaders/colorbalance.fs");
		ofDisableAntiAliasing();
		glPointSize(2);
		ofSetLineWidth(3);
		ofSetLogLevel(OF_LOG_VERBOSE);
	}
예제 #2
0
	void exit() {
		imageSaver.exit();
		tracker.stopThread();
#ifdef INSTALL
		cam.close();
#endif
	}
예제 #3
0
	void update() {
#ifdef INSTALL
		if(cam.update()) {
			ofPixels& pixels = cam.getColorPixels();
#else
		cam.update();
		if(cam.isFrameNew()) {
			ofPixels& pixels = cam.getPixelsRef();
#endif
			// next two could be replaced with one line
			ofxCv::rotate90(pixels, rotated, rotate ? 270 : 0);
			ofxCv:flip(rotated, rotated, 1);
			Mat rotatedMat = toCv(rotated);
			if(tracker.update(rotatedMat))  {
				ofVec2f position = tracker.getPosition();
				vector<FaceTrackerData*> neighbors = data.getNeighborsCount(position, neighborCount);
				FaceTrackerData curData;
				curData.load(tracker);
				if(!neighbors.empty()) {
					nearestData = *faceCompare.nearest(curData, neighbors);
					if(nearestData.label != lastLabel) {
						similar.loadImage(nearestData.getImageFilename());
#ifdef INSTALL
						whitePoint = getWhitePoint(similar);
#else
						whitePoint.set(1, 1, 1);
#endif
					}
					lastLabel = nearestData.label;
				}
				if(faceCompare.different(curData, currentData) && faceCompare.different(curData, neighbors)) {
					saveFace(curData, rotated);
					currentData.push_back(pair<ofVec2f, FaceTrackerData>(position, curData));
				}
			}
			presence.update(tracker.getFound());
			if(presence.wasTriggered()) {
				presenceFade.stop();
			}
			if(presence.wasUntriggered()) {
				for(int i = 0; i < currentData.size(); i++) {
					data.add(currentData[i].first, currentData[i].second);
				}
				currentData.clear();
				presenceFade.start();
			}
		}
	}
	void draw() {
		ofBackground(255);
		CGDisplayHideCursor(NULL);
		ofSetColor(255);
		if(similar.isAllocated()) {
			shader.begin();
			shader.setUniformTexture("tex", similar, 0);
			shader.setUniform3fv("whitePoint", (float*) &whitePoint);
			similar.draw(0, 0);
			shader.end();
		}
		ofPushStyle();
		if(presenceFade.getActive()) {
			ofSetColor(0, ofMap(presenceFade.get(), 0, 1, 0, 128));
			ofFill();
			ofRect(0, 0, ofGetWidth(), ofGetHeight());
			ofSetColor(255, ofMap(presenceFade.get(), 0, 1, 0, 32));
			data.drawBins();
			ofSetColor(255, ofMap(presenceFade.get(), 0, 1, 0, 64));
			data.drawData();
		}
		ofSetColor(255, 64);
		ofNoFill();
		if(!tracker.getFound()) {
			ofCircle(tracker.getPosition(), 10);
		}
		tracker.draw();
		ofPopStyle();
		
#ifndef INSTALL
		drawFramerate();
#endif
	}
예제 #4
0
	void draw() {
		cam.drawColor();
		ofDrawBitmapStringHighlight(ofToString((int) timer.getFramerate()), 10, 20);
	}
예제 #5
0
	void update() {
		if(cam.update()) {
			timer.tick();
		}
	}
예제 #6
0
	void exit() {
		cam.close();
	}
예제 #7
0
	void setup() {
		ofSetLogLevel(OF_LOG_VERBOSE);
		cam.setup(1920, 1080, 30);
	}