Smile Detector collection app advice

Hiya! I’m using the smile detector example from ofxcv, and aim to make an app that takes a photo of your screen when you smile, so you end up having a collection of screenshots of content you saw that made you smile. I used ofxScreenGrab.h, to take the screenshots.

The app works and takes the screen grab when the app is running, up and in the same desktop screen in the dashboard. (Mac lets you have several screens)

However, when I switch screens, say from desktop 1 to 2 on the same mac, while the app is running the program breaks.

This is my code:

include “ofApp.h”
using namespace ofxCv;
using namespace cv;

void ofApp::setup() {
cam.setup(640, 480);
bool retina = true;
grabber.setup(ofGetWidth(), ofGetHeight(), retina);


void ofApp::update() {

if(cam.isFrameNew()) {
    if(smile.getFaceFound()) {
        float cur = smile.getSmileAmount();
        ofLog() << graph.getNormalized(cur);
        grabber.grabScreen(0, 0)          

void ofApp::draw() {

cam.draw(0, 0);
if (smile.getSmileAmount()>100){
grabber.draw(0, 0);

  1. How can I overcome this? As the aim to make a background running app and eventually make it a phone app, how can this successfully work in the background?

  2. Could I get some advice on how to turn this into an app form that can run smoothly in the background? On the laptop or on an ios

Thank you so much!!!

Edit: instead of ofxScreenGrab, I can call the terminal from open frameworks to take a screenshot, and these solves the multi screen problem!

Would still love to get feedback on how to approach this as a mobile app :slight_smile: