Doxygen
detectUtil.cpp File Reference

common routines for face detection More...

#include <functional>
#include "connected.h"
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <fstream>
#include <streambuf>
#include <cstdio>
#include <Eigen/Dense>
#include "commonUtil.h"
#include "detectUtil.h"
#include "Detector.h"
+ Include dependency graph for detectUtil.cpp:

Go to the source code of this file.

Macros

#define FOLLOW_VJ   true
 
#define PEN_WIDTH   3
 
#define STD_NORM_CONST   1e4
 
#define FLAT_THRESHOLD   1
 
#define EXAMPLE_SIZE   24
 
#define ROTATE_DEGREE   5
 
#define WINDOW_SCALE_MULTIPLIER   1.5
 

Typedefs

typedef Matrix< long double,
Dynamic, Dynamic > 
MatrixXld
 

Functions

void gaussianSmoothing (MatrixXf *image, float sigma)
 convolute an image with a Gaussian kernel More...
 
float gaussianKernel (float sigmaSquare, int ref, int cur)
 calculate the gaussian density up to a constant More...
 
void gaussianRowSmoothing (MatrixXf &image, float sigma, int row, int nRows)
 convolute row-wise an image with a Gaussian kernel More...
 
bool zoomOutNegative (MatrixXf *&image, int shrinkedSize, int defaultLayerNumber, vector< stumpRule > *cascade, VectorXf &tweaks)
 try to make an example out of a false positive window More...
 
VectorXf readInCascade (vector< stumpRule > *&cascade)
 cascade More...
 
MatrixXf * convertToColor (const char *inputName, int &nRows, int &nCols, bool &isColor)
 convert a grayscale image to a RGB More...
 
bool isSkinPixel (int row, int col, MatrixXf *image)
 
bool hasEnoughSkin (MatrixXf *image, square area)
 
void augmentedPostProcessing (MatrixXf *image, int nRows, int nCols, bool isColor, float required_nFriends, vector< square > &areas, int ppMode)
 
void highlight (const char *inputName, vector< square > &areas, int ppMode, float required_nFriends)
 highlight the faces so that we can see them More...
 
bool detectFace (square const &area, MatrixXld &integralImage, double varianceNormalizer, VectorXf &tweaks, vector< stumpRule > const *cascade, int defaultLayerNumber)
 detect face in an image subwindow More...
 
int round (int digit, double scale)
 round the real number digit*scale More...
 
double computeFeature (int featureIndex, square const &area, MatrixXld &integralImage, bool removeMean)
 compute the feature from an image subwindow More...
 
bool exampleScan (MatrixXf &example, int defaultLayerNumber, vector< stumpRule > const *cascade, VectorXf &tweaks)
 scan a standard example More...
 
void scan (const char *file, int defaultLayerNumber, float required_nFriends)
 detect faces on an image More...
 
void tscan (const char *file, int &nRows, int &nCols, int defaultLayerNumber, vector< stumpRule > *cascade, VectorXf &tweaks, vector< square > &toMark)
 scan the whole image using a cascade More...
 
bool isLegal (square &area, int nRows, int nCols)
 
bool windowOrder (square window1, square window2)
 
bool isInside (square window1, square window2)
 
void postProcessing (int nRows, int nCols, float required_nFriends, vector< square > &areas)
 toss out several more false positives and beautify the highlighting More...
 
void computeHaarLikeFeatures (MatrixXf &image, VectorXf *&features, const char *cppName, bool enforceShape, bool firstTime)
 compute Haar-like features with integral image More...
 
void rotateCoordinate (int input_i, int input_j, int center_i, int center_j, float theta, int &output_i, int &output_j)
 
void rotateImage (const char *infile, const char *outfile, float theta, int &center_i, int &center_j)
 

Detailed Description

common routines for face detection

Author
Yi-Qing WANG yiqin.nosp@m.g.wa.nosp@m.ng@po.nosp@m.lyte.nosp@m.chniq.nosp@m.ue.e.nosp@m.du

Definition in file detectUtil.cpp.

Macro Definition Documentation

#define EXAMPLE_SIZE   24

Definition at line 44 of file detectUtil.cpp.

#define FLAT_THRESHOLD   1

Definition at line 43 of file detectUtil.cpp.

#define FOLLOW_VJ   true

Definition at line 40 of file detectUtil.cpp.

#define PEN_WIDTH   3

Definition at line 41 of file detectUtil.cpp.

#define ROTATE_DEGREE   5

Definition at line 45 of file detectUtil.cpp.

#define STD_NORM_CONST   1e4

Definition at line 42 of file detectUtil.cpp.

#define WINDOW_SCALE_MULTIPLIER   1.5

Definition at line 46 of file detectUtil.cpp.

Typedef Documentation

typedef Matrix<long double,Dynamic,Dynamic> MatrixXld

Definition at line 50 of file detectUtil.cpp.

Function Documentation

void augmentedPostProcessing ( MatrixXf *  image,
int  nRows,
int  nCols,
bool  isColor,
float  required_nFriends,
vector< square > &  areas,
int  ppMode 
)

Definition at line 244 of file detectUtil.cpp.

double computeFeature ( int  featureIndex,
square const &  area,
MatrixXld integralImage,
bool  removeMean 
)

compute the feature from an image subwindow

Parameters
featureIndexwhich feature
areathe subwindow in question
integralImagethe whole image's integral image
removeMeanin the preprocessing, shall we remove the subwindow's mean
Returns
the feature's numerical value

Definition at line 369 of file detectUtil.cpp.

void computeHaarLikeFeatures ( MatrixXf &  image,
VectorXf *&  features,
const char *  toFile,
bool  enforceShape,
bool  inTrain 
)

compute Haar-like features with integral image

