Package pycv :: Package cs :: Package cv
[hide private]
[frames] | no frames]

Package cv

source code

An umbrella package containing all Computer Vision packages.

For researchers, if you are using any of the methods in this package,
please accept the following term:
 - Any published result, involving training a weak classifier using
Haar-like features, based on running any method in the 'haar.py' 
module, must cite the following paper:
@INPROCEEDINGS{Pham2007a,
  author = {Minh-Tri Pham and Tat-Jen Cham},
  title = {Fast Training and Selection of Haar features using Statistisc in Boosting-based Face Detection},
  booktitle = {11th IEEE International Conference on Computer Vision (ICCV 2007)},
  year = {2007},
  address = {Rio de Janeiro, Brazil}
}



Submodules [hide private]

Classes [hide private]
  ImageView
A rotated rectangular view of an image.
  THaarClassifier
  ObjectDetectionInfo
  ObjectDetector
Functions [hide private]
 
fromCvMat(mat)
Convert a POINTER(CvMat) into numpy.array
source code
 
fromIplImage(img)
Convert a POINTER(IplImage) into numpy.array
source code
 
integral(img, iimg)
Convert an image of type uint8 into an image integral of type double.
source code
 
integral_uint32(img, iimg)
Convert an image of type uint8 into an image integral of type uint32.
source code
 
stats_integral(input_data, weights=None)
Similar to stats.statslist(), but integrate each image of type uint8 first, then vectorize, then do the stats.
source code
 
integral_int32(img, iimg)
Convert an image of type uint8 into an image integral of type int32.
source code
 
compute_Stats2_integral(classification_dataset, vi=True)
Given a J-class ClassificationDataset of image patches.
source code
 
make_vi(input_data)
Given a list of image patches, integrate then vectorize them all.
source code
 
train_Haar(cd, haars, crit, param1)
Take a 2-class ClassificationDataset, then train a THaarClassifier.
source code
 
train_SRClassifier(stats2, criterion, param1, nrects, nseconds)
Train Sparse Rectangular features and select the best feature classifier.
source code
 
train_refined_SRClassifier(wcd)
A training function that takes in a WeightedCDataset and produces a weak BinaryClassifier.
source code
 
train_Haar_GC(scd, cdgenerator, haars, thelambda=1.0, rmaxFRR=0.001, rmaxFAR=0.8, maxM=20)
Take a CDataset, then train a GeneralizedCascade of THaarClassifiers.
source code
 
train_Haar_UAC_filter(scd, haars, rmaxFRR=0.001, rmaxFAR=0.8)
Take a ScoringCDataset, then train a THaarClassifier 'filter' using UAC.
source code
 
project_Haar(input_data, A, ind)
Project the input data into a line using haar direction specified by coefficients 'A' and indices 'ind'
source code
 
train_Haar_with_local_stats(Binvert, haars, crit, param1)
Given local statistics, train a THaarClassifier.
source code
 
subsample_Haars(haars, ratio)
Take a set of Haar features and subsample it.
source code
 
project_SR_stats(stats2, A, ind)
Project the high-dim statistics into a line using a SR direction specified by coefficients 'A' and indices 'ind'
source code
 
get_local_stats(cd, haars)
Take a 2-class ClassificationDataset, obtain the global statistics, then project using different Haar directions.
source code
 
generate_Haars(M, N)
Find all Haar-like features, applied on a M-by-N image patch.
source code
Variables [hide private]
  __doc__
  datapath = 'M:\\utils\\Python25\\lib\\site-packages\\pycv\\cs\...
Function Details [hide private]

fromCvMat(mat)

source code 

Convert a POINTER(CvMat) into numpy.array

Input:
mat: a POINTER(CvMat)
Output:
mat2: a numpy.array

fromIplImage(img)

source code 

Convert a POINTER(IplImage) into numpy.array

Input:
img: a POINTER(IplImage)
Output:
img2: a numpy.array

integral(img, iimg)

source code 

Convert an image of type uint8 into an image integral of type double.

Input:
img: a 2D numpy.array of type uint8 iimg: a 2D numpy.array of type double of the same size to hold the data
Output:
data filled into img2, where iimg[x,y] = int( img[x,y], i = 0..x, j = 0..y )

integral_uint32(img, iimg)

source code 

Convert an image of type uint8 into an image integral of type uint32.

Input:
img: a 2D numpy.array of type uint8 iimg: a 2D numpy.array of type uint32 of the same size to hold the data
Output:
data filled into img2, where iimg[x,y] = int( img[x,y], i = 0..x, j = 0..y )

stats_integral(input_data, weights=None)

source code 

Similar to stats.statslist(), but integrate each image of type uint8 first, then vectorize, then do the stats.

Input:
input_data: a array 2D images of type uint8 (numpy.array)
Output:
w, mean, cov: total weight, mean vector and covariance matrix

integral_int32(img, iimg)

source code 

Convert an image of type uint8 into an image integral of type int32.

Input:
img: a 2D numpy.array of type uint8 iimg: a 2D numpy.array of type int32 of the same size to hold the data
Output:
data filled into img2, where iimg[x,y] = int( img[x,y], i = 0..x, j = 0..y )

compute_Stats2_integral(classification_dataset, vi=True)

source code 

Given a J-class ClassificationDataset of image patches. The patches are either in 'uint8' raw form (vi = False), or in 'double' vectorintegrated form (vi = True)

Input:
classification_dataset: a ClassificationDataset vi: input data are vectorintegrated?
Output:
stats2: a Stats2 holding the obtained statistics

make_vi(input_data)

source code 

Given a list of image patches, integrate then vectorize them all.

Input:
input_data: a numpy.array of shape (N,d,d) type uint8
Output:
output_data: the vectorized-integrated version, a numpy.array of shape (N,d*d) type float64

train_Haar(cd, haars, crit, param1)

source code 

Take a 2-class ClassificationDataset, then train a THaarClassifier. Select the 'best' Haar feature in the set. This function actually calls get_local_stats(), followed by train_Haar_with_local_stats()

Input:
cd: a 2-class ClassificationDataset haars: the generated Haar feature set crit, param1: as mentioned above
Output:
lc: a THaarClassifier, with lc.err as the estimated 'error'

train_SRClassifier(stats2, criterion, param1, nrects, nseconds)

source code 
Train Sparse Rectangular features and select the best feature classifier.

Suppose we have 2 classes c: positive and negative.
Suppose the vector-integrated version of an image of size 'len'-by-'len'
is a random vector y.
Let 'stats' be the Stats2 statistics of the two classes.
Consider 'criterion' and 'param1' described in sdGTSolve().

Now consider the following features called Sparse Rectangular features:
   H = \sum_{k=1}^{nrects} a_k \pi(x_k,y_k,w_k,h_k)
This function trains and selects the 'best' Sparse Rectangular feature
classifier based on sdGTSolve()'s criterion.
The classifier is as follows:
    return sign( (H \convolve I) - threshold )

The underlying algorithm is Differential Evolution.
It runs for 'nseconds' seconds.

:Parameters:
    stats : Stats2
        Statistics of the 2 classes
    criterion : int
        from 0 to 3, used in conjunction with param1, see sdGTSolve()
    param1 : double
        see 'criterion'
    nrects : int
        number of rectangles of the sparse feature
    nseconds : double
        this algorithm uses Differential Evolution, so this tells at
        most how many seconds to run

:Returns:
    fc: THaarClassifier
        the best feature classifier obtained
        fc.err is the estimated 'error' obtained

    ngen : int
        number of generations used in DE
    ngenome : int
        number of genomes generated in DE
    nvgenome : int
        number of *valid* genomes generated in DE

train_refined_SRClassifier(wcd)

source code 

A training function that takes in a WeightedCDataset and produces a weak BinaryClassifier.

This training function uses train_SRClassifier() to train but with 6 rectangles and 2 seconds. Also, the threshold of the weak classifier is refined after training. The objective is to minimize classification error with lambda = 1.0

Parameters:
  • wcd (WeightedCDataset) - a weighted dataset of vector-integrated patches
Returns:
fc: THaarClassifier
the best feature classifier obtained with
fc.b being the best threshold after refined fc.err is the estimated 'error' corresponding to fc.b fc.b2 is the best threshold estimated by train_SRClassifier() fc.err2 is its corresponding 'estimated error' fc.stats2e is its corresponding 1D statistics

