Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HEADER
- int camWidth = 320;
- int camHeight = 240;
- ofVideoGrabber cam;
- ofxCvColorImage testApply;
- ofxFaceTracker tracker;
- ofImage testimg;
- ofEasyCam easyCam;
- MAIN
- void testApp::setup() {
- ofSetVerticalSync(true);
- cam.initGrabber(camWidth, camHeight);
- tracker.setup();
- testApply.allocate(camWidth, camHeight);
- }
- void testApp::update() {
- cam.update();
- if(cam.isFrameNew()) {
- tracker.update(toCv(cam));
- }
- }
- void testApp::draw() {
- ofSetColor(255);
- ofDrawBitmapString(ofToString((int) ofGetFrameRate()), 10, 20);
- if(tracker.getFound()) {
- ofPolyline lefteye = tracker.getImageFeature(ofxFaceTracker::LEFT_EYE);
- ofPolyline righteye = tracker.getImageFeature(ofxFaceTracker::RIGHT_EYE);
- ofPolyline topmouth = tracker.getImageFeature(ofxFaceTracker::OUTER_MOUTH);
- ofPolyline botmouth = tracker.getImageFeature(ofxFaceTracker::INNER_MOUTH);
- ofPolyline nosebridge = tracker.getImageFeature(ofxFaceTracker::NOSE_BRIDGE);
- ofPolyline nosebase = tracker.getImageFeature(ofxFaceTracker::NOSE_BASE);
- vector<ofPoint> eye = lefteye.getVertices();
- ofPixels pix = cam.getPixelsRef();
- for(int i = 0;i<camWidth*camHeight*3;i++){
- int x = i % camWidth;
- int y = (i - x) / camWidth;
- if(lefteye.inside(x, y) ||
- righteye.inside(x, y) ||
- topmouth.inside(x, y) ||
- botmouth.inside(x, y) ||
- nosebridge.inside(x, y) ||
- nosebase.inside(x, y)){
- pix[i] = pix[i];
- pix[i+1] = pix[i+1];
- pix[i+2] = pix[i+2];
- }else{
- pix[i] = 255;
- }
- }
- testimg.setFromPixels(pix);
- testApply.flagImageChanged();
- }
- ofScale(2,2);
- testimg.draw(0,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement