Click here to Skip to main content
15,883,975 members
Articles / Programming Languages / C#

Intelligent Screen Saver

Rate me:
Please Sign up or sign in to vote.
3.87/5 (17 votes)
15 Aug 2007CPOL2 min read 183.5K   10.9K   111  
A utility to control screen saver on your computer using computer vision (human face detection), rather than idle timer.
// facedetect.h : main header file for the FACEDETECT DLL
//
#pragma once
#include "cv.h"
#pragma managed 

#define scale 1.3
#define MAXOBJECTCOUNT 5
#define MaxValue 32000

#define cascade_name "haarcascade_frontalface_alt.xml"



/////////////////////////////////////////////////////////////////////////////
// CFacedetectApp
// See facedetect.cpp for the implementation of this class
//
#pragma managed 
__gc class ObjectLocator 
{
private:
	int width,height;             //dimensions of the scene bitmap	  
	CvHaarClassifierCascade* cascade;
	CvMemStorage* storage ;		
	int object_location __gc[,];
	//int object_location __gc[MAXOBJECTCOUNT][4];  //stores the locations of detected objects	
	
	/* finds sequence element by its index */
	char* Helper( const CvSeq *seq, int index )
	{
		CvSeqBlock block;
		int count, total = seq->total;

		if( (unsigned)index >= (unsigned)total )
		{
			index += index < 0 ? total : 0;
			index -= index >= total ? total : 0;
			if( (unsigned)index >= (unsigned)total )
				return 0;
		}

		block = *seq->first;
		if( index + index <= total )
		{
			while( index >= (count = block.count) )
			{
				block = *block.next;
				index -= count;
			}
		}
		else
		{
			do
			{
				block = *block.prev;
				total -= block.count;
			}
			while( index < total );
			index -= total;
		}

		return block.data + index * seq->elem_size;
	}

public:		
	void SetFaceROI(int index);
	void UnSetFaceROI();

	void UnInitImageStorage();
	void InitImageStorage(int img_width, int img_height, double img_scale);
	
	void ImagePreProcessForFaceDetection();
	void ImagePreProcessForEyeDetection();
	
	void ManagedImagetoUnManagedImage(IplImage* Src);
	//void PrepareSmallImage();		
	int NoOfObjects;            //number of faces detected	
	void GetObjectCoordinates(int oNum, int &tx, int &ty, int &bx, int &by);
	int DetectObjects();
	int InitObjectDetect(char* cascadename);	
	ObjectLocator();
	~ObjectLocator();
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
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.

Comments and Discussions