void update() { cam.update(); if(cam.isFrameNew()) { Mat camMat = toCv(cam); tracker.update(camMat); trackerDataSave.load(tracker); } }
void keyPressed(int key) { if(key == 's') { trackerDataSave.save("metadata/out.face"); } if(key == 'l') { trackerDataLoad.load("metadata/out.face"); } }
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 }