Click here to Skip to main content
13,500,000 members (52,408 online)
Click here to Skip to main content
Add your own
alternative version


109 bookmarked
Posted 18 Jul 2007

Intelligent Screen Saver

, 15 Aug 2007
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


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.


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, 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 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;
    //check if screen saver is currently active
    IsScreenSaverRunning = ScreenSaverHandler.IsScreenSaverRunning();
    //if last captured frame has not been evaluated
    //was faces detected in the last polled frame
      CommonVariables.VoteCount = 0;
    //yes face was detected, kill screen saver if running
     else if(!IsScreenSaverRunning)
    //face was not detected, screen saver isnt running either
    //collect votes of no_face_detected
    //if votes exceed tolerated amount of no_face detected condition
      if(CommonVariables.VoteCount >= CommonVariables.MinVoteRequired)
    //reset votescount and launch screen saver
       CommonVariables.VoteCount = 0;
      Thread.Sleep(1000);     //shorter polling timer
    else             //longer polling timer

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.



  • First version, proof of concept


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


About the Author

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

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

You may also be interested in...

Comments and Discussions

GeneralRe: Can't build in VS2005... Pin
Wiebe Tijsma15-Aug-07 2:35
memberWiebe Tijsma15-Aug-07 2:35 
GeneralRe: Can't build in VS2005... Pin
digitals200215-Aug-07 1:25
memberdigitals200215-Aug-07 1:25 
GeneralRe: Can't build in VS2005... Pin
br00t_4_c24-Aug-07 10:01
memberbr00t_4_c24-Aug-07 10:01 
GeneralRe: Can't build in VS2005... Pin
digitals200224-Aug-07 10:54
memberdigitals200224-Aug-07 10:54 
GeneralRe: Can't build in VS2005... [modified] Pin
trecee_jhnsn18-Oct-07 2:44
membertrecee_jhnsn18-Oct-07 2:44 
GeneralRe: Can't build in VS2005... Pin
Zeeshan Ejaz Bhatti24-Oct-07 0:13
memberZeeshan Ejaz Bhatti24-Oct-07 0:13 
GeneralData corrupted Pin
Eduardolemco24-Jul-07 17:55
memberEduardolemco24-Jul-07 17:55 
GeneralRe: Data corrupted Pin
digitals200225-Jul-07 10:06
memberdigitals200225-Jul-07 10:06 
I removed the link of, the link tosource isnow (note the 2).. are you still seeing the old link? wasthe archiv that contained source code with intellisense database, which was a superflous thing. I think you can compile the code without intellisense further more it willalready be created again once you try to search definition of a function. So summing up, it had no purpose, it was just icnreasing the size of the archive.

Please reply.

All Rights Reserved! All Wrongs Revenged!

GeneralRe: Data corrupted Pin
Eduardolemco25-Jul-07 17:22
memberEduardolemco25-Jul-07 17:22 
GeneralRe: Data corrupted Pin
digitals200226-Jul-07 10:29
memberdigitals200226-Jul-07 10:29 
GeneralRe: Data corrupted Pin
digitals200225-Jul-07 10:14
memberdigitals200225-Jul-07 10:14 
GeneralIf a tree falls in a forest with no one there to hear it... Pin
reinux23-Jul-07 1:20
memberreinux23-Jul-07 1:20 
GeneralRe: If a tree falls in a forest with no one there to hear it... Pin
digitals200223-Jul-07 7:57
memberdigitals200223-Jul-07 7:57 
GeneralRe: If a tree falls in a forest with no one there to hear it... Pin
reinux23-Jul-07 11:43
memberreinux23-Jul-07 11:43 
GeneralRe: If a tree falls in a forest with no one there to hear it... Pin
digitals200223-Jul-07 19:57
memberdigitals200223-Jul-07 19:57 
GeneralRe: If a tree falls in a forest with no one there to hear it... Pin
reinux23-Jul-07 20:17
memberreinux23-Jul-07 20:17 
GeneralRe: If a tree falls in a forest with no one there to hear it... Pin
digitals200224-Jul-07 1:22
memberdigitals200224-Jul-07 1:22 
GeneralRe: If a tree falls in a forest with no one there to hear it... Pin
reinux25-Jul-07 12:41
memberreinux25-Jul-07 12:41 
GeneralRe: If a tree falls in a forest with no one there to hear it... Pin
Drew Noakes11-Aug-07 1:20
memberDrew Noakes11-Aug-07 1:20 
GeneralArchive + Database corupted Pin
pawned20-Jul-07 4:49
memberpawned20-Jul-07 4:49 
GeneralRe: Archive + Database corupted Pin
digitals200220-Jul-07 23:33
memberdigitals200220-Jul-07 23:33 

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

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

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