Parameters
integralImageits integral image
featuresall the features from this image
theorder in which features are arranged are put in toFile
enforceShapethe original Viola-Jones's proposal or more extensive definition of rectangle features (requires significantly more memory if disabled)
inTrainam I in the training mode

Definition at line 726 of file detectUtil.cpp.

MatrixXf* convertToColor ( const char *  inputName,
int &  nRows,
int &  nCols,
bool &  isColor 
)

convert a grayscale image to a RGB

Parameters
inputNamewhich image
thereturn image's row numbers
thereturn image's column numbers
Returns
the converted image

Definition at line 187 of file detectUtil.cpp.

bool detectFace ( square const &  area,
MatrixXld integralImage,
double  varianceNormalizer,
VectorXf &  tweaks,
vector< stumpRule > const *  cascade,
int  defaultLayerNumber 
)

detect face in an image subwindow

Parameters
areathe subwindow's parameters
integralImagethe whole image's integral image
varianceNormalizerfor the image preprocessing
tweaksshifts applied to the cascade layers
cascade
defaultLayerNumberhow many layers should be used
Returns
true if it's a face and false otherwise

Definition at line 325 of file detectUtil.cpp.

bool exampleScan ( MatrixXf &  example,
int  defaultLayerNumber,
vector< stumpRule > const *  cascade,
VectorXf &  tweaks 
)

scan a standard example

Parameters
examplea standard training or validation example
defaultLayerNumberhow many layers are there in the cascade
cascade
tweaksshifts applied to the cascade layers
Returns
true if it's a face and false otherwise

Definition at line 488 of file detectUtil.cpp.

float gaussianKernel ( float  sigmaSquare,
int  ref,
int  cur 
)
inline

calculate the gaussian density up to a constant

Parameters
2times Gaussian kernel's variance
refthe point on which the density is centered
curthe point for which the density shall be computed
Returns
the density up to a constant

Definition at line 68 of file detectUtil.cpp.

void gaussianRowSmoothing ( MatrixXf &  image,
float  sigma,
int  row,
int  nRows 
)

convolute row-wise an image with a Gaussian kernel

Parameters
image
Gaussiankernel's standard deviation
rowwhich row
nRowsthe number of pixels in this row
Returns
the blurred image via the image variable

Definition at line 77 of file detectUtil.cpp.

void gaussianSmoothing ( MatrixXf *  image,
float  sigma 
)

convolute an image with a Gaussian kernel

Parameters
image
sigmathe standard deviation of the kernel
Returns
via the image variable

Definition at line 53 of file detectUtil.cpp.

bool hasEnoughSkin ( MatrixXf *  image,
square  area 
)

Definition at line 223 of file detectUtil.cpp.

void highlight ( const char *  inputName,
vector< square > &  areas,
int  PPMode,
float  nFriends 
)

highlight the faces so that we can see them

Parameters
inputNamewhich image
areaswhere the found faces are

Definition at line 272 of file detectUtil.cpp.

bool isInside ( square  window1,
square  window2 
)

Definition at line 626 of file detectUtil.cpp.

bool isLegal ( square area,
int  nRows,
int  nCols 
)

Definition at line 602 of file detectUtil.cpp.

bool isSkinPixel ( int  row,
int  col,
MatrixXf *  image 
)

Definition at line 211 of file detectUtil.cpp.

void postProcessing ( int  nRows,
int  nCols,
float  nFriends,
vector< square > &  areas 
)

toss out several more false positives and beautify the highlighting

Parameters
nRows
nCols
areasselected by the cascade and refined by postProcessing

Definition at line 637 of file detectUtil.cpp.

VectorXf readInCascade ( vector< stumpRule > *&  cascade)

cascade

Parameters
cascadereturned cascade
Returns
tweaks that go with the cascade

Definition at line 158 of file detectUtil.cpp.

void rotateCoordinate ( int  input_i,
int  input_j,
int  center_i,
int  center_j,
float  theta,
int &  output_i,
int &  output_j 
)

Definition at line 933 of file detectUtil.cpp.

void rotateImage ( const char *  infile,
const char *  outfile,
float  theta,
int &  center_i,
int &  center_j 
)

Definition at line 952 of file detectUtil.cpp.

int round ( int  digit,
double  scale 
)
inline

round the real number digit*scale

Parameters
digit
scale

Definition at line 361 of file detectUtil.cpp.

void scan ( const char *  file,
int  defaultLayerNumber,
float  nFriends 
)

detect faces on an image

Parameters
fileimage name
defaultLayerNumberhow many layers should be used

Definition at line 513 of file detectUtil.cpp.

void tscan ( const char *  file,
int &  nRows,
int &  nCols,
int  defaultLayerNumber,
vector< stumpRule > *  cascade,
VectorXf &  tweaks,
vector< square > &  toMark 
)

scan the whole image using a cascade

Parameters
fileimage
defaultLayerNumberhow many layers are there in the cascade
cascade
tweaksshifts applied to the cascade layers
toMarkthe windows recognized as a face

Definition at line 550 of file detectUtil.cpp.

bool windowOrder ( square  window1,
square  window2 
)

Definition at line 619 of file detectUtil.cpp.

bool zoomOutNegative ( MatrixXf *&  image,
int  shrinkedSize,
int  defaultLayerNumber,
vector< stumpRule > *  cascade,
VectorXf &  tweaks 
)

try to make an example out of a false positive window

Parameters
imagea false positive window
defaultexample size
defaultLayerNumberhow many layers are there in the cascade
cascade
tweaksshifts applied to the cascade layers
Returns
true if image can be shrunk into a good sized false positive example (returned via the image variable) and false otherwise

Definition at line 106 of file detectUtil.cpp.