The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

blinkDetector/windows/FilterSrc/FilterInterface.h

Go to the documentation of this file.
00001 #ifndef __FILTERINTERFACE_H__
00002 #define __FILTERINTERFACE_H__
00003 
00004 #include <windows.h>
00005 #include "eyefinderBinary.h"
00006 #include "faceobject.h"
00007 #include "blink.h"
00008 #include "Images/color.h"
00009 #include "cluster.h"
00010 #include <fstream>
00011 
00012 class FilterInterface
00013 {
00014 public:
00015 
00016         FilterInterface();    // Constructor
00017         ~FilterInterface();     // Destructor
00018 
00019         int runInterface(BYTE *pData, int imgWidth, int imgHeight);
00020         void printFrame(RGBTRIPLE *prgb, int cxImage, int cyImage);
00021 
00022 private:
00023 
00024         MPBlink blink;
00025     MPEyeFinder *m_eyefinder;
00026     VisualObject m_faces;
00027                 VisualObject m_lastFace;
00028         RImage<float> m_pixels;
00029         MPColorTools colorT;
00030         int m_failedCycles;
00031         bool m_failedSearch;
00032 
00033         //Added to handle individual normalization
00034         //Cluster cluster;
00035 
00036 // ================================================================
00037 
00038         inline void GreyScaleFlipVideo(int width, int height, RGBTRIPLE *rgbpix, RImage<float> & pixels)
00039         {
00040                 RGBTRIPLE *source;
00041                 unsigned char *sp;
00042                 float *dest;
00043 
00044                 // convert image to grayscale and out of directshow coordinates 
00045                 for (int y=0; y < height; y++) {
00046                         source = rgbpix + width * ((height-1) - y);
00047                         sp = (unsigned char *) source;
00048                         dest = pixels.array + width*y;
00049                         for (int x = 0; x < width; x++) {
00050                                 *dest++ = (float)(sp[2] + sp[1]*6 + sp[0]*3);
00051                                 sp += 3;
00052                         }
00053                 }
00054 
00055         } 
00056 
00057 // ================================================================
00058 
00059         inline void DrawBoxes(RGBTRIPLE *prgb, int cxImage, int cyImage)
00060         {  
00061                 bool firstface = true;
00062                 RGBCOLOR color;
00063                 double alpha;
00064                 FFImage<RGBTRIPLE> rgbimage(prgb, cxImage, cyImage);
00065 
00066                 if(m_failedSearch) alpha = exp(-m_failedCycles*0.25);
00067                 else alpha = 1;
00068                 list<VisualObject *>::iterator face = m_lastFace.begin();
00069                 list<VisualObject *>::iterator last_face = m_lastFace.end();
00070                 for ( ; face != last_face; ++face) {
00071                         //print face box
00072                         if(firstface) color = RGBRED;
00073                         else color = RGBBLUE;
00074                         FaceObject *fo = static_cast<FaceObject*>(*face);
00075                         colorT.DrawRGBBox(rgbimage, fo->x, fo->y, fo->xSize, fo->ySize, color, alpha);
00076 
00077                         //print eye boxes
00078                         color = RGBWHITE;
00079                         float eyeSize = fo->xSize * 0.1;
00080                         //left eye
00081                         colorT.DrawRGBBox(rgbimage, static_cast<int>(fo->eyes.xLeft-eyeSize), static_cast<int>(fo->eyes.yLeft-eyeSize), 
00082                                                 static_cast<int>(eyeSize*2), static_cast<int>(eyeSize*2), color, alpha);
00083                         
00084                         //right eye
00085                         colorT.DrawRGBBox(rgbimage, static_cast<int>(fo->eyes.xRight-eyeSize), static_cast<int>(fo->eyes.yRight-eyeSize), 
00086                                                 static_cast<int>(eyeSize*2), static_cast<int>(eyeSize*2), color, alpha);
00087                         firstface = false;
00088                 }
00089         }
00090 
00092 
00093         inline void ShowBlinkResults(RGBTRIPLE *prgb, int cxImage, int cyImage){
00094 
00095                 double bResults;
00096                 static int beeped = 0;
00097                 double alpha;
00098                 if(m_failedSearch) alpha = exp(-m_failedCycles*0.25);
00099                 else alpha = 1;
00100                 int startX = 5;
00101                 RGBTRIPLE *tmpPtr;
00102                 if (m_lastFace.size()) {
00103                         FaceObject *fo = static_cast<FaceObject*>(*m_lastFace.begin());
00104                         if (fo->xSize > 0) {
00105                                 bResults = -fo->activation;//cluster.UpdateCluster(fo->activation) - fo->activation;
00106                                 if(bResults > 0){
00107                                         if (!beeped) {
00108                                                 for (int i = 1000; i > 800; i-=100)
00109                                                         Beep(i, 100);
00110                                                 beeped = 1;
00111                                         }
00112                                         int maxRes = static_cast<int>(bResults+cyImage*0.5);
00113                                         maxRes = min(maxRes, cyImage-1);
00114                                         for(int y = cyImage*0.5; y < maxRes; y++){
00115                                                 tmpPtr = prgb + startX + cxImage*((cyImage-1) - y);
00116                                                 for(int w = 0; w < 15; w++, *tmpPtr++)
00117                                                         colorT.setRGBColor(*tmpPtr, RGBBLUE, alpha);
00118                                         }
00119                                 }
00120                                 else{
00121                                         beeped = 0;
00122                                         int minRes = static_cast<int>(bResults+cyImage/2);
00123                                         minRes = max(minRes, 0);
00124                                         for(int y = cyImage*0.5; y > minRes; y--){
00125                                                 tmpPtr = prgb + startX + cxImage*((cyImage-1) - y);
00126                                                 for(int w = 0; w < 15; w++, *tmpPtr++)
00127                                                         colorT.setRGBColor(*tmpPtr, RGBRED, alpha);
00128                                         }
00129                                 }
00130                         }
00131                 }
00132         }
00133 
00134 
00135 // ================================================================
00136 
00137 
00138 }; // FilterInterface
00139 
00140 #endif __FILTERINTERFACE_H__

Generated on Mon Nov 8 17:07:34 2004 for MPT by  doxygen 1.3.9.1