//use the camera to aid the decision to sleep.
//Copyright 2009 Daniel Watson
/*
- This file is part of oble.
+ 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 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.
+ 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/>.
+ You should have received a copy of the GNU General Public License
+ along with oble. If not, see <http://www.gnu.org/licenses/>.
- */
+*/
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
+#include <iostream>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+
+using namespace std;
+
+DBusGConnection *connection;
+GError *error;
+DBusGProxy *proxy;
+char **name_list;
+char **name_list_ptr;
+
// argument for cvFlip(src, dest, FLIP_TYPE)
-#define VERTICAL_FLIP 1
+#define MIRROR 1
CvHaarClassifierCascade* load_object_detector(const char* cascade_path)
{
faces = cvHaarDetectObjects(small_image, cascade, storage, 1.2, 2,
CV_HAAR_DO_CANNY_PRUNING);
+ if(0 < faces->total)
+ {
+ dbus_g_proxy_call_no_reply(proxy, "SimulateUserActivity", G_TYPE_INVALID);
+ }
+
/* draw all the rectangles */
for(i = 0; i < faces->total; i++)
{
// A Simple Camera Capture Framework.
int main(int argc, char** argv)
{
+ g_type_init ();
+
+ error = NULL;
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION,
+ &error);
+ if (connection == NULL)
+ {
+ g_printerr ("Failed to open connection to bus: %s\n",
+ error->message);
+ g_error_free (error);
+ exit (1);
+ }
+
+ /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
+
+ proxy = dbus_g_proxy_new_for_name (connection,
+ "org.gnome.ScreenSaver",
+ "/org/gnome/ScreenSaver",
+ "org.gnome.ScreenSaver");
+
CvHaarClassifierCascade* cascade = load_object_detector(argv[1]);
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
if(!capture) {
- fprintf(stderr, "ERROR: capture is NULL \n");
+ cerr << "ERROR: capture is NULL " << endl;
getchar();
return -1;
}
IplImage* frame = cvQueryFrame(capture);
if(!frame) {
- fprintf(stderr, "ERROR: frame is null...\n");
+ cerr << "ERROR: frame is null..." << endl;
getchar();
return -1;
}
- IplImage* flipped =
+ IplImage* mirrored =
cvCreateImage(cvGetSize(frame), frame->depth, frame->nChannels);
// Show the image captured from the camera in the window and repeat
while(1) {
// Get one frame
frame = cvQueryFrame(capture);
if(!frame) {
- fprintf(stderr, "ERROR: frame is null...\n");
+ cerr << "ERROR: frame is null..." << endl;
getchar();
break;
}
//flip the image so displayed right/left corresponds to physical right/left
- cvFlip(frame, flipped, VERTICAL_FLIP);
+ cvFlip(frame, mirrored, MIRROR);
- detect_and_draw_objects(flipped, cascade, 1);
- cvShowImage("mywindow", flipped);
+ detect_and_draw_objects(mirrored, cascade, 1);
+ cvShowImage("mywindow", mirrored);
// Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
// Release the capture device housekeeping
cvReleaseCapture(&capture);
cvDestroyWindow("mywindow");
- cvReleaseImage(&flipped);
+ cvReleaseImage(&mirrored);
return 0;
}