face detection resets idle time and deactivates ss
[ozzloy@gmail.com/oble] / oble.cpp
index ab7d509341105b2a942a45dd1558d27c371ba232..0e24b9e05ff6462e3b8a095f8fc768afbcad9d83 100644 (file)
--- a/oble.cpp
+++ b/oble.cpp
 #include <iostream>
 #include <time.h>
 #include "oble.h"
+#include "idle_x11.h"
 
 using namespace std;
 
 // argument for cvFlip(src, dest, FLIP_TYPE)
 #define MIRROR 1
 
+#define DEBUG 0
+
 CvHaarClassifierCascade* load_object_detector(const char* cascade_path)
 {
        return (CvHaarClassifierCascade*)cvLoad(cascade_path);
@@ -59,6 +62,7 @@ void detect_and_draw_objects(IplImage* image,
        CvMemStorage* storage = cvCreateMemStorage(0);
        CvSeq* faces;
        int i, scale = 1;
+       static int saw_last_time = 0;
 
        /* if the flag is specified, down-scale the input image to get a
                 performance boost w/o loosing quality (perhaps) */
@@ -77,7 +81,25 @@ void detect_and_draw_objects(IplImage* image,
        if(0 < faces->total)
        {
                t_current = time(NULL);
-               //system("./gss-poke.py");
+               if(DEBUG)
+               {
+                       printf(":) face \n");
+               }
+               if(saw_last_time)
+               {
+                       if(DEBUG)printf("\t\tpoking\n");
+                       reset_idle_time();
+                       system("gnome-screensaver-command --poke");
+               }
+               saw_last_time = 1;
+       }
+       else
+       {
+               saw_last_time = 0;
+               if(DEBUG)
+               {
+                       printf(":( no face \n");
+               }
        }
 
        /* draw all the rectangles */
@@ -105,7 +127,10 @@ void screensave(time_t t_current)
        if(elapse > timeout && elapse != last_elapse)
        {
                last_elapse = elapse;
-               printf("elapse = %d\n", elapse);
+               if(DEBUG)
+               {
+                       printf("elapse = %d\n", elapse);
+               }
                if(!activated)
                {
                        printf("activated\n");
@@ -161,7 +186,7 @@ int main(int argc, char** argv)
                detect_and_draw_objects(mirrored, cascade, 1);
                cvShowImage("mywindow", mirrored);
                // Do not release the frame!
-               screensave(t_current);
+               //screensave(t_current);
 
                //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
                //remove higher bits using AND operator