train_Haar_GC(scd, cdgenerator, haars, thelambda=1.0, rmaxFRR=0.001, rmaxFAR=0.8, maxM=20)

source code 
Take a CDataset, then train a GeneralizedCascade of THaarClassifiers.

Input:
    scd: a 2-class ScoringCDataset -- must be vectorintegrated
        scd *is modified* after the training process
    cdgenerator: a CDGenerator that can generate negative points for scd
    haars: the generated Haar feature set
    thelambda: the goal for 'improver' is to minimize thelambda*FRR+FAR
    rmaxFRR, rmaxFAR: train 'filter' to reject if there is a classifier
        that can do FRR <= rmaxFRR and FAR <= rmaxFAR
Output:
    gc: a GeneralizedCascade

train_Haar_UAC_filter(scd, haars, rmaxFRR=0.001, rmaxFAR=0.8)

source code 
Take a ScoringCDataset, then train a THaarClassifier 'filter' using UAC.
Select the 'best' Haar feature in the set.

Input:
    scd: a ScoringCDataset -- must be vectorintegrated
    haars: the generated Haar feature set
    rmaxFRR, rmaxFAR: train 'filter' to reject if there is a classifier
        that can do FRR <= rmaxFRR and FAR <= rmaxFAR
Output:
    lc: a THaarClassifier, with:
        lc.sol: training (FRR,FAR)
    c: voting coefficient
    both lc and c will be None if there's no filter satisfied

project_Haar(input_data, A, ind)

source code 

Project the input data into a line using haar direction specified by coefficients 'A' and indices 'ind'

Input:
input_data: a vectorintegrated 2D numpy.array A,ind: coefficients and indices of a Haar feature
Output:
x: a 1D numpy.array of projected values

train_Haar_with_local_stats(Binvert, haars, crit, param1)

source code 
Given local statistics, train a THaarClassifier.
Select the 'best' Haar feature in the set.
The features are trained using one of three criteria:
    crit = 0: param1 is 'thelambda', then call gaussian.find_classification_threshold()
    crit = 1: param1 is 'minDR', then call gaussian.find_filtering_threshold()
    crit = 2: param1 is 'maxFAR', then call gaussian.find_filtering_threshold2()

Input: 
    Binvert: (B,invert), is output of get_local_stats() actually
        B: a list of J*2-class Stats2e, each for each type of Haar features.
        invert: a list of numpy.arrays, each array tells whether which feature
            needs negating its projection direction
    haars: the generated Haar feature set of J features
    crit, param1: as mentioned above
Output:
    lc: a THaarClassifier, with lc.err as the estimated 'error'

subsample_Haars(haars, ratio)

source code 
Take a set of Haar features and subsample it.

Input:
    haars: a set of Haar features, output of generate_Haars()
    ratio: the ratio to subsample, if 'haars' has N features,
        the output 'haars' will have roughly ratio*N features
Output:
    ohaars: a smaller set of Haar features

project_SR_stats(stats2, A, ind)

source code 
Project the high-dim statistics into a line using a SR direction specified by coefficients 'A' and indices 'ind'
Parameters:
  • stats2, Stats2 - a vectorintegrated 2D numpy.array
  • ind, array(shape=(n, ), dtype='int') - indices of the SR feature
  • A, array(shape=(n, ), dtype='double') - coefficients of the SR feature
Returns:
stats2e: a 1D Stats2e representing the projected result

get_local_stats(cd, haars)

source code 

Take a 2-class ClassificationDataset, obtain the global statistics,
then project using different Haar directions.

Input:
    cd: a 2-class ClassificationDataset
    haars: the generated Haar feature set of J features
Output: output of _project_Haar_stats() actually
    B: a list of J*2-class Stats2e, each for each type of Haar features.
    invert: a list of numpy.arrays, each array tells whether which feature
        needs negating its projection direction

generate_Haars(M, N)

source code 

Find all Haar-like features, applied on a M-by-N image patch.

Input:
M, N: number of rows and columns of an image patch
Output:
haars: a list of tuples (A,ind,ind2) output from _features_from_shape()

Variables Details [hide private]

datapath

Value:
'M:\\utils\\Python25\\lib\\site-packages\\pycv\\cs\\cv\\data'