Click here to Skip to main content
11,706,979 members (54,832 online)
Click here to Skip to main content

Intelligent Screen Saver

, 15 Aug 2007 CPOL 133K 9.5K 109
Rate this:
Please Sign up or sign in to vote.
A utility to control screen saver on your computer using computer vision (human face detection), rather than idle timer.
Screenshot - facede.png

Introduction

This is a utility to control screen saver using human face detection. Human face detection is performed using OpenCV Haar-Cascade method. The software is primarily a daemon that resides in your system tray and keeps observing the input from a webcam to analyze if the user is no longer in view. Currently two angles are supported namely frontal pose and profile pose.

Background

The idea of an intelligent screen saver is not new. In the past, it was not achievable because of accuracy problems with computer vision algorithms and computation power of computers. OpenCV (open source computer vision library) has an implementation of the object detection algorithm suggested originally by Paul Viola. I have adopted from the face detection sample that comes with this library and have used the cascades files that come with it.

Using the Code

Face detection is performed by a mix-mode DLL, i.e. it uses unmanaged code to perform face detection and provides a managed wrapper. This DLL, hence can now be called from any CLR enabled language (C#, VB.NET, etc.). This DLL expects a managed System.Drawing.Image object and performs face detection.

This managed System.Drawing.Image object is taken from the ctlDxCam library (a custom library built from code posted on an article on CodeProject.com, it can capture frames from a webcam as System.Drawing.Image objects) which captures video frames from a webcam.

Screensaver is controlled by a class that uses borrowed code from another article on CodeProject.com. Please consult references section for details.

// On the first thread, we perform polling for face detection
CommonVariables.FaceDetected = (faceLocator.WrapDetectFaces(LatestFrame)>0);

// On the second thread, we evaluate conditions to trigger screen saver
private void Run()
  {
   bool IsScreenSaverRunning;
   while(KeepRunning)
   {
    //check if screen saver is currently active
    IsScreenSaverRunning = ScreenSaverHandler.IsScreenSaverRunning();
    
    //if last captured frame has not been evaluated
    if(!CommonVariables.IsConsumed)
    {
    //was faces detected in the last polled frame
     if(CommonVariables.FaceDetected)
     {
      CommonVariables.VoteCount = 0;
    //yes face was detected, kill screen saver if running
      if(IsScreenSaverRunning)
        ScreenSaverHandler.StopScreenSaver();
     }
     else if(!IsScreenSaverRunning)
     {     
    //face was not detected, screen saver isnt running either
    //collect votes of no_face_detected
      CommonVariables.VoteCount++;
    //if votes exceed tolerated amount of no_face detected condition
      if(CommonVariables.VoteCount >= CommonVariables.MinVoteRequired)
      {
    //reset votescount and launch screen saver
       CommonVariables.VoteCount = 0;
       ScreenSaverHandler.LaunchScreenSaver();
      }
     }
    }
 
    if(IsScreenSaverRunning)
      Thread.Sleep(1000);     //shorter polling timer
    else             //longer polling timer
      Thread.Sleep(CommonVariables.PollingTimer); 
   }
  }  

The source code performs polling on the camera input and evaluates the captured frame at desired interval of time. For each frame that does not have a face in it, a counter (VoteCount) is incremented. After a specified number of such votes, screen saver is launched.

If the polling timer is set to 5 seconds and required votes is set to 2, then if a person leaves his seat, screen saver will start running in approximately (5*2) 10 seconds.

Points of Interest

This source code demonstrates an interesting concept to use OpenCV from managed code (C#, VB.NET, Managed VC++.NET). The algorithm of face detection is very robust but still has its limitations. False detection of the algorithm can be adjusted by setting the light condition of the environment and camera position, etc. User can select whether he wants frontal face detection or profile face detection and hence place camera in respective angles.

References

History

  • First version, proof of concept

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Zeeshan Ejaz Bhatti
Web Developer
Pakistan Pakistan
BCSE - Software Engineering (2000 - 2004)
Foundation University Institute of Management and Computer Sciences.
Pakistan.

MS - Computer Sciences (2004 - 2005)
Lahore Univeristy of Management Sciences
Pakistan.

You may also be interested in...

Comments and Discussions

 
Questionthe program (in the release zip) does not detect face Pin
hakanyanik6-Dec-13 1:02
memberhakanyanik6-Dec-13 1:02 
QuestionNeed Help plz ! Pin
SERVODROID1-Aug-11 1:28
memberSERVODROID1-Aug-11 1:28 
GeneralError in running Face and Eye Detection Pin
UpdateAk478-Oct-10 9:45
memberUpdateAk478-Oct-10 9:45 
QuestionPlease help me: face recognition program for absence system Pin
Alveen Scofield28-May-10 20:42
memberAlveen Scofield28-May-10 20:42 
GeneralMy vote of 1 Pin
CreepX7-Jan-10 7:35
memberCreepX7-Jan-10 7:35 
Generalharcascade classifier Pin
duta24-Nov-09 9:57
memberduta24-Nov-09 9:57 
GeneralRe: harcascade classifier Pin
Zeeshan Ejaz Bhatti27-Nov-09 19:24
memberZeeshan Ejaz Bhatti27-Nov-09 19:24 
GeneralThe specified module could not be found. (Exception from HRESULT: 0x8007007E) Pin
roody_21117-Jun-09 0:23
memberroody_21117-Jun-09 0:23 
GeneralRe: The specified module could not be found. (Exception from HRESULT: 0x8007007E) Pin
Zeeshan Ejaz Bhatti27-Nov-09 19:25
memberZeeshan Ejaz Bhatti27-Nov-09 19:25 
GeneralRe: The specified module could not be found. (Exception from HRESULT: 0x8007007E) Pin
Lazerus24-Dec-09 7:14
memberLazerus24-Dec-09 7:14 
QuestionStoring facial features for comparison for secure login or facial matching Pin
Richard Milligan6-May-08 15:41
memberRichard Milligan6-May-08 15:41 
AnswerRe: Storing facial features for comparison for secure login or facial matching Pin
Zeeshan Ejaz Bhatti9-May-08 7:24
memberZeeshan Ejaz Bhatti9-May-08 7:24 
QuestionNew error? Pin
lamedust25-Mar-08 12:28
memberlamedust25-Mar-08 12:28 
AnswerRe: New error? Pin
lamedust25-Mar-08 12:45
memberlamedust25-Mar-08 12:45 
QuestionRe: New error? Pin
TheFrnd1-Jun-09 4:25
memberTheFrnd1-Jun-09 4:25 
QuestionFaceDetect not working Pin
jinxp9-Nov-07 17:33
memberjinxp9-Nov-07 17:33 
AnswerRe: FaceDetect not working Pin
Zeeshan Ejaz Bhatti9-Nov-07 21:53
memberZeeshan Ejaz Bhatti9-Nov-07 21:53 
HI,

The face detect project accepts pointer to the managed image. VB.NET does not have pointers so you cannot use VB.NET with this project.

A helpful chap created a VB.NET wrapper for this project. Either use C#/Managed C++ or Use the above mentioned VB.NET Wrapper. Here is the link for the VB.NET wrapper

http://www.zen-turkey.com/blog/default.aspx?id=42&t=VB-NET-Wrapper-For-Face-Detection

Donot forget to vote Wink | ;)

All Rights Reserved! All Wrongs Revenged!

GeneralRe: FaceDetect not working Pin
jinxp11-Nov-07 13:43
memberjinxp11-Nov-07 13:43 
GeneralRe: FaceDetect not working Pin
Zeeshan Ejaz Bhatti14-Nov-07 1:28
memberZeeshan Ejaz Bhatti14-Nov-07 1:28 
GeneralRe: FaceDetect not working Pin
hamada el3ashe214-Jul-11 14:46
memberhamada el3ashe214-Jul-11 14:46 
QuestionWrapGetFaceCordinates help Pin
skull_missah18-Sep-07 11:19
memberskull_missah18-Sep-07 11:19 
AnswerRe: WrapGetFaceCordinates help Pin
digitals200219-Sep-07 6:37
memberdigitals200219-Sep-07 6:37 
GeneralRe: WrapGetFaceCordinates help Pin
skull_missah19-Sep-07 6:42
memberskull_missah19-Sep-07 6:42 
GeneralRe: WrapGetFaceCordinates help Pin
Zeeshn19-Sep-07 7:43
memberZeeshn19-Sep-07 7:43 
Questioncall the DLL from ASP .NET Pin
skull_missah17-Sep-07 10:47
memberskull_missah17-Sep-07 10:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150819.1 | Last Updated 15 Aug 2007
Article Copyright 2007 by Zeeshan Ejaz Bhatti
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid