allow specifying cascade file as cli arg. Closes #7
authorozzloy <ozzloy@zero7.(none)>
Mon, 22 Feb 2010 10:56:57 +0000 (02:56 -0800)
committerozzloy <ozzloy@zero7.(none)>
Mon, 22 Feb 2010 10:56:57 +0000 (02:56 -0800)
Makefile
NOTES [deleted file]
TODO
gss-poke.py [deleted file]
oble.cpp
oble.h

index e268f883d5e26a6593248a821b97d2be70591650..329027ca5ad1c5bc6825e44f85a69e8e5df92453 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ oble: $(OBJS)
        gcc $(LDFLAGS) -o $@ $(OBJS)
 
 test: all
-       ./oble /usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml
+       ./oble -c /usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml
 
 clean:
        rm -rf oble *.o
diff --git a/NOTES b/NOTES
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/TODO b/TODO
index 646efd4bb64bf3b5fb60dd3d30e5a4e3bf978d6c..e70bd335c5bc63127badd66cc5f2a828499f49c3 100644 (file)
--- a/TODO
+++ b/TODO
@@ -4,28 +4,4 @@ FOR SCREENSAVER:
        * file bug
        * track down bug
                * compile gnome-screensaver
-* cli opt parse
-       * quiet mode
-               * no display window
-               * no text printed to terminal
-* fire up the face detector only just before going to inactive mode.
-       * possibly this is how kreed's version works.  read kreed's code to find out
-       * that way the camera isn't running all the time
-       * maybe start 10 seconds before going inactive, then run until activity, or 10
-       seconds, whichever's first.
-* be more aggressive with turning off the screen.  dim the screen as soon as
-it's not being looked at.  turn it off soon thereafter.
-       * could be enough to save battery.  would need to power the camera sometimes,
-       but would save on backlight.  need to profile.
-* don't prevent sleep when face is detected, but user isn't actually looking at
-screen.
-       * requires pose estimation.
-       * also requires estimating the direction of the eye.
 
-OTHER IDEAS:
-* authenticating a user based on face recognition (as opposed to face
-detection)
-       * much more difficult to do reliably
-       * use object tracking and emotion estimation to require a set of facial
-       expressions as authentication.
-               * awesome for people who find typing hard, eg: no hands
diff --git a/gss-poke.py b/gss-poke.py
deleted file mode 100755 (executable)
index 78a4d69..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-#! /usr/bin/env python
-#inhibit then uninhibit gnome-screensaver.  this is a kludge for
-#SimulateUserActivity
-#Copyright 2010 Daniel Watson
-'''
-    use a camera to prevent screensaver
-    Copyright (C) 2009  daniel watson, ozzloy@gmail.com
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-'''
-'''
-        This file is part of oble.
-
-        oble is free software: you can redistribute it and/or modify
-        it under the terms of the GNU General Public License as published by
-        the Free Software Foundation, either version 3 of the License, or
-        (at your option) any later version.
-
-        oble is distributed in the hope that it will be useful,
-        but WITHOUT ANY WARRANTY; without even the implied warranty of
-        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-        GNU General Public License for more details.
-
-        You should have received a copy of the GNU General Public License
-        along with oble.  If not, see <http://www.gnu.org/licenses/>.
-
-'''
-
-
-import dbus
-import dbus.glib
-import sys
-import time
-
-def inhibit():
-  try:
-    bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
-    devobj = bus.get_object('org.gnome.ScreenSaver',  '/org/gnome/ScreenSaver')
-    dev = dbus.Interface(devobj, "org.gnome.ScreenSaver")
-    cookie = dev.Inhibit('gss-poke', 'SimulateUserActivity kludge')
-    print "gnome screensaver inhibited."    
-    return (dev, cookie)
-  except Exception, e:
-    print "could not send the dbus Inhibit signal: %s" % e
-    return (False, False)
-
-def uninhibit(dev, cookie):
-  try:
-    dev.UnInhibit(cookie)
-    print "gnome screensaver enabled."
-    return(True)  
-  except Exception, e:
-    print "could not send the dbus UnInhibit signal: %s" % e
-    return (False)
-
-if __name__ == '__main__':
-  (dev, cookie) = inhibit()
-  time.sleep(0.1)
-  uninhibit(dev, cookie)
-  sys.exit(0)
index 0e24b9e05ff6462e3b8a095f8fc768afbcad9d83..d949cd594d9f31df2c287b943af0281472229e09 100644 (file)
--- a/oble.cpp
+++ b/oble.cpp
 #include <stdio.h>
 #include <iostream>
 #include <time.h>
+#include <unistd.h>
 #include "oble.h"
 #include "idle_x11.h"
 
 using namespace std;
 
+static string cascade_filename = "";
+
 // argument for cvFlip(src, dest, FLIP_TYPE)
 #define MIRROR 1
 
@@ -146,10 +149,47 @@ void screensave(time_t t_current)
        }
 }
 
+int parse_opts(int argc, char **argv)
+{
+       int index, c;
+       //int opterr=0, optopt=0, optind=0;
+       //char *optarg;
+       // int getopt(int argc, char **argv, const char *options);
+       opterr = 0;
+       const char *options = "c:";
+       while((c = getopt(argc, argv, options)) != -1)
+               switch(c)
+               {
+                       case 'c':
+                               cascade_filename = string(optarg);
+                               printf("option c, argument = %s\n", optarg);
+                       case '?':
+                               if(optopt == 'c')
+                                       printf("option -%c requires an argument.\n", optopt);
+                               else if(isprint (optopt))
+                                       printf("unknown option `-%c'.\n", optopt);
+                               else
+                                       printf("unknown option char `\\x%x'.\n", optopt);
+                               goto known_args_processed;
+                       default:
+                               abort();
+               }
+known_args_processed:
+
+       for(index = optind; index < argc; index++)
+               printf("Non-option arg %s\n", argv[index]);
+
+       return 0;
+}
+
 // A Simple Camera Capture Framework.
 int main(int argc, char** argv)
 {
-       CvHaarClassifierCascade* cascade = load_object_detector(argv[1]);
+       if(parse_opts(argc, argv)) return 0;
+
+       if(cascade_filename == "") cascade_filename = string(argv[1]);
+       CvHaarClassifierCascade* cascade =
+               load_object_detector(cascade_filename.c_str());
 
        CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
        if(!capture) {
diff --git a/oble.h b/oble.h
index 3e900f09b73172e9bb4d299d10b962d429d3847b..3e65b6e1a1b569cd4529408cf6fb0a99c1ca5b90 100644 (file)
--- a/oble.h
+++ b/oble.h
@@ -48,4 +48,4 @@ void detect_and_draw_objects(IplImage* image,
 
 void screensave(time_t t_current);
 
-bool parse_opts(int argc, char **argv);
+int parse_opts(int argc, char **argv);