Normalize line endings and whitespace

This commit is contained in:
OpenCV Buildbot
2012-10-17 03:18:30 +04:00
committed by Andrey Kamaev
parent 69020da607
commit 04384a71e4
1516 changed files with 258846 additions and 258162 deletions

View File

@@ -1,398 +1,398 @@
/*****************************************************************************/
/* Latent SVM prediction API */
/*****************************************************************************/
#ifndef _LATENTSVM_H_
#define _LATENTSVM_H_
#include <stdio.h>
#include "_lsvm_types.h"
#include "_lsvm_error.h"
#include "_lsvm_routine.h"
//////////////////////////////////////////////////////////////
// Building feature pyramid
// (pyramid constructed both contrast and non-contrast image)
//////////////////////////////////////////////////////////////
/*
// Getting feature pyramid
//
// API
// int getFeaturePyramid(IplImage * image, const filterObject **all_F,
const int n_f,
const int lambda, const int k,
const int startX, const int startY,
const int W, const int H, featurePyramid **maps);
// INPUT
// image - image
// lambda - resize scale
// k - size of cells
// startX - X coordinate of the image rectangle to search
// startY - Y coordinate of the image rectangle to search
// W - width of the image rectangle to search
// H - height of the image rectangle to search
// OUTPUT
// maps - feature maps for all levels
// RESULT
// Error status
*/
int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramid **maps);
/*
// Getting feature map for the selected subimage
//
// API
// int getFeatureMaps(const IplImage * image, const int k, featureMap **map);
// INPUT
// image - selected subimage
// k - size of cells
// OUTPUT
// map - feature map
// RESULT
// Error status
*/
int getFeatureMaps(const IplImage * image, const int k, CvLSVMFeatureMap **map);
/*
// Feature map Normalization and Truncation
//
// API
// int normalizationAndTruncationFeatureMaps(featureMap *map, const float alfa);
// INPUT
// map - feature map
// alfa - truncation threshold
// OUTPUT
// map - truncated and normalized feature map
// RESULT
// Error status
*/
int normalizeAndTruncate(CvLSVMFeatureMap *map, const float alfa);
/*
// Feature map reduction
// In each cell we reduce dimension of the feature vector
// according to original paper special procedure
//
// API
// int PCAFeatureMaps(featureMap *map)
// INPUT
// map - feature map
// OUTPUT
// map - feature map
// RESULT
// Error status
*/
int PCAFeatureMaps(CvLSVMFeatureMap *map);
//////////////////////////////////////////////////////////////
// search object
//////////////////////////////////////////////////////////////
/*
// Transformation filter displacement from the block space
// to the space of pixels at the initial image
//
// API
// int convertPoints(int countLevel, int lambda,
int initialImageLevel,
CvPoint *points, int *levels,
CvPoint **partsDisplacement, int kPoints, int n,
int maxXBorder,
int maxYBorder);
// INPUT
// countLevel - the number of levels in the feature pyramid
// lambda - method parameter
// initialImageLevel - level of feature pyramid that contains feature map
for initial image
// points - the set of root filter positions (in the block space)
// levels - the set of levels
// partsDisplacement - displacement of part filters (in the block space)
// kPoints - number of root filter positions
// n - number of part filters
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// OUTPUT
// points - the set of root filter positions (in the space of pixels)
// partsDisplacement - displacement of part filters (in the space of pixels)
// RESULT
// Error status
*/
int convertPoints(int countLevel, int lambda,
int initialImageLevel,
CvPoint *points, int *levels,
CvPoint **partsDisplacement, int kPoints, int n,
int maxXBorder,
int maxYBorder);
/*
// Elimination boxes that are outside the image boudaries
//
// API
// int clippingBoxes(int width, int height,
CvPoint *points, int kPoints);
// INPUT
// width - image wediht
// height - image heigth
// points - a set of points (coordinates of top left or
bottom right corners)
// kPoints - points number
// OUTPUT
// points - updated points (if coordinates less than zero then
set zero coordinate, if coordinates more than image
size then set coordinates equal image size)
// RESULT
// Error status
*/
#ifdef __cplusplus
extern "C"
#endif
int clippingBoxes(int width, int height,
CvPoint *points, int kPoints);
/*
// Creation feature pyramid with nullable border
//
// API
// featurePyramid* createFeaturePyramidWithBorder(const IplImage *image,
int maxXBorder, int maxYBorder);
// INPUT
// image - initial image
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// OUTPUT
// RESULT
// Feature pyramid with nullable border
*/
#ifdef __cplusplus
extern "C"
#endif
CvLSVMFeaturePyramid* createFeaturePyramidWithBorder(IplImage *image,
int maxXBorder, int maxYBorder);
/*
// Computation of the root filter displacement and values of score function
//
// API
// int searchObject(const featurePyramid *H, const filterObject **all_F, int n,
float b,
int maxXBorder,
int maxYBorder,
CvPoint **points, int **levels, int *kPoints, float *score,
CvPoint ***partsDisplacement);
// INPUT
// H - feature pyramid
// all_F - the set of filters (the first element is root filter,
other elements - part filters)
// n - the number of part filters
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// OUTPUT
// points - positions (x, y) of the upper-left corner
of root filter frame
// levels - levels that correspond to each position
// kPoints - number of positions
// score - value of the score function
// partsDisplacement - part filters displacement for each position
of the root filter
// RESULT
// Error status
*/
int searchObject(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F, int n,
float b,
int maxXBorder,
int maxYBorder,
CvPoint **points, int **levels, int *kPoints, float *score,
CvPoint ***partsDisplacement);
/*
// Computation of the root filter displacement and values of score function
//
// API
// int searchObjectThreshold(const featurePyramid *H,
const filterObject **all_F, int n,
float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
CvPoint **points, int **levels, int *kPoints,
float **score, CvPoint ***partsDisplacement);
// INPUT
// H - feature pyramid
// all_F - the set of filters (the first element is root filter,
other elements - part filters)
// n - the number of part filters
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// scoreThreshold - score threshold
// OUTPUT
// points - positions (x, y) of the upper-left corner
of root filter frame
// levels - levels that correspond to each position
// kPoints - number of positions
// score - values of the score function
// partsDisplacement - part filters displacement for each position
of the root filter
// RESULT
// Error status
*/
int searchObjectThreshold(const CvLSVMFeaturePyramid *H,
const CvLSVMFilterObject **all_F, int n,
float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
CvPoint **points, int **levels, int *kPoints,
float **score, CvPoint ***partsDisplacement,
int numThreads CV_DEFAULT(-1));
/*
// Computation root filters displacement and values of score function
//
// API
// int searchObjectThresholdSomeComponents(const featurePyramid *H,
const filterObject **filters,
int kComponents, const int *kPartFilters,
const float *b, float scoreThreshold,
CvPoint **points, CvPoint **oppPoints,
float **score, int *kPoints);
// INPUT
// H - feature pyramid
// filters - filters (root filter then it's part filters, etc.)
// kComponents - root filters number
// kPartFilters - array of part filters number for each component
// b - array of linear terms
// scoreThreshold - score threshold
// OUTPUT
// points - root filters displacement (top left corners)
// oppPoints - root filters displacement (bottom right corners)
// score - array of score values
// kPoints - number of boxes
// RESULT
// Error status
*/
#ifdef __cplusplus
extern "C"
#endif
int searchObjectThresholdSomeComponents(const CvLSVMFeaturePyramid *H,
const CvLSVMFilterObject **filters,
int kComponents, const int *kPartFilters,
const float *b, float scoreThreshold,
CvPoint **points, CvPoint **oppPoints,
float **score, int *kPoints, int numThreads);
/*
// Compute opposite point for filter box
//
// API
// int getOppositePoint(CvPoint point,
int sizeX, int sizeY,
float step, int degree,
CvPoint *oppositePoint);
// INPUT
// point - coordinates of filter top left corner
(in the space of pixels)
// (sizeX, sizeY) - filter dimension in the block space
// step - scaling factor
// degree - degree of the scaling factor
// OUTPUT
// oppositePoint - coordinates of filter bottom corner
(in the space of pixels)
// RESULT
// Error status
*/
int getOppositePoint(CvPoint point,
int sizeX, int sizeY,
float step, int degree,
CvPoint *oppositePoint);
/*
// Drawing root filter boxes
//
// API
// int showRootFilterBoxes(const IplImage *image,
const filterObject *filter,
CvPoint *points, int *levels, int kPoints,
CvScalar color, int thickness,
int line_type, int shift);
// INPUT
// image - initial image
// filter - root filter object
// points - a set of points
// levels - levels of feature pyramid
// kPoints - number of points
// color - line color for each box
// thickness - line thickness
// line_type - line type
// shift - shift
// OUTPUT
// window contained initial image and filter boxes
// RESULT
// Error status
*/
int showRootFilterBoxes(IplImage *image,
const CvLSVMFilterObject *filter,
CvPoint *points, int *levels, int kPoints,
CvScalar color, int thickness,
int line_type, int shift);
/*
// Drawing part filter boxes
//
// API
// int showPartFilterBoxes(const IplImage *image,
const filterObject *filter,
CvPoint *points, int *levels, int kPoints,
CvScalar color, int thickness,
int line_type, int shift);
// INPUT
// image - initial image
// filters - a set of part filters
// n - number of part filters
// partsDisplacement - a set of points
// levels - levels of feature pyramid
// kPoints - number of foot filter positions
// color - line color for each box
// thickness - line thickness
// line_type - line type
// shift - shift
// OUTPUT
// window contained initial image and filter boxes
// RESULT
// Error status
*/
int showPartFilterBoxes(IplImage *image,
const CvLSVMFilterObject **filters,
int n, CvPoint **partsDisplacement,
int *levels, int kPoints,
CvScalar color, int thickness,
int line_type, int shift);
/*
// Drawing boxes
//
// API
// int showBoxes(const IplImage *img,
const CvPoint *points, const CvPoint *oppositePoints, int kPoints,
CvScalar color, int thickness, int line_type, int shift);
// INPUT
// img - initial image
// points - top left corner coordinates
// oppositePoints - right bottom corner coordinates
// kPoints - points number
// color - line color for each box
// thickness - line thickness
// line_type - line type
// shift - shift
// OUTPUT
// RESULT
// Error status
*/
int showBoxes(IplImage *img,
const CvPoint *points, const CvPoint *oppositePoints, int kPoints,
CvScalar color, int thickness, int line_type, int shift);
#endif
/*****************************************************************************/
/* Latent SVM prediction API */
/*****************************************************************************/
#ifndef _LATENTSVM_H_
#define _LATENTSVM_H_
#include <stdio.h>
#include "_lsvm_types.h"
#include "_lsvm_error.h"
#include "_lsvm_routine.h"
//////////////////////////////////////////////////////////////
// Building feature pyramid
// (pyramid constructed both contrast and non-contrast image)
//////////////////////////////////////////////////////////////
/*
// Getting feature pyramid
//
// API
// int getFeaturePyramid(IplImage * image, const filterObject **all_F,
const int n_f,
const int lambda, const int k,
const int startX, const int startY,
const int W, const int H, featurePyramid **maps);
// INPUT
// image - image
// lambda - resize scale
// k - size of cells
// startX - X coordinate of the image rectangle to search
// startY - Y coordinate of the image rectangle to search
// W - width of the image rectangle to search
// H - height of the image rectangle to search
// OUTPUT
// maps - feature maps for all levels
// RESULT
// Error status
*/
int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramid **maps);
/*
// Getting feature map for the selected subimage
//
// API
// int getFeatureMaps(const IplImage * image, const int k, featureMap **map);
// INPUT
// image - selected subimage
// k - size of cells
// OUTPUT
// map - feature map
// RESULT
// Error status
*/
int getFeatureMaps(const IplImage * image, const int k, CvLSVMFeatureMap **map);
/*
// Feature map Normalization and Truncation
//
// API
// int normalizationAndTruncationFeatureMaps(featureMap *map, const float alfa);
// INPUT
// map - feature map
// alfa - truncation threshold
// OUTPUT
// map - truncated and normalized feature map
// RESULT
// Error status
*/
int normalizeAndTruncate(CvLSVMFeatureMap *map, const float alfa);
/*
// Feature map reduction
// In each cell we reduce dimension of the feature vector
// according to original paper special procedure
//
// API
// int PCAFeatureMaps(featureMap *map)
// INPUT
// map - feature map
// OUTPUT
// map - feature map
// RESULT
// Error status
*/
int PCAFeatureMaps(CvLSVMFeatureMap *map);
//////////////////////////////////////////////////////////////
// search object
//////////////////////////////////////////////////////////////
/*
// Transformation filter displacement from the block space
// to the space of pixels at the initial image
//
// API
// int convertPoints(int countLevel, int lambda,
int initialImageLevel,
CvPoint *points, int *levels,
CvPoint **partsDisplacement, int kPoints, int n,
int maxXBorder,
int maxYBorder);
// INPUT
// countLevel - the number of levels in the feature pyramid
// lambda - method parameter
// initialImageLevel - level of feature pyramid that contains feature map
for initial image
// points - the set of root filter positions (in the block space)
// levels - the set of levels
// partsDisplacement - displacement of part filters (in the block space)
// kPoints - number of root filter positions
// n - number of part filters
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// OUTPUT
// points - the set of root filter positions (in the space of pixels)
// partsDisplacement - displacement of part filters (in the space of pixels)
// RESULT
// Error status
*/
int convertPoints(int countLevel, int lambda,
int initialImageLevel,
CvPoint *points, int *levels,
CvPoint **partsDisplacement, int kPoints, int n,
int maxXBorder,
int maxYBorder);
/*
// Elimination boxes that are outside the image boudaries
//
// API
// int clippingBoxes(int width, int height,
CvPoint *points, int kPoints);
// INPUT
// width - image wediht
// height - image heigth
// points - a set of points (coordinates of top left or
bottom right corners)
// kPoints - points number
// OUTPUT
// points - updated points (if coordinates less than zero then
set zero coordinate, if coordinates more than image
size then set coordinates equal image size)
// RESULT
// Error status
*/
#ifdef __cplusplus
extern "C"
#endif
int clippingBoxes(int width, int height,
CvPoint *points, int kPoints);
/*
// Creation feature pyramid with nullable border
//
// API
// featurePyramid* createFeaturePyramidWithBorder(const IplImage *image,
int maxXBorder, int maxYBorder);
// INPUT
// image - initial image
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// OUTPUT
// RESULT
// Feature pyramid with nullable border
*/
#ifdef __cplusplus
extern "C"
#endif
CvLSVMFeaturePyramid* createFeaturePyramidWithBorder(IplImage *image,
int maxXBorder, int maxYBorder);
/*
// Computation of the root filter displacement and values of score function
//
// API
// int searchObject(const featurePyramid *H, const filterObject **all_F, int n,
float b,
int maxXBorder,
int maxYBorder,
CvPoint **points, int **levels, int *kPoints, float *score,
CvPoint ***partsDisplacement);
// INPUT
// H - feature pyramid
// all_F - the set of filters (the first element is root filter,
other elements - part filters)
// n - the number of part filters
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// OUTPUT
// points - positions (x, y) of the upper-left corner
of root filter frame
// levels - levels that correspond to each position
// kPoints - number of positions
// score - value of the score function
// partsDisplacement - part filters displacement for each position
of the root filter
// RESULT
// Error status
*/
int searchObject(const CvLSVMFeaturePyramid *H, const CvLSVMFilterObject **all_F, int n,
float b,
int maxXBorder,
int maxYBorder,
CvPoint **points, int **levels, int *kPoints, float *score,
CvPoint ***partsDisplacement);
/*
// Computation of the root filter displacement and values of score function
//
// API
// int searchObjectThreshold(const featurePyramid *H,
const filterObject **all_F, int n,
float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
CvPoint **points, int **levels, int *kPoints,
float **score, CvPoint ***partsDisplacement);
// INPUT
// H - feature pyramid
// all_F - the set of filters (the first element is root filter,
other elements - part filters)
// n - the number of part filters
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// scoreThreshold - score threshold
// OUTPUT
// points - positions (x, y) of the upper-left corner
of root filter frame
// levels - levels that correspond to each position
// kPoints - number of positions
// score - values of the score function
// partsDisplacement - part filters displacement for each position
of the root filter
// RESULT
// Error status
*/
int searchObjectThreshold(const CvLSVMFeaturePyramid *H,
const CvLSVMFilterObject **all_F, int n,
float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
CvPoint **points, int **levels, int *kPoints,
float **score, CvPoint ***partsDisplacement,
int numThreads CV_DEFAULT(-1));
/*
// Computation root filters displacement and values of score function
//
// API
// int searchObjectThresholdSomeComponents(const featurePyramid *H,
const filterObject **filters,
int kComponents, const int *kPartFilters,
const float *b, float scoreThreshold,
CvPoint **points, CvPoint **oppPoints,
float **score, int *kPoints);
// INPUT
// H - feature pyramid
// filters - filters (root filter then it's part filters, etc.)
// kComponents - root filters number
// kPartFilters - array of part filters number for each component
// b - array of linear terms
// scoreThreshold - score threshold
// OUTPUT
// points - root filters displacement (top left corners)
// oppPoints - root filters displacement (bottom right corners)
// score - array of score values
// kPoints - number of boxes
// RESULT
// Error status
*/
#ifdef __cplusplus
extern "C"
#endif
int searchObjectThresholdSomeComponents(const CvLSVMFeaturePyramid *H,
const CvLSVMFilterObject **filters,
int kComponents, const int *kPartFilters,
const float *b, float scoreThreshold,
CvPoint **points, CvPoint **oppPoints,
float **score, int *kPoints, int numThreads);
/*
// Compute opposite point for filter box
//
// API
// int getOppositePoint(CvPoint point,
int sizeX, int sizeY,
float step, int degree,
CvPoint *oppositePoint);
// INPUT
// point - coordinates of filter top left corner
(in the space of pixels)
// (sizeX, sizeY) - filter dimension in the block space
// step - scaling factor
// degree - degree of the scaling factor
// OUTPUT
// oppositePoint - coordinates of filter bottom corner
(in the space of pixels)
// RESULT
// Error status
*/
int getOppositePoint(CvPoint point,
int sizeX, int sizeY,
float step, int degree,
CvPoint *oppositePoint);
/*
// Drawing root filter boxes
//
// API
// int showRootFilterBoxes(const IplImage *image,
const filterObject *filter,
CvPoint *points, int *levels, int kPoints,
CvScalar color, int thickness,
int line_type, int shift);
// INPUT
// image - initial image
// filter - root filter object
// points - a set of points
// levels - levels of feature pyramid
// kPoints - number of points
// color - line color for each box
// thickness - line thickness
// line_type - line type
// shift - shift
// OUTPUT
// window contained initial image and filter boxes
// RESULT
// Error status
*/
int showRootFilterBoxes(IplImage *image,
const CvLSVMFilterObject *filter,
CvPoint *points, int *levels, int kPoints,
CvScalar color, int thickness,
int line_type, int shift);
/*
// Drawing part filter boxes
//
// API
// int showPartFilterBoxes(const IplImage *image,
const filterObject *filter,
CvPoint *points, int *levels, int kPoints,
CvScalar color, int thickness,
int line_type, int shift);
// INPUT
// image - initial image
// filters - a set of part filters
// n - number of part filters
// partsDisplacement - a set of points
// levels - levels of feature pyramid
// kPoints - number of foot filter positions
// color - line color for each box
// thickness - line thickness
// line_type - line type
// shift - shift
// OUTPUT
// window contained initial image and filter boxes
// RESULT
// Error status
*/
int showPartFilterBoxes(IplImage *image,
const CvLSVMFilterObject **filters,
int n, CvPoint **partsDisplacement,
int *levels, int kPoints,
CvScalar color, int thickness,
int line_type, int shift);
/*
// Drawing boxes
//
// API
// int showBoxes(const IplImage *img,
const CvPoint *points, const CvPoint *oppositePoints, int kPoints,
CvScalar color, int thickness, int line_type, int shift);
// INPUT
// img - initial image
// points - top left corner coordinates
// oppositePoints - right bottom corner coordinates
// kPoints - points number
// color - line color for each box
// thickness - line thickness
// line_type - line type
// shift - shift
// OUTPUT
// RESULT
// Error status
*/
int showBoxes(IplImage *img,
const CvPoint *points, const CvPoint *oppositePoints, int kPoints,
CvScalar color, int thickness, int line_type, int shift);
#endif

View File

@@ -11,8 +11,8 @@
// a(y - q2) + b(q2 - y)(q2 - y) + f[q2]
//
// API
// int GetPointOfIntersection(const F_type *f,
const F_type a, const F_type b,
// int GetPointOfIntersection(const F_type *f,
const F_type a, const F_type b,
int q1, int q2, F_type *point);
// INPUT
// f - function on the regular grid
@@ -25,8 +25,8 @@
// RESULT
// Error status
*/
int GetPointOfIntersection(const float *f,
const float a, const float b,
int GetPointOfIntersection(const float *f,
const float a, const float b,
int q1, int q2, float *point);
/*
@@ -36,9 +36,9 @@ int GetPointOfIntersection(const float *f,
//
// API
// int DistanceTransformOneDimensionalProblem(const F_type *f, const int n,
const F_type a, const F_type b,
const F_type a, const F_type b,
F_type *distanceTransform,
int *points);
int *points);
// INPUT
// f - function on the regular grid
// n - grid dimension
@@ -51,9 +51,9 @@ int GetPointOfIntersection(const float *f,
// Error status
*/
int DistanceTransformOneDimensionalProblem(const float *f, const int n,
const float a, const float b,
const float a, const float b,
float *distanceTransform,
int *points);
int *points);
/*
// Computation next cycle element
@@ -106,21 +106,21 @@ void Transpose(float *a, int n, int m);
/*
// Decision of two dimensional problem generalized distance transform
// on the regular grid at all points
// min{d2(y' - y) + d4(y' - y)(y' - y) +
// min{d2(y' - y) + d4(y' - y)(y' - y) +
min(d1(x' - x) + d3(x' - x)(x' - x) + f(x',y'))} (on x', y')
//
// API
// int DistanceTransformTwoDimensionalProblem(const F_type *f,
// int DistanceTransformTwoDimensionalProblem(const F_type *f,
const int n, const int m,
const F_type coeff[4],
const F_type coeff[4],
F_type *distanceTransform,
int *pointsX, int *pointsY);
int *pointsX, int *pointsY);
// INPUT
// f - function on the regular grid
// n - number of rows
// m - number of columns
// coeff - coefficients of optimizable function
coeff[0] = d1, coeff[1] = d2,
coeff[0] = d1, coeff[1] = d2,
coeff[2] = d3, coeff[3] = d4
// OUTPUT
// distanceTransform - values of generalized distance transform
@@ -129,10 +129,10 @@ void Transpose(float *a, int n, int m);
// RESULT
// Error status
*/
int DistanceTransformTwoDimensionalProblem(const float *f,
int DistanceTransformTwoDimensionalProblem(const float *f,
const int n, const int m,
const float coeff[4],
const float coeff[4],
float *distanceTransform,
int *pointsX, int *pointsY);
int *pointsX, int *pointsY);
#endif

View File

@@ -9,13 +9,13 @@
// 1-dimensional FFT
//
// API
// int fft(float *x_in, float *x_out, int n, int shift);
// int fft(float *x_in, float *x_out, int n, int shift);
// INPUT
// x_in - input signal
// n - number of elements for searching Fourier image
// shift - shift between input elements
// OUTPUT
// x_out - output signal (contains 2n elements in order
// x_out - output signal (contains 2n elements in order
Re(x_in[0]), Im(x_in[0]), Re(x_in[1]), Im(x_in[1]) and etc.)
// RESULT
// Error status
@@ -28,8 +28,8 @@ int fft(float *x_in, float *x_out, int n, int shift);
// API
// int fftInverse(float *x_in, float *x_out, int n, int shift);
// INPUT
// x_in - Fourier image of 1d input signal(contains 2n elements
in order Re(x_in[0]), Im(x_in[0]),
// x_in - Fourier image of 1d input signal(contains 2n elements
in order Re(x_in[0]), Im(x_in[0]),
Re(x_in[1]), Im(x_in[1]) and etc.)
// n - number of elements for searching counter FFT image
// shift - shift between input elements
@@ -51,7 +51,7 @@ int fftInverse(float *x_in, float *x_out, int n, int shift);
// numColls - number of collumns
// OUTPUT
// x_out - output signal (contains (2 * numRows * numColls) elements
in order Re(x_in[0][0]), Im(x_in[0][0]),
in order Re(x_in[0][0]), Im(x_in[0][0]),
Re(x_in[0][1]), Im(x_in[0][1]) and etc.)
// RESULT
// Error status
@@ -64,8 +64,8 @@ int fft2d(float *x_in, float *x_out, int numRows, int numColls);
// API
// int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls);
// INPUT
// x_in - Fourier image of matrix (contains (2 * numRows * numColls)
elements in order Re(x_in[0][0]), Im(x_in[0][0]),
// x_in - Fourier image of matrix (contains (2 * numRows * numColls)
elements in order Re(x_in[0][0]), Im(x_in[0][0]),
Re(x_in[0][1]), Im(x_in[0][1]) and etc.)
// numRows - number of rows
// numColls - number of collumns

View File

@@ -18,7 +18,7 @@
//extern "C" {
/*
// Function for convolution computation
//
//
// API
// int convolution(const filterObject *Fi, const featureMap *map, float *f);
// INPUT
@@ -35,7 +35,7 @@ int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float
// Computation multiplication of FFT images
//
// API
// int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
// int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
float *multi);
// INPUT
// fftImage1 - first fft image
@@ -46,14 +46,14 @@ int convolution(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *map, float
// RESULT
// Error status
*/
int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls,
float *multi);
/*
// Turnover filter matrix for the single feature
//
// API
// int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
// int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
int p, int shift);
// INPUT
// filter - filter weight matrix
@@ -65,14 +65,14 @@ int fftImagesMulti(float *fftImage1, float *fftImage2, int numRows, int numColls
// RESULT
// Error status
*/
int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
int p, int shift);
/*
// Addition nullable bars to the dimension of feature map (single feature)
//
// API
// int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
// int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
float *newFilter, int newDimX, int newDimY);
// INPUT
// rot2PIFilter - filter matrix for the single feature that was rotated
@@ -83,14 +83,14 @@ int rot2PI(float *filter, int dimX, int dimY, float *rot2PIFilter,
// RESULT
// Error status
*/
int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
float *newFilter, int newDimX, int newDimY);
/*
// Computation FFT image for filter object
//
// API
// int getFFTImageFilterObject(const filterObject *filter,
// int getFFTImageFilterObject(const filterObject *filter,
int mapDimX, int mapDimY,
fftImage **image);
// INPUT
@@ -101,7 +101,7 @@ int addNullableBars(float *rot2PIFilter, int dimX, int dimY,
// RESULT
// Error status
*/
int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
int getFFTImageFilterObject(const CvLSVMFilterObject *filter,
int mapDimX, int mapDimY,
CvLSVMFftImage **image);
@@ -119,9 +119,9 @@ int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image);
/*
// Function for convolution computation using FFT
//
//
// API
// int convFFTConv2d(const fftImage *featMapImage, const fftImage *filterImage,
// int convFFTConv2d(const fftImage *featMapImage, const fftImage *filterImage,
int filterDimX, int filterDimY, float **conv);
// INPUT
// featMapImage - feature map image
@@ -132,7 +132,7 @@ int getFFTImageFeatureMap(const CvLSVMFeatureMap *map, CvLSVMFftImage **image);
// RESULT
// Error status
*/
int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filterImage,
int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filterImage,
int filterDimX, int filterDimY, float **conv);
/*
@@ -140,21 +140,21 @@ int convFFTConv2d(const CvLSVMFftImage *featMapImage, const CvLSVMFftImage *filt
//
// API
// int filterDispositionLevel(const filterObject *Fi, const featureMap *pyramid,
float **scoreFi,
float **scoreFi,
int **pointsX, int **pointsY);
// INPUT
// Fi - filter object (weights and coefficients of penalty
// Fi - filter object (weights and coefficients of penalty
function that are used in this routine)
// pyramid - feature map
// OUTPUT
// scoreFi - values of distance transform on the level at all positions
// (pointsX, pointsY)- positions that correspond to the maximum value
// (pointsX, pointsY)- positions that correspond to the maximum value
of distance transform at all grid nodes
// RESULT
// Error status
*/
int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap *pyramid,
float **scoreFi,
float **scoreFi,
int **pointsX, int **pointsY);
/*
@@ -162,21 +162,21 @@ int filterDispositionLevel(const CvLSVMFilterObject *Fi, const CvLSVMFeatureMap
//
// API
// int filterDispositionLevelFFT(const filterObject *Fi, const fftImage *featMapImage,
float **scoreFi,
float **scoreFi,
int **pointsX, int **pointsY);
// INPUT
// Fi - filter object (weights and coefficients of penalty
// Fi - filter object (weights and coefficients of penalty
function that are used in this routine)
// featMapImage - FFT image of feature map
// OUTPUT
// scoreFi - values of distance transform on the level at all positions
// (pointsX, pointsY)- positions that correspond to the maximum value
// (pointsX, pointsY)- positions that correspond to the maximum value
of distance transform at all grid nodes
// RESULT
// Error status
*/
int filterDispositionLevelFFT(const CvLSVMFilterObject *Fi, const CvLSVMFftImage *featMapImage,
float **scoreFi,
float **scoreFi,
int **pointsX, int **pointsY);
/*
@@ -214,14 +214,14 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by);
// Computation the maximum of the score function at the level
//
// API
// int maxFunctionalScoreFixedLevel(const filterObject **all_F, int n,
const featurePyramid *H,
int level, float b,
int maxXBorder, int maxYBorder,
// int maxFunctionalScoreFixedLevel(const filterObject **all_F, int n,
const featurePyramid *H,
int level, float b,
int maxXBorder, int maxYBorder,
float *score, CvPoint **points, int *kPoints,
CvPoint ***partsDisplacement);
// INPUT
// all_F - the set of filters (the first element is root filter,
// all_F - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
@@ -238,10 +238,10 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by);
// RESULT
// Error status
*/
int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
int level, float b,
int maxXBorder, int maxYBorder,
int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
int level, float b,
int maxXBorder, int maxYBorder,
float *score, CvPoint **points, int *kPoints,
CvPoint ***partsDisplacement);
@@ -249,15 +249,15 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
// Computation score function at the level that exceed threshold
//
// API
// int thresholdFunctionalScoreFixedLevel(const filterObject **all_F, int n,
const featurePyramid *H,
int level, float b,
// int thresholdFunctionalScoreFixedLevel(const filterObject **all_F, int n,
const featurePyramid *H,
int level, float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
float **score, CvPoint **points, int *kPoints,
CvPoint ***partsDisplacement);
// INPUT
// all_F - the set of filters (the first element is root filter,
// all_F - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
@@ -275,9 +275,9 @@ int maxFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
// RESULT
// Error status
*/
int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
int level, float b,
int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
int level, float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
float **score, CvPoint **points, int *kPoints,
@@ -287,14 +287,14 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
// Computation the maximum of the score function
//
// API
// int maxFunctionalScore(const filterObject **all_F, int n,
const featurePyramid *H, float b,
// int maxFunctionalScore(const filterObject **all_F, int n,
const featurePyramid *H, float b,
int maxXBorder, int maxYBorder,
float *score,
float *score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
// INPUT
// all_F - the set of filters (the first element is root filter,
// all_F - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
@@ -310,10 +310,10 @@ int thresholdFunctionalScoreFixedLevel(const CvLSVMFilterObject **all_F, int n,
// RESULT
// Error status
*/
int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H, float b,
int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H, float b,
int maxXBorder, int maxYBorder,
float *score,
float *score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
@@ -321,16 +321,16 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// Computation score function that exceed threshold
//
// API
// int thresholdFunctionalScore(const filterObject **all_F, int n,
const featurePyramid *H,
float b,
// int thresholdFunctionalScore(const filterObject **all_F, int n,
const featurePyramid *H,
float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
float **score,
float **score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
// INPUT
// all_F - the set of filters (the first element is root filter,
// all_F - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
@@ -347,28 +347,28 @@ int maxFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// RESULT
// Error status
*/
int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
float b,
int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
float b,
int maxXBorder, int maxYBorder,
float scoreThreshold,
float **score,
float **score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
#ifdef HAVE_TBB
/*
// int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
const float b,
// int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
const int threadsNum,
float **score,
float **score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
// INPUT
// all_F - the set of filters (the first element is root filter,
// all_F - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
@@ -386,13 +386,13 @@ int thresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// RESULT
// Error status
*/
int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
const float b,
int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
const CvLSVMFeaturePyramid *H,
const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
const int threadsNum,
float **score,
float **score,
CvPoint **points, int **levels, int *kPoints,
CvPoint ***partsDisplacement);
#endif
@@ -402,18 +402,18 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
// to remove "similar" bounding boxes
//
// API
// int nonMaximumSuppression(int numBoxes, const CvPoint *points,
// int nonMaximumSuppression(int numBoxes, const CvPoint *points,
const CvPoint *oppositePoints, const float *score,
float overlapThreshold,
int *numBoxesout, CvPoint **pointsOut,
float overlapThreshold,
int *numBoxesout, CvPoint **pointsOut,
CvPoint **oppositePointsOut, float **scoreOut);
// INPUT
// numBoxes - number of bounding boxes
// points - array of left top corner coordinates
// oppositePoints - array of right bottom corner coordinates
// score - array of detection scores
// overlapThreshold - threshold: bounding box is removed if overlap part
is greater than passed value
// overlapThreshold - threshold: bounding box is removed if overlap part
is greater than passed value
// OUTPUT
// numBoxesOut - the number of bounding boxes algorithm returns
// pointsOut - array of left top corner coordinates
@@ -425,16 +425,16 @@ int tbbThresholdFunctionalScore(const CvLSVMFilterObject **all_F, int n,
#ifdef __cplusplus
extern "C"
#endif
int nonMaximumSuppression(int numBoxes, const CvPoint *points,
int nonMaximumSuppression(int numBoxes, const CvPoint *points,
const CvPoint *oppositePoints, const float *score,
float overlapThreshold,
int *numBoxesOut, CvPoint **pointsOut,
float overlapThreshold,
int *numBoxesOut, CvPoint **pointsOut,
CvPoint **oppositePointsOut, float **scoreOut);
#ifdef __cplusplus
extern "C"
#endif
int getMaxFilterDims(const CvLSVMFilterObject **filters, int kComponents,
const int *kPartFilters,
const int *kPartFilters,
unsigned int *maxXBorder, unsigned int *maxYBorder);
//}
#endif

View File

@@ -12,7 +12,7 @@
// with all fields including arrays
// Error status is return value
//////////////////////////////////////////////////////////////
int allocFilterObject(CvLSVMFilterObject **obj, const int sizeX, const int sizeY,
int allocFilterObject(CvLSVMFilterObject **obj, const int sizeX, const int sizeY,
const int p);
int freeFilterObject (CvLSVMFilterObject **obj);
@@ -23,7 +23,7 @@ int freeFeatureMapObject (CvLSVMFeatureMap **obj);
#ifdef __cplusplus
extern "C"
#endif
int allocFeaturePyramidObject(CvLSVMFeaturePyramid **obj,
int allocFeaturePyramidObject(CvLSVMFeaturePyramid **obj,
const int countLevel);
#ifdef __cplusplus

View File

@@ -1,51 +1,51 @@
#ifndef _LSVM_TBBVERSION_H
#define _LSVM_TBBVERSION_H
#include "_lsvm_matching.h"
/*
// Computation score function using TBB tasks
//
// API
// int tbbTasksThresholdFunctionalScore(const CvLSVMFilterObject **filters, const int n,
const CvLSVMFeaturePyramid *H, const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
int *kLevels, int **procLevels,
const int threadsNum,
float **score, CvPoint ***points,
int *kPoints,
CvPoint ****partsDisplacement);
// INPUT
// filters - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// scoreThreshold - score threshold
// kLevels - array that contains number of levels processed
by each thread
// procLevels - array that contains lists of levels processed
by each thread
// threadsNum - the number of created threads
// OUTPUT
// score - score function values that exceed threshold
// points - the set of root filter positions (in the block space)
// kPoints - number of root filter positions
// partsDisplacement - displacement of part filters (in the block space)
// RESULT
//
*/
int tbbTasksThresholdFunctionalScore(const CvLSVMFilterObject **filters, const int n,
const CvLSVMFeaturePyramid *H, const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
int *kLevels, int **procLevels,
const int threadsNum,
float **score, CvPoint ***points,
int *kPoints,
CvPoint ****partsDisplacement);
#ifndef _LSVM_TBBVERSION_H
#define _LSVM_TBBVERSION_H
#include "_lsvm_matching.h"
/*
// Computation score function using TBB tasks
//
// API
// int tbbTasksThresholdFunctionalScore(const CvLSVMFilterObject **filters, const int n,
const CvLSVMFeaturePyramid *H, const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
int *kLevels, int **procLevels,
const int threadsNum,
float **score, CvPoint ***points,
int *kPoints,
CvPoint ****partsDisplacement);
// INPUT
// filters - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// scoreThreshold - score threshold
// kLevels - array that contains number of levels processed
by each thread
// procLevels - array that contains lists of levels processed
by each thread
// threadsNum - the number of created threads
// OUTPUT
// score - score function values that exceed threshold
// points - the set of root filter positions (in the block space)
// kPoints - number of root filter positions
// partsDisplacement - displacement of part filters (in the block space)
// RESULT
//
*/
int tbbTasksThresholdFunctionalScore(const CvLSVMFilterObject **filters, const int n,
const CvLSVMFeaturePyramid *H, const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
int *kLevels, int **procLevels,
const int threadsNum,
float **score, CvPoint ***points,
int *kPoints,
CvPoint ****partsDisplacement);
#endif

View File

@@ -23,7 +23,7 @@
// Block size. Used in feature pyramid building procedure
#define SIDE_LENGTH 8
#define VAL_OF_TRUNCATE 0.2f
#define VAL_OF_TRUNCATE 0.2f
//////////////////////////////////////////////////////////////
// main data structures //
@@ -31,10 +31,10 @@
// DataType: STRUCT featureMap
// FEATURE MAP DESCRIPTION
// Rectangular map (sizeX x sizeY),
// Rectangular map (sizeX x sizeY),
// every cell stores feature vector (dimension = numFeatures)
// map - matrix of feature vectors
// to set and get feature vectors (i,j)
// to set and get feature vectors (i,j)
// used formula map[(j * sizeX + i) * p + k], where
// k - component of feature vector in cell (i, j)
typedef struct{
@@ -55,7 +55,7 @@ typedef struct{
// DataType: STRUCT filterDisposition
// The structure stores preliminary results in optimization process
// with objective function D
// with objective function D
//
// x - array with X coordinates of optimization problems solutions
// y - array with Y coordinates of optimization problems solutions

View File

@@ -52,14 +52,14 @@
extern "C"
#endif
int loadModel(
const char *modelPath,
CvLSVMFilterObject ***filters,
int *kFilters,
int *kComponents,
int **kPartFilters,
float **b,
float *scoreThreshold);
float *scoreThreshold);
//};
#endif

View File

@@ -1,383 +1,383 @@
#include "precomp.hpp"
#include "_lsvm_distancetransform.h"
/*
// Computation the point of intersection functions
// (parabolas on the variable y)
// a(y - q1) + b(q1 - y)(q1 - y) + f[q1]
// a(y - q2) + b(q2 - y)(q2 - y) + f[q2]
//
//
// API
// int GetPointOfIntersection(const float *f,
const float a, const float b,
int q1, int q2, float *point);
// INPUT
// f - function on the regular grid
// a - coefficient of the function
// b - coefficient of the function
// q1 - parameter of the function
// q2 - parameter of the function
// OUTPUT
// point - point of intersection
// RESULT
// Error status
*/
int GetPointOfIntersection(const float *f,
const float a, const float b,
int q1, int q2, float *point)
{
if (q1 == q2)
{
return DISTANCE_TRANSFORM_EQUAL_POINTS;
} /* if (q1 == q2) */
(*point) = ( (f[q2] - a * q2 + b *q2 * q2) -
(f[q1] - a * q1 + b * q1 * q1) ) / (2 * b * (q2 - q1));
return DISTANCE_TRANSFORM_OK;
}
/*
// Decision of one dimensional problem generalized distance transform
// on the regular grid at all points
// min (a(y' - y) + b(y' - y)(y' - y) + f(y')) (on y')
//
// API
// int DistanceTransformOneDimensionalProblem(const float *f, const int n,
const float a, const float b,
float *distanceTransform,
int *points);
// INPUT
// f - function on the regular grid
// n - grid dimension
// a - coefficient of optimizable function
// b - coefficient of optimizable function
// OUTPUT
// distanceTransform - values of generalized distance transform
// points - arguments that corresponds to the optimal value of function
// RESULT
// Error status
*/
int DistanceTransformOneDimensionalProblem(const float *f, const int n,
const float a, const float b,
float *distanceTransform,
int *points)
{
int i, k;
int tmp;
int diff;
float pointIntersection;
int *v;
float *z;
k = 0;
// Allocation memory (must be free in this function)
v = (int *)malloc (sizeof(int) * n);
z = (float *)malloc (sizeof(float) * (n + 1));
v[0] = 0;
z[0] = (float)F_MIN; // left border of envelope
z[1] = (float)F_MAX; // right border of envelope
for (i = 1; i < n; i++)
{
tmp = GetPointOfIntersection(f, a, b, v[k], i, &pointIntersection);
if (tmp != DISTANCE_TRANSFORM_OK)
{
free(v);
free(z);
return DISTANCE_TRANSFORM_GET_INTERSECTION_ERROR;
} /* if (tmp != DISTANCE_TRANSFORM_OK) */
if (pointIntersection <= z[k])
{
// Envelope doesn't contain current parabola
do
{
k--;
tmp = GetPointOfIntersection(f, a, b, v[k], i, &pointIntersection);
if (tmp != DISTANCE_TRANSFORM_OK)
{
free(v);
free(z);
return DISTANCE_TRANSFORM_GET_INTERSECTION_ERROR;
} /* if (tmp != DISTANCE_TRANSFORM_OK) */
}while (pointIntersection <= z[k]);
// Addition parabola to the envelope
k++;
v[k] = i;
z[k] = pointIntersection;
z[k + 1] = (float)F_MAX;
}
else
{
// Addition parabola to the envelope
k++;
v[k] = i;
z[k] = pointIntersection;
z[k + 1] = (float)F_MAX;
} /* if (pointIntersection <= z[k]) */
}
// Computation values of generalized distance transform at all grid points
k = 0;
for (i = 0; i < n; i++)
{
while (z[k + 1] < i)
{
k++;
}
points[i] = v[k];
diff = i - v[k];
distanceTransform[i] = a * diff + b * diff * diff + f[v[k]];
}
// Release allocated memory
free(v);
free(z);
return DISTANCE_TRANSFORM_OK;
}
/*
// Computation next cycle element
//
// API
// int GetNextCycleElement(int k, int n, int q);
// INPUT
// k - index of the previous cycle element
// n - number of matrix rows
// q - parameter that equal
(number_of_rows * number_of_columns - 1)
// OUTPUT
// None
// RESULT
// Next cycle element
*/
int GetNextCycleElement(int k, int n, int q)
{
return ((k * n) % q);
}
/*
// Transpose cycle elements
//
// API
// void TransposeCycleElements(float *a, int *cycle, int cycle_len)
// INPUT
// a - initial matrix
// cycle - indeces array of cycle
// cycle_len - number of elements in the cycle
// OUTPUT
// a - matrix with transposed elements
// RESULT
// Error status
*/
void TransposeCycleElements(float *a, int *cycle, int cycle_len)
{
int i;
float buf;
for (i = cycle_len - 1; i > 0 ; i--)
{
buf = a[ cycle[i] ];
a[ cycle[i] ] = a[ cycle[i - 1] ];
a[ cycle[i - 1] ] = buf;
}
}
/*
// Transpose cycle elements
//
// API
// void TransposeCycleElements(int *a, int *cycle, int cycle_len)
// INPUT
// a - initial matrix
// cycle - indeces array of cycle
// cycle_len - number of elements in the cycle
// OUTPUT
// a - matrix with transposed elements
// RESULT
// Error status
*/
static void TransposeCycleElements_int(int *a, int *cycle, int cycle_len)
{
int i;
int buf;
for (i = cycle_len - 1; i > 0 ; i--)
{
buf = a[ cycle[i] ];
a[ cycle[i] ] = a[ cycle[i - 1] ];
a[ cycle[i - 1] ] = buf;
}
}
/*
// Getting transposed matrix
//
// API
// void Transpose(float *a, int n, int m);
// INPUT
// a - initial matrix
// n - number of rows
// m - number of columns
// OUTPUT
// a - transposed matrix
// RESULT
// None
*/
void Transpose(float *a, int n, int m)
{
int *cycle;
int i, k, q, cycle_len;
int max_cycle_len;
max_cycle_len = n * m;
// Allocation memory (must be free in this function)
cycle = (int *)malloc(sizeof(int) * max_cycle_len);
cycle_len = 0;
q = n * m - 1;
for (i = 1; i < q; i++)
{
k = GetNextCycleElement(i, n, q);
cycle[cycle_len] = i;
cycle_len++;
while (k > i)
{
cycle[cycle_len] = k;
cycle_len++;
k = GetNextCycleElement(k, n, q);
}
if (k == i)
{
TransposeCycleElements(a, cycle, cycle_len);
} /* if (k == i) */
cycle_len = 0;
}
// Release allocated memory
free(cycle);
}
/*
// Getting transposed matrix
//
// API
// void Transpose_int(int *a, int n, int m);
// INPUT
// a - initial matrix
// n - number of rows
// m - number of columns
// OUTPUT
// a - transposed matrix
// RESULT
// None
*/
static void Transpose_int(int *a, int n, int m)
{
int *cycle;
int i, k, q, cycle_len;
int max_cycle_len;
max_cycle_len = n * m;
// Allocation memory (must be free in this function)
cycle = (int *)malloc(sizeof(int) * max_cycle_len);
cycle_len = 0;
q = n * m - 1;
for (i = 1; i < q; i++)
{
k = GetNextCycleElement(i, n, q);
cycle[cycle_len] = i;
cycle_len++;
while (k > i)
{
cycle[cycle_len] = k;
cycle_len++;
k = GetNextCycleElement(k, n, q);
}
if (k == i)
{
TransposeCycleElements_int(a, cycle, cycle_len);
} /* if (k == i) */
cycle_len = 0;
}
// Release allocated memory
free(cycle);
}
/*
// Decision of two dimensional problem generalized distance transform
// on the regular grid at all points
// min{d2(y' - y) + d4(y' - y)(y' - y) +
min(d1(x' - x) + d3(x' - x)(x' - x) + f(x',y'))} (on x', y')
//
// API
// int DistanceTransformTwoDimensionalProblem(const float *f,
const int n, const int m,
const float coeff[4],
float *distanceTransform,
int *pointsX, int *pointsY);
// INPUT
// f - function on the regular grid
// n - number of rows
// m - number of columns
// coeff - coefficients of optimizable function
coeff[0] = d1, coeff[1] = d2,
coeff[2] = d3, coeff[3] = d4
// OUTPUT
// distanceTransform - values of generalized distance transform
// pointsX - arguments x' that correspond to the optimal value
// pointsY - arguments y' that correspond to the optimal value
// RESULT
// Error status
*/
int DistanceTransformTwoDimensionalProblem(const float *f,
const int n, const int m,
const float coeff[4],
float *distanceTransform,
int *pointsX, int *pointsY)
{
int i, j, tmp;
int resOneDimProblem;
int size = n * m;
std::vector<float> internalDistTrans(size);
std::vector<int> internalPointsX(size);
for (i = 0; i < n; i++)
{
resOneDimProblem = DistanceTransformOneDimensionalProblem(
f + i * m, m,
coeff[0], coeff[2],
&internalDistTrans[i * m],
&internalPointsX[i * m]);
if (resOneDimProblem != DISTANCE_TRANSFORM_OK)
return DISTANCE_TRANSFORM_ERROR;
}
Transpose(&internalDistTrans[0], n, m);
for (j = 0; j < m; j++)
{
resOneDimProblem = DistanceTransformOneDimensionalProblem(
&internalDistTrans[j * n], n,
coeff[1], coeff[3],
distanceTransform + j * n,
pointsY + j * n);
if (resOneDimProblem != DISTANCE_TRANSFORM_OK)
return DISTANCE_TRANSFORM_ERROR;
}
Transpose(distanceTransform, m, n);
Transpose_int(pointsY, m, n);
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
tmp = pointsY[i * m + j];
pointsX[i * m + j] = internalPointsX[tmp * m + j];
}
}
return DISTANCE_TRANSFORM_OK;
}
#include "precomp.hpp"
#include "_lsvm_distancetransform.h"
/*
// Computation the point of intersection functions
// (parabolas on the variable y)
// a(y - q1) + b(q1 - y)(q1 - y) + f[q1]
// a(y - q2) + b(q2 - y)(q2 - y) + f[q2]
//
//
// API
// int GetPointOfIntersection(const float *f,
const float a, const float b,
int q1, int q2, float *point);
// INPUT
// f - function on the regular grid
// a - coefficient of the function
// b - coefficient of the function
// q1 - parameter of the function
// q2 - parameter of the function
// OUTPUT
// point - point of intersection
// RESULT
// Error status
*/
int GetPointOfIntersection(const float *f,
const float a, const float b,
int q1, int q2, float *point)
{
if (q1 == q2)
{
return DISTANCE_TRANSFORM_EQUAL_POINTS;
} /* if (q1 == q2) */
(*point) = ( (f[q2] - a * q2 + b *q2 * q2) -
(f[q1] - a * q1 + b * q1 * q1) ) / (2 * b * (q2 - q1));
return DISTANCE_TRANSFORM_OK;
}
/*
// Decision of one dimensional problem generalized distance transform
// on the regular grid at all points
// min (a(y' - y) + b(y' - y)(y' - y) + f(y')) (on y')
//
// API
// int DistanceTransformOneDimensionalProblem(const float *f, const int n,
const float a, const float b,
float *distanceTransform,
int *points);
// INPUT
// f - function on the regular grid
// n - grid dimension
// a - coefficient of optimizable function
// b - coefficient of optimizable function
// OUTPUT
// distanceTransform - values of generalized distance transform
// points - arguments that corresponds to the optimal value of function
// RESULT
// Error status
*/
int DistanceTransformOneDimensionalProblem(const float *f, const int n,
const float a, const float b,
float *distanceTransform,
int *points)
{
int i, k;
int tmp;
int diff;
float pointIntersection;
int *v;
float *z;
k = 0;
// Allocation memory (must be free in this function)
v = (int *)malloc (sizeof(int) * n);
z = (float *)malloc (sizeof(float) * (n + 1));
v[0] = 0;
z[0] = (float)F_MIN; // left border of envelope
z[1] = (float)F_MAX; // right border of envelope
for (i = 1; i < n; i++)
{
tmp = GetPointOfIntersection(f, a, b, v[k], i, &pointIntersection);
if (tmp != DISTANCE_TRANSFORM_OK)
{
free(v);
free(z);
return DISTANCE_TRANSFORM_GET_INTERSECTION_ERROR;
} /* if (tmp != DISTANCE_TRANSFORM_OK) */
if (pointIntersection <= z[k])
{
// Envelope doesn't contain current parabola
do
{
k--;
tmp = GetPointOfIntersection(f, a, b, v[k], i, &pointIntersection);
if (tmp != DISTANCE_TRANSFORM_OK)
{
free(v);
free(z);
return DISTANCE_TRANSFORM_GET_INTERSECTION_ERROR;
} /* if (tmp != DISTANCE_TRANSFORM_OK) */
}while (pointIntersection <= z[k]);
// Addition parabola to the envelope
k++;
v[k] = i;
z[k] = pointIntersection;
z[k + 1] = (float)F_MAX;
}
else
{
// Addition parabola to the envelope
k++;
v[k] = i;
z[k] = pointIntersection;
z[k + 1] = (float)F_MAX;
} /* if (pointIntersection <= z[k]) */
}
// Computation values of generalized distance transform at all grid points
k = 0;
for (i = 0; i < n; i++)
{
while (z[k + 1] < i)
{
k++;
}
points[i] = v[k];
diff = i - v[k];
distanceTransform[i] = a * diff + b * diff * diff + f[v[k]];
}
// Release allocated memory
free(v);
free(z);
return DISTANCE_TRANSFORM_OK;
}
/*
// Computation next cycle element
//
// API
// int GetNextCycleElement(int k, int n, int q);
// INPUT
// k - index of the previous cycle element
// n - number of matrix rows
// q - parameter that equal
(number_of_rows * number_of_columns - 1)
// OUTPUT
// None
// RESULT
// Next cycle element
*/
int GetNextCycleElement(int k, int n, int q)
{
return ((k * n) % q);
}
/*
// Transpose cycle elements
//
// API
// void TransposeCycleElements(float *a, int *cycle, int cycle_len)
// INPUT
// a - initial matrix
// cycle - indeces array of cycle
// cycle_len - number of elements in the cycle
// OUTPUT
// a - matrix with transposed elements
// RESULT
// Error status
*/
void TransposeCycleElements(float *a, int *cycle, int cycle_len)
{
int i;
float buf;
for (i = cycle_len - 1; i > 0 ; i--)
{
buf = a[ cycle[i] ];
a[ cycle[i] ] = a[ cycle[i - 1] ];
a[ cycle[i - 1] ] = buf;
}
}
/*
// Transpose cycle elements
//
// API
// void TransposeCycleElements(int *a, int *cycle, int cycle_len)
// INPUT
// a - initial matrix
// cycle - indeces array of cycle
// cycle_len - number of elements in the cycle
// OUTPUT
// a - matrix with transposed elements
// RESULT
// Error status
*/
static void TransposeCycleElements_int(int *a, int *cycle, int cycle_len)
{
int i;
int buf;
for (i = cycle_len - 1; i > 0 ; i--)
{
buf = a[ cycle[i] ];
a[ cycle[i] ] = a[ cycle[i - 1] ];
a[ cycle[i - 1] ] = buf;
}
}
/*
// Getting transposed matrix
//
// API
// void Transpose(float *a, int n, int m);
// INPUT
// a - initial matrix
// n - number of rows
// m - number of columns
// OUTPUT
// a - transposed matrix
// RESULT
// None
*/
void Transpose(float *a, int n, int m)
{
int *cycle;
int i, k, q, cycle_len;
int max_cycle_len;
max_cycle_len = n * m;
// Allocation memory (must be free in this function)
cycle = (int *)malloc(sizeof(int) * max_cycle_len);
cycle_len = 0;
q = n * m - 1;
for (i = 1; i < q; i++)
{
k = GetNextCycleElement(i, n, q);
cycle[cycle_len] = i;
cycle_len++;
while (k > i)
{
cycle[cycle_len] = k;
cycle_len++;
k = GetNextCycleElement(k, n, q);
}
if (k == i)
{
TransposeCycleElements(a, cycle, cycle_len);
} /* if (k == i) */
cycle_len = 0;
}
// Release allocated memory
free(cycle);
}
/*
// Getting transposed matrix
//
// API
// void Transpose_int(int *a, int n, int m);
// INPUT
// a - initial matrix
// n - number of rows
// m - number of columns
// OUTPUT
// a - transposed matrix
// RESULT
// None
*/
static void Transpose_int(int *a, int n, int m)
{
int *cycle;
int i, k, q, cycle_len;
int max_cycle_len;
max_cycle_len = n * m;
// Allocation memory (must be free in this function)
cycle = (int *)malloc(sizeof(int) * max_cycle_len);
cycle_len = 0;
q = n * m - 1;
for (i = 1; i < q; i++)
{
k = GetNextCycleElement(i, n, q);
cycle[cycle_len] = i;
cycle_len++;
while (k > i)
{
cycle[cycle_len] = k;
cycle_len++;
k = GetNextCycleElement(k, n, q);
}
if (k == i)
{
TransposeCycleElements_int(a, cycle, cycle_len);
} /* if (k == i) */
cycle_len = 0;
}
// Release allocated memory
free(cycle);
}
/*
// Decision of two dimensional problem generalized distance transform
// on the regular grid at all points
// min{d2(y' - y) + d4(y' - y)(y' - y) +
min(d1(x' - x) + d3(x' - x)(x' - x) + f(x',y'))} (on x', y')
//
// API
// int DistanceTransformTwoDimensionalProblem(const float *f,
const int n, const int m,
const float coeff[4],
float *distanceTransform,
int *pointsX, int *pointsY);
// INPUT
// f - function on the regular grid
// n - number of rows
// m - number of columns
// coeff - coefficients of optimizable function
coeff[0] = d1, coeff[1] = d2,
coeff[2] = d3, coeff[3] = d4
// OUTPUT
// distanceTransform - values of generalized distance transform
// pointsX - arguments x' that correspond to the optimal value
// pointsY - arguments y' that correspond to the optimal value
// RESULT
// Error status
*/
int DistanceTransformTwoDimensionalProblem(const float *f,
const int n, const int m,
const float coeff[4],
float *distanceTransform,
int *pointsX, int *pointsY)
{
int i, j, tmp;
int resOneDimProblem;
int size = n * m;
std::vector<float> internalDistTrans(size);
std::vector<int> internalPointsX(size);
for (i = 0; i < n; i++)
{
resOneDimProblem = DistanceTransformOneDimensionalProblem(
f + i * m, m,
coeff[0], coeff[2],
&internalDistTrans[i * m],
&internalPointsX[i * m]);
if (resOneDimProblem != DISTANCE_TRANSFORM_OK)
return DISTANCE_TRANSFORM_ERROR;
}
Transpose(&internalDistTrans[0], n, m);
for (j = 0; j < m; j++)
{
resOneDimProblem = DistanceTransformOneDimensionalProblem(
&internalDistTrans[j * n], n,
coeff[1], coeff[3],
distanceTransform + j * n,
pointsY + j * n);
if (resOneDimProblem != DISTANCE_TRANSFORM_OK)
return DISTANCE_TRANSFORM_ERROR;
}
Transpose(distanceTransform, m, n);
Transpose_int(pointsY, m, n);
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
tmp = pointsY[i * m + j];
pointsX[i * m + j] = internalPointsX[tmp * m + j];
}
}
return DISTANCE_TRANSFORM_OK;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,247 +1,247 @@
#include "precomp.hpp"
#include "_lsvm_fft.h"
// static int getEntireRes(int number, int divisor, int *entire, int *res)
// {
// *entire = number / divisor;
// *res = number % divisor;
// return FFT_OK;
// }
static int getMultipliers(int n, int *n1, int *n2)
{
int multiplier, i;
if (n == 1)
{
*n1 = 1;
*n2 = 1;
return FFT_ERROR; // n = 1
}
multiplier = n / 2;
for (i = multiplier; i >= 2; i--)
{
if (n % i == 0)
{
*n1 = i;
*n2 = n / i;
return FFT_OK; // n = n1 * n2
}
}
*n1 = 1;
*n2 = n;
return FFT_ERROR; // n - prime number
}
/*
// 1-dimensional FFT
//
// API
// int fft(float *x_in, float *x_out, int n, int shift);
// INPUT
// x_in - input signal
// n - number of elements for searching Fourier image
// shift - shift between input elements
// OUTPUT
// x_out - output signal (contains 2n elements in order
Re(x_in[0]), Im(x_in[0]), Re(x_in[1]), Im(x_in[1]) and etc.)
// RESULT
// Error status
*/
int fft(float *x_in, float *x_out, int n, int shift)
{
int n1, n2, res, k1, k2, m1, m2, index, idx;
float alpha, beta, gamma, angle, cosAngle, sinAngle;
float tmpGamma, tmpAlpha, tmpBeta;
float tmpRe, tmpIm, phaseRe, phaseIm;
res = getMultipliers(n, &n1, &n2);
if (res == FFT_OK)
{
fft(x_in, x_out, n1, shift);
fft(x_in, x_out, n2, shift);
}
alpha = (float)(2.0 * PI / ((float)n));
beta = (float)(2.0 * PI / ((float)n1));
gamma = (float)(2.0 * PI / ((float)n2));
for (k1 = 0; k1 < n1; k1++)
{
tmpBeta = beta * k1;
for (k2 = 0; k2 < n2; k2++)
{
idx = shift * (n2 * k1 + k2);
x_out[idx] = 0.0;
x_out[idx + 1] = 0.0;
tmpGamma = gamma * k2;
tmpAlpha = alpha * k2;
for (m1 = 0; m1 < n1; m1++)
{
tmpRe = 0.0;
tmpIm = 0.0;
for (m2 = 0; m2 < n2; m2++)
{
angle = tmpGamma * m2;
index = shift * (n1 * m2 + m1);
cosAngle = cosf(angle);
sinAngle = sinf(angle);
tmpRe += x_in[index] * cosAngle + x_in[index + 1] * sinAngle;
tmpIm += x_in[index + 1] * cosAngle - x_in[index] * sinAngle;
}
angle = tmpAlpha * m1;
cosAngle = cosf(angle);
sinAngle = sinf(angle);
phaseRe = cosAngle * tmpRe + sinAngle * tmpIm;
phaseIm = cosAngle * tmpIm - sinAngle * tmpRe;
angle = tmpBeta * m1;
cosAngle = cosf(angle);
sinAngle = sinf(angle);
x_out[idx] += (cosAngle * phaseRe + sinAngle * phaseIm);
x_out[idx + 1] += (cosAngle * phaseIm - sinAngle * phaseRe);
}
}
}
return FFT_OK;
}
/*
// Inverse 1-dimensional FFT
//
// API
// int fftInverse(float *x_in, float *x_out, int n, int shift);
// INPUT
// x_in - Fourier image of 1d input signal(contains 2n elements
in order Re(x_in[0]), Im(x_in[0]),
Re(x_in[1]), Im(x_in[1]) and etc.)
// n - number of elements for searching counter FFT image
// shift - shift between input elements
// OUTPUT
// x_in - input signal (contains n elements)
// RESULT
// Error status
*/
int fftInverse(float *x_in, float *x_out, int n, int shift)
{
int n1, n2, res, k1, k2, m1, m2, index, idx;
float alpha, beta, gamma, angle, cosAngle, sinAngle;
float tmpRe, tmpIm, phaseRe, phaseIm;
res = getMultipliers(n, &n1, &n2);
if (res == FFT_OK)
{
fftInverse(x_in, x_out, n1, shift);
fftInverse(x_in, x_out, n2, shift);
}
alpha = (float)(2.0f * PI / ((float)n));
beta = (float)(2.0f * PI / ((float)n1));
gamma = (float)(2.0f * PI / ((float)n2));
for (m1 = 0; m1 < n1; m1++)
{
for (m2 = 0; m2 < n2; m2++)
{
idx = (n1 * m2 + m1) * shift;
x_out[idx] = 0.0;
x_out[idx + 1] = 0.0;
for (k2 = 0; k2 < n2; k2++)
{
tmpRe = 0.0;
tmpIm = 0.0;
for (k1 = 0; k1 < n1; k1++)
{
angle = beta * k1 * m1;
index = shift *(n2 * k1 + k2);
sinAngle = sinf(angle);
cosAngle = cosf(angle);
tmpRe += x_in[index] * cosAngle - x_in[index + 1] * sinAngle;
tmpIm += x_in[index] * sinAngle + x_in[index + 1] * cosAngle;
}
angle = alpha * m1 * k2;
sinAngle = sinf(angle);
cosAngle = cosf(angle);
phaseRe = cosAngle * tmpRe - sinAngle * tmpIm;
phaseIm = cosAngle * tmpIm + sinAngle * tmpRe;
angle = gamma * k2 * m2;
sinAngle = sinf(angle);
cosAngle = cosf(angle);
x_out[idx] += cosAngle * phaseRe - sinAngle * phaseIm;
x_out[idx + 1] += cosAngle * phaseIm + sinAngle * phaseRe;
}
x_out[idx] /= n;
x_out[idx + 1] /= n;
}
}
return FFT_OK;
}
/*
// 2-dimensional FFT
//
// API
// int fft2d(float *x_in, float *x_out, int numRows, int numColls);
// INPUT
// x_in - input signal (matrix, launched by rows)
// numRows - number of rows
// numColls - number of collumns
// OUTPUT
// x_out - output signal (contains (2 * numRows * numColls) elements
in order Re(x_in[0][0]), Im(x_in[0][0]),
Re(x_in[0][1]), Im(x_in[0][1]) and etc.)
// RESULT
// Error status
*/
int fft2d(float *x_in, float *x_out, int numRows, int numColls)
{
int i, size;
float *x_outTmp;
size = numRows * numColls;
x_outTmp = (float *)malloc(sizeof(float) * (2 * size));
for (i = 0; i < numRows; i++)
{
fft(x_in + i * 2 * numColls,
x_outTmp + i * 2 * numColls,
numColls, 2);
}
for (i = 0; i < numColls; i++)
{
fft(x_outTmp + 2 * i,
x_out + 2 * i,
numRows, 2 * numColls);
}
free(x_outTmp);
return FFT_OK;
}
/*
// Inverse 2-dimensional FFT
//
// API
// int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls);
// INPUT
// x_in - Fourier image of matrix (contains (2 * numRows * numColls)
elements in order Re(x_in[0][0]), Im(x_in[0][0]),
Re(x_in[0][1]), Im(x_in[0][1]) and etc.)
// numRows - number of rows
// numColls - number of collumns
// OUTPUT
// x_out - initial signal (matrix, launched by rows)
// RESULT
// Error status
*/
int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls)
{
int i, size;
float *x_outTmp;
size = numRows * numColls;
x_outTmp = (float *)malloc(sizeof(float) * (2 * size));
for (i = 0; i < numRows; i++)
{
fftInverse(x_in + i * 2 * numColls,
x_outTmp + i * 2 * numColls,
numColls, 2);
}
for (i = 0; i < numColls; i++)
{
fftInverse(x_outTmp + 2 * i,
x_out + 2 * i,
numRows, 2 * numColls);
}
free(x_outTmp);
return FFT_OK;
}
#include "precomp.hpp"
#include "_lsvm_fft.h"
// static int getEntireRes(int number, int divisor, int *entire, int *res)
// {
// *entire = number / divisor;
// *res = number % divisor;
// return FFT_OK;
// }
static int getMultipliers(int n, int *n1, int *n2)
{
int multiplier, i;
if (n == 1)
{
*n1 = 1;
*n2 = 1;
return FFT_ERROR; // n = 1
}
multiplier = n / 2;
for (i = multiplier; i >= 2; i--)
{
if (n % i == 0)
{
*n1 = i;
*n2 = n / i;
return FFT_OK; // n = n1 * n2
}
}
*n1 = 1;
*n2 = n;
return FFT_ERROR; // n - prime number
}
/*
// 1-dimensional FFT
//
// API
// int fft(float *x_in, float *x_out, int n, int shift);
// INPUT
// x_in - input signal
// n - number of elements for searching Fourier image
// shift - shift between input elements
// OUTPUT
// x_out - output signal (contains 2n elements in order
Re(x_in[0]), Im(x_in[0]), Re(x_in[1]), Im(x_in[1]) and etc.)
// RESULT
// Error status
*/
int fft(float *x_in, float *x_out, int n, int shift)
{
int n1, n2, res, k1, k2, m1, m2, index, idx;
float alpha, beta, gamma, angle, cosAngle, sinAngle;
float tmpGamma, tmpAlpha, tmpBeta;
float tmpRe, tmpIm, phaseRe, phaseIm;
res = getMultipliers(n, &n1, &n2);
if (res == FFT_OK)
{
fft(x_in, x_out, n1, shift);
fft(x_in, x_out, n2, shift);
}
alpha = (float)(2.0 * PI / ((float)n));
beta = (float)(2.0 * PI / ((float)n1));
gamma = (float)(2.0 * PI / ((float)n2));
for (k1 = 0; k1 < n1; k1++)
{
tmpBeta = beta * k1;
for (k2 = 0; k2 < n2; k2++)
{
idx = shift * (n2 * k1 + k2);
x_out[idx] = 0.0;
x_out[idx + 1] = 0.0;
tmpGamma = gamma * k2;
tmpAlpha = alpha * k2;
for (m1 = 0; m1 < n1; m1++)
{
tmpRe = 0.0;
tmpIm = 0.0;
for (m2 = 0; m2 < n2; m2++)
{
angle = tmpGamma * m2;
index = shift * (n1 * m2 + m1);
cosAngle = cosf(angle);
sinAngle = sinf(angle);
tmpRe += x_in[index] * cosAngle + x_in[index + 1] * sinAngle;
tmpIm += x_in[index + 1] * cosAngle - x_in[index] * sinAngle;
}
angle = tmpAlpha * m1;
cosAngle = cosf(angle);
sinAngle = sinf(angle);
phaseRe = cosAngle * tmpRe + sinAngle * tmpIm;
phaseIm = cosAngle * tmpIm - sinAngle * tmpRe;
angle = tmpBeta * m1;
cosAngle = cosf(angle);
sinAngle = sinf(angle);
x_out[idx] += (cosAngle * phaseRe + sinAngle * phaseIm);
x_out[idx + 1] += (cosAngle * phaseIm - sinAngle * phaseRe);
}
}
}
return FFT_OK;
}
/*
// Inverse 1-dimensional FFT
//
// API
// int fftInverse(float *x_in, float *x_out, int n, int shift);
// INPUT
// x_in - Fourier image of 1d input signal(contains 2n elements
in order Re(x_in[0]), Im(x_in[0]),
Re(x_in[1]), Im(x_in[1]) and etc.)
// n - number of elements for searching counter FFT image
// shift - shift between input elements
// OUTPUT
// x_in - input signal (contains n elements)
// RESULT
// Error status
*/
int fftInverse(float *x_in, float *x_out, int n, int shift)
{
int n1, n2, res, k1, k2, m1, m2, index, idx;
float alpha, beta, gamma, angle, cosAngle, sinAngle;
float tmpRe, tmpIm, phaseRe, phaseIm;
res = getMultipliers(n, &n1, &n2);
if (res == FFT_OK)
{
fftInverse(x_in, x_out, n1, shift);
fftInverse(x_in, x_out, n2, shift);
}
alpha = (float)(2.0f * PI / ((float)n));
beta = (float)(2.0f * PI / ((float)n1));
gamma = (float)(2.0f * PI / ((float)n2));
for (m1 = 0; m1 < n1; m1++)
{
for (m2 = 0; m2 < n2; m2++)
{
idx = (n1 * m2 + m1) * shift;
x_out[idx] = 0.0;
x_out[idx + 1] = 0.0;
for (k2 = 0; k2 < n2; k2++)
{
tmpRe = 0.0;
tmpIm = 0.0;
for (k1 = 0; k1 < n1; k1++)
{
angle = beta * k1 * m1;
index = shift *(n2 * k1 + k2);
sinAngle = sinf(angle);
cosAngle = cosf(angle);
tmpRe += x_in[index] * cosAngle - x_in[index + 1] * sinAngle;
tmpIm += x_in[index] * sinAngle + x_in[index + 1] * cosAngle;
}
angle = alpha * m1 * k2;
sinAngle = sinf(angle);
cosAngle = cosf(angle);
phaseRe = cosAngle * tmpRe - sinAngle * tmpIm;
phaseIm = cosAngle * tmpIm + sinAngle * tmpRe;
angle = gamma * k2 * m2;
sinAngle = sinf(angle);
cosAngle = cosf(angle);
x_out[idx] += cosAngle * phaseRe - sinAngle * phaseIm;
x_out[idx + 1] += cosAngle * phaseIm + sinAngle * phaseRe;
}
x_out[idx] /= n;
x_out[idx + 1] /= n;
}
}
return FFT_OK;
}
/*
// 2-dimensional FFT
//
// API
// int fft2d(float *x_in, float *x_out, int numRows, int numColls);
// INPUT
// x_in - input signal (matrix, launched by rows)
// numRows - number of rows
// numColls - number of collumns
// OUTPUT
// x_out - output signal (contains (2 * numRows * numColls) elements
in order Re(x_in[0][0]), Im(x_in[0][0]),
Re(x_in[0][1]), Im(x_in[0][1]) and etc.)
// RESULT
// Error status
*/
int fft2d(float *x_in, float *x_out, int numRows, int numColls)
{
int i, size;
float *x_outTmp;
size = numRows * numColls;
x_outTmp = (float *)malloc(sizeof(float) * (2 * size));
for (i = 0; i < numRows; i++)
{
fft(x_in + i * 2 * numColls,
x_outTmp + i * 2 * numColls,
numColls, 2);
}
for (i = 0; i < numColls; i++)
{
fft(x_outTmp + 2 * i,
x_out + 2 * i,
numRows, 2 * numColls);
}
free(x_outTmp);
return FFT_OK;
}
/*
// Inverse 2-dimensional FFT
//
// API
// int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls);
// INPUT
// x_in - Fourier image of matrix (contains (2 * numRows * numColls)
elements in order Re(x_in[0][0]), Im(x_in[0][0]),
Re(x_in[0][1]), Im(x_in[0][1]) and etc.)
// numRows - number of rows
// numColls - number of collumns
// OUTPUT
// x_out - initial signal (matrix, launched by rows)
// RESULT
// Error status
*/
int fftInverse2d(float *x_in, float *x_out, int numRows, int numColls)
{
int i, size;
float *x_outTmp;
size = numRows * numColls;
x_outTmp = (float *)malloc(sizeof(float) * (2 * size));
for (i = 0; i < numRows; i++)
{
fftInverse(x_in + i * 2 * numColls,
x_outTmp + i * 2 * numColls,
numColls, 2);
}
for (i = 0; i < numColls; i++)
{
fftInverse(x_outTmp + 2 * i,
x_out + 2 * i,
numRows, 2 * numColls);
}
free(x_outTmp);
return FFT_OK;
}

View File

@@ -110,7 +110,7 @@ bool HOGDescriptor::read(FileNode& obj)
obj["L2HysThreshold"] >> L2HysThreshold;
obj["gammaCorrection"] >> gammaCorrection;
obj["nlevels"] >> nlevels;
FileNode vecNode = obj["SVMDetector"];
if( vecNode.isSeq() )
{
@@ -119,7 +119,7 @@ bool HOGDescriptor::read(FileNode& obj)
}
return true;
}
void HOGDescriptor::write(FileStorage& fs, const String& objName) const
{
if( !objName.empty() )
@@ -819,7 +819,7 @@ void HOGDescriptor::compute(const Mat& img, vector<float>& descriptors,
for( size_t i = 0; i < nwindows; i++ )
{
float* descriptor = &descriptors[i*dsize];
Point pt0;
if( !locations.empty() )
{
@@ -854,7 +854,7 @@ void HOGDescriptor::compute(const Mat& img, vector<float>& descriptors,
void HOGDescriptor::detect(const Mat& img,
vector<Point>& hits, vector<double>& weights, double hitThreshold,
vector<Point>& hits, vector<double>& weights, double hitThreshold,
Size winStride, Size padding, const vector<Point>& locations) const
{
hits.clear();
@@ -932,7 +932,7 @@ void HOGDescriptor::detect(const Mat& img,
}
}
void HOGDescriptor::detect(const Mat& img, vector<Point>& hits, double hitThreshold,
void HOGDescriptor::detect(const Mat& img, vector<Point>& hits, double hitThreshold,
Size winStride, Size padding, const vector<Point>& locations) const
{
vector<double> weightsV;
@@ -1021,7 +1021,7 @@ public:
void HOGDescriptor::detectMultiScale(
const Mat& img, vector<Rect>& foundLocations, vector<double>& foundWeights,
double hitThreshold, Size winStride, Size padding,
double scale0, double finalThreshold, bool useMeanshiftGrouping) const
double scale0, double finalThreshold, bool useMeanshiftGrouping) const
{
double scale = 1.;
int levels = 0;
@@ -1064,12 +1064,12 @@ void HOGDescriptor::detectMultiScale(
}
}
void HOGDescriptor::detectMultiScale(const Mat& img, vector<Rect>& foundLocations,
void HOGDescriptor::detectMultiScale(const Mat& img, vector<Rect>& foundLocations,
double hitThreshold, Size winStride, Size padding,
double scale0, double finalThreshold, bool useMeanshiftGrouping) const
double scale0, double finalThreshold, bool useMeanshiftGrouping) const
{
vector<double> foundWeights;
detectMultiScale(img, foundLocations, foundWeights, hitThreshold, winStride,
detectMultiScale(img, foundLocations, foundWeights, hitThreshold, winStride,
padding, scale0, finalThreshold, useMeanshiftGrouping);
}
@@ -1888,8 +1888,8 @@ vector<float> HOGDescriptor::getDefaultPeopleDetector()
-0.02411991f, -0.04229729f, 0.10666174f, -6.66579151f };
return vector<float>(detector, detector + sizeof(detector)/sizeof(detector[0]));
}
//This function renurn 1981 SVM coeffs obtained from daimler's base.
//To use these coeffs the detection window size should be (48,96)
//This function renurn 1981 SVM coeffs obtained from daimler's base.
//To use these coeffs the detection window size should be (48,96)
vector<float> HOGDescriptor::getDaimlerPeopleDetector()
{
static const float detector[] = {

File diff suppressed because it is too large Load Diff

View File

@@ -1,268 +1,268 @@
#include "precomp.hpp"
#include "_lsvmparser.h"
#include "_lsvm_matching.h"
/*
// load trained detector from a file
//
// API
// CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename);
// INPUT
// filename - path to the file containing the parameters of
// - trained Latent SVM detector
// OUTPUT
// trained Latent SVM detector in internal representation
*/
CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename)
{
CvLatentSvmDetector* detector = 0;
CvLSVMFilterObject** filters = 0;
int kFilters = 0;
int kComponents = 0;
int* kPartFilters = 0;
float* b = 0;
float scoreThreshold = 0.f;
int err_code = 0;
err_code = loadModel(filename, &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold);
if (err_code != LATENT_SVM_OK) return 0;
detector = (CvLatentSvmDetector*)malloc(sizeof(CvLatentSvmDetector));
detector->filters = filters;
detector->b = b;
detector->num_components = kComponents;
detector->num_filters = kFilters;
detector->num_part_filters = kPartFilters;
detector->score_threshold = scoreThreshold;
return detector;
}
/*
// release memory allocated for CvLatentSvmDetector structure
//
// API
// void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector);
// INPUT
// detector - CvLatentSvmDetector structure to be released
// OUTPUT
*/
void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector)
{
free((*detector)->b);
free((*detector)->num_part_filters);
for (int i = 0; i < (*detector)->num_filters; i++)
{
free((*detector)->filters[i]->H);
free((*detector)->filters[i]);
}
free((*detector)->filters);
free((*detector));
*detector = 0;
}
/*
// find rectangular regions in the given image that are likely
// to contain objects and corresponding confidence levels
//
// API
// CvSeq* cvLatentSvmDetectObjects(const IplImage* image,
// CvLatentSvmDetector* detector,
// CvMemStorage* storage,
// float overlap_threshold = 0.5f,
int numThreads = -1);
// INPUT
// image - image to detect objects in
// detector - Latent SVM detector in internal representation
// storage - memory storage to store the resultant sequence
// of the object candidate rectangles
// overlap_threshold - threshold for the non-maximum suppression algorithm [here will be the reference to original paper]
// OUTPUT
// sequence of detected objects (bounding boxes and confidence levels stored in CvObjectDetection structures)
*/
CvSeq* cvLatentSvmDetectObjects(IplImage* image,
CvLatentSvmDetector* detector,
CvMemStorage* storage,
float overlap_threshold, int numThreads)
{
CvLSVMFeaturePyramid *H = 0;
CvPoint *points = 0, *oppPoints = 0;
int kPoints = 0;
float *score = 0;
unsigned int maxXBorder = 0, maxYBorder = 0;
int numBoxesOut = 0;
CvPoint *pointsOut = 0;
CvPoint *oppPointsOut = 0;
float *scoreOut = 0;
CvSeq* result_seq = 0;
int error = 0;
if(image->nChannels == 3)
cvCvtColor(image, image, CV_BGR2RGB);
// Getting maximum filter dimensions
getMaxFilterDims((const CvLSVMFilterObject**)(detector->filters), detector->num_components,
detector->num_part_filters, &maxXBorder, &maxYBorder);
// Create feature pyramid with nullable border
H = createFeaturePyramidWithBorder(image, maxXBorder, maxYBorder);
// Search object
error = searchObjectThresholdSomeComponents(H, (const CvLSVMFilterObject**)(detector->filters),
detector->num_components, detector->num_part_filters, detector->b, detector->score_threshold,
&points, &oppPoints, &score, &kPoints, numThreads);
if (error != LATENT_SVM_OK)
{
return NULL;
}
// Clipping boxes
clippingBoxes(image->width, image->height, points, kPoints);
clippingBoxes(image->width, image->height, oppPoints, kPoints);
// NMS procedure
nonMaximumSuppression(kPoints, points, oppPoints, score, overlap_threshold,
&numBoxesOut, &pointsOut, &oppPointsOut, &scoreOut);
result_seq = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvObjectDetection), storage );
for (int i = 0; i < numBoxesOut; i++)
{
CvObjectDetection detection = {{0, 0, 0, 0}, 0};
detection.score = scoreOut[i];
CvRect bounding_box = {0, 0, 0, 0};
bounding_box.x = pointsOut[i].x;
bounding_box.y = pointsOut[i].y;
bounding_box.width = oppPointsOut[i].x - pointsOut[i].x;
bounding_box.height = oppPointsOut[i].y - pointsOut[i].y;
detection.rect = bounding_box;
cvSeqPush(result_seq, &detection);
}
if(image->nChannels == 3)
cvCvtColor(image, image, CV_RGB2BGR);
freeFeaturePyramidObject(&H);
free(points);
free(oppPoints);
free(score);
return result_seq;
}
namespace cv
{
LatentSvmDetector::ObjectDetection::ObjectDetection() : score(0.f), classID(-1)
{}
LatentSvmDetector::ObjectDetection::ObjectDetection( const Rect& _rect, float _score, int _classID ) :
rect(_rect), score(_score), classID(_classID)
{}
LatentSvmDetector::LatentSvmDetector()
{}
LatentSvmDetector::LatentSvmDetector( const vector<string>& filenames, const vector<string>& _classNames )
{
load( filenames, _classNames );
}
LatentSvmDetector::~LatentSvmDetector()
{
clear();
}
void LatentSvmDetector::clear()
{
for( size_t i = 0; i < detectors.size(); i++ )
cvReleaseLatentSvmDetector( &detectors[i] );
detectors.clear();
classNames.clear();
}
bool LatentSvmDetector::empty() const
{
return detectors.empty();
}
const vector<string>& LatentSvmDetector::getClassNames() const
{
return classNames;
}
size_t LatentSvmDetector::getClassCount() const
{
return classNames.size();
}
static string extractModelName( const string& filename )
{
size_t startPos = filename.rfind('/');
if( startPos == string::npos )
startPos = filename.rfind('\\');
if( startPos == string::npos )
startPos = 0;
else
startPos++;
const int extentionSize = 4; //.xml
int substrLength = (int)(filename.size() - startPos - extentionSize);
return filename.substr(startPos, substrLength);
}
bool LatentSvmDetector::load( const vector<string>& filenames, const vector<string>& _classNames )
{
clear();
CV_Assert( _classNames.empty() || _classNames.size() == filenames.size() );
for( size_t i = 0; i < filenames.size(); i++ )
{
const string filename = filenames[i];
if( filename.length() < 5 || filename.substr(filename.length()-4, 4) != ".xml" )
continue;
CvLatentSvmDetector* detector = cvLoadLatentSvmDetector( filename.c_str() );
if( detector )
{
detectors.push_back( detector );
if( _classNames.empty() )
{
classNames.push_back( extractModelName(filenames[i]) );
}
else
classNames.push_back( _classNames[i] );
}
}
return !empty();
}
void LatentSvmDetector::detect( const Mat& image,
vector<ObjectDetection>& objectDetections,
float overlapThreshold,
int numThreads )
{
objectDetections.clear();
if( numThreads <= 0 )
numThreads = 1;
for( size_t classID = 0; classID < detectors.size(); classID++ )
{
IplImage image_ipl = image;
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* detections = cvLatentSvmDetectObjects( &image_ipl, detectors[classID], storage, overlapThreshold, numThreads );
// convert results
objectDetections.reserve( objectDetections.size() + detections->total );
for( int detectionIdx = 0; detectionIdx < detections->total; detectionIdx++ )
{
CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, detectionIdx );
objectDetections.push_back( ObjectDetection(Rect(detection.rect), detection.score, (int)classID) );
}
cvReleaseMemStorage( &storage );
}
}
} // namespace cv
#include "precomp.hpp"
#include "_lsvmparser.h"
#include "_lsvm_matching.h"
/*
// load trained detector from a file
//
// API
// CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename);
// INPUT
// filename - path to the file containing the parameters of
// - trained Latent SVM detector
// OUTPUT
// trained Latent SVM detector in internal representation
*/
CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename)
{
CvLatentSvmDetector* detector = 0;
CvLSVMFilterObject** filters = 0;
int kFilters = 0;
int kComponents = 0;
int* kPartFilters = 0;
float* b = 0;
float scoreThreshold = 0.f;
int err_code = 0;
err_code = loadModel(filename, &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold);
if (err_code != LATENT_SVM_OK) return 0;
detector = (CvLatentSvmDetector*)malloc(sizeof(CvLatentSvmDetector));
detector->filters = filters;
detector->b = b;
detector->num_components = kComponents;
detector->num_filters = kFilters;
detector->num_part_filters = kPartFilters;
detector->score_threshold = scoreThreshold;
return detector;
}
/*
// release memory allocated for CvLatentSvmDetector structure
//
// API
// void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector);
// INPUT
// detector - CvLatentSvmDetector structure to be released
// OUTPUT
*/
void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector)
{
free((*detector)->b);
free((*detector)->num_part_filters);
for (int i = 0; i < (*detector)->num_filters; i++)
{
free((*detector)->filters[i]->H);
free((*detector)->filters[i]);
}
free((*detector)->filters);
free((*detector));
*detector = 0;
}
/*
// find rectangular regions in the given image that are likely
// to contain objects and corresponding confidence levels
//
// API
// CvSeq* cvLatentSvmDetectObjects(const IplImage* image,
// CvLatentSvmDetector* detector,
// CvMemStorage* storage,
// float overlap_threshold = 0.5f,
int numThreads = -1);
// INPUT
// image - image to detect objects in
// detector - Latent SVM detector in internal representation
// storage - memory storage to store the resultant sequence
// of the object candidate rectangles
// overlap_threshold - threshold for the non-maximum suppression algorithm [here will be the reference to original paper]
// OUTPUT
// sequence of detected objects (bounding boxes and confidence levels stored in CvObjectDetection structures)
*/
CvSeq* cvLatentSvmDetectObjects(IplImage* image,
CvLatentSvmDetector* detector,
CvMemStorage* storage,
float overlap_threshold, int numThreads)
{
CvLSVMFeaturePyramid *H = 0;
CvPoint *points = 0, *oppPoints = 0;
int kPoints = 0;
float *score = 0;
unsigned int maxXBorder = 0, maxYBorder = 0;
int numBoxesOut = 0;
CvPoint *pointsOut = 0;
CvPoint *oppPointsOut = 0;
float *scoreOut = 0;
CvSeq* result_seq = 0;
int error = 0;
if(image->nChannels == 3)
cvCvtColor(image, image, CV_BGR2RGB);
// Getting maximum filter dimensions
getMaxFilterDims((const CvLSVMFilterObject**)(detector->filters), detector->num_components,
detector->num_part_filters, &maxXBorder, &maxYBorder);
// Create feature pyramid with nullable border
H = createFeaturePyramidWithBorder(image, maxXBorder, maxYBorder);
// Search object
error = searchObjectThresholdSomeComponents(H, (const CvLSVMFilterObject**)(detector->filters),
detector->num_components, detector->num_part_filters, detector->b, detector->score_threshold,
&points, &oppPoints, &score, &kPoints, numThreads);
if (error != LATENT_SVM_OK)
{
return NULL;
}
// Clipping boxes
clippingBoxes(image->width, image->height, points, kPoints);
clippingBoxes(image->width, image->height, oppPoints, kPoints);
// NMS procedure
nonMaximumSuppression(kPoints, points, oppPoints, score, overlap_threshold,
&numBoxesOut, &pointsOut, &oppPointsOut, &scoreOut);
result_seq = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvObjectDetection), storage );
for (int i = 0; i < numBoxesOut; i++)
{
CvObjectDetection detection = {{0, 0, 0, 0}, 0};
detection.score = scoreOut[i];
CvRect bounding_box = {0, 0, 0, 0};
bounding_box.x = pointsOut[i].x;
bounding_box.y = pointsOut[i].y;
bounding_box.width = oppPointsOut[i].x - pointsOut[i].x;
bounding_box.height = oppPointsOut[i].y - pointsOut[i].y;
detection.rect = bounding_box;
cvSeqPush(result_seq, &detection);
}
if(image->nChannels == 3)
cvCvtColor(image, image, CV_RGB2BGR);
freeFeaturePyramidObject(&H);
free(points);
free(oppPoints);
free(score);
return result_seq;
}
namespace cv
{
LatentSvmDetector::ObjectDetection::ObjectDetection() : score(0.f), classID(-1)
{}
LatentSvmDetector::ObjectDetection::ObjectDetection( const Rect& _rect, float _score, int _classID ) :
rect(_rect), score(_score), classID(_classID)
{}
LatentSvmDetector::LatentSvmDetector()
{}
LatentSvmDetector::LatentSvmDetector( const vector<string>& filenames, const vector<string>& _classNames )
{
load( filenames, _classNames );
}
LatentSvmDetector::~LatentSvmDetector()
{
clear();
}
void LatentSvmDetector::clear()
{
for( size_t i = 0; i < detectors.size(); i++ )
cvReleaseLatentSvmDetector( &detectors[i] );
detectors.clear();
classNames.clear();
}
bool LatentSvmDetector::empty() const
{
return detectors.empty();
}
const vector<string>& LatentSvmDetector::getClassNames() const
{
return classNames;
}
size_t LatentSvmDetector::getClassCount() const
{
return classNames.size();
}
static string extractModelName( const string& filename )
{
size_t startPos = filename.rfind('/');
if( startPos == string::npos )
startPos = filename.rfind('\\');
if( startPos == string::npos )
startPos = 0;
else
startPos++;
const int extentionSize = 4; //.xml
int substrLength = (int)(filename.size() - startPos - extentionSize);
return filename.substr(startPos, substrLength);
}
bool LatentSvmDetector::load( const vector<string>& filenames, const vector<string>& _classNames )
{
clear();
CV_Assert( _classNames.empty() || _classNames.size() == filenames.size() );
for( size_t i = 0; i < filenames.size(); i++ )
{
const string filename = filenames[i];
if( filename.length() < 5 || filename.substr(filename.length()-4, 4) != ".xml" )
continue;
CvLatentSvmDetector* detector = cvLoadLatentSvmDetector( filename.c_str() );
if( detector )
{
detectors.push_back( detector );
if( _classNames.empty() )
{
classNames.push_back( extractModelName(filenames[i]) );
}
else
classNames.push_back( _classNames[i] );
}
}
return !empty();
}
void LatentSvmDetector::detect( const Mat& image,
vector<ObjectDetection>& objectDetections,
float overlapThreshold,
int numThreads )
{
objectDetections.clear();
if( numThreads <= 0 )
numThreads = 1;
for( size_t classID = 0; classID < detectors.size(); classID++ )
{
IplImage image_ipl = image;
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* detections = cvLatentSvmDetectObjects( &image_ipl, detectors[classID], storage, overlapThreshold, numThreads );
// convert results
objectDetections.reserve( objectDetections.size() + detections->total );
for( int detectionIdx = 0; detectionIdx < detections->total; detectionIdx++ )
{
CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, detectionIdx );
objectDetections.push_back( ObjectDetection(Rect(detection.rect), detection.score, (int)classID) );
}
cvReleaseMemStorage( &storage );
}
}
} // namespace cv

File diff suppressed because it is too large Load Diff

View File

@@ -1,123 +1,123 @@
#include "precomp.hpp"
#ifdef HAVE_TBB
#include "_lsvm_tbbversion.h"
/*
// Task class
*/
class ScoreComputation : public tbb::task
{
private:
const CvLSVMFilterObject **filters;
const int n;
const CvLSVMFeaturePyramid *H;
const float b;
const int maxXBorder;
const int maxYBorder;
const float scoreThreshold;
const int kLevels;
const int *procLevels;
public:
float **score;
CvPoint ***points;
CvPoint ****partsDisplacement;
int *kPoints;
public:
ScoreComputation(const CvLSVMFilterObject **_filters, int _n,
const CvLSVMFeaturePyramid *_H,
float _b, int _maxXBorder, int _maxYBorder,
float _scoreThreshold, int _kLevels, const int *_procLevels,
float **_score, CvPoint ***_points, int *_kPoints,
CvPoint ****_partsDisplacement) :
n(_n), b(_b), maxXBorder(_maxXBorder),
maxYBorder(_maxYBorder), scoreThreshold(_scoreThreshold),
kLevels(_kLevels), score(_score), points(_points),
partsDisplacement(_partsDisplacement), kPoints(_kPoints)
{
filters = _filters;
H = _H;
procLevels = _procLevels;
};
task* execute()
{
int i, level, partsLevel, res;
for (i = 0; i < kLevels; i++)
{
level = procLevels[i];
partsLevel = level - LAMBDA;//H->lambda;
res = thresholdFunctionalScoreFixedLevel(
filters, n, H, level, b,
maxXBorder, maxYBorder, scoreThreshold, &(score[partsLevel]),
points[partsLevel], &(kPoints[partsLevel]),
partsDisplacement[partsLevel]);
if (res != LATENT_SVM_OK)
{
continue;
}
}
return NULL;
}
};
/*
// Computation score function using TBB tasks
//
// API
// int tbbTasksThresholdFunctionalScore(const CvLSVMFilterObject **filters, const int n,
const CvLSVMFeatureMap *H, const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
int *kLevels, int **procLevels,
const int threadsNum,
float **score, CvPoint ***points,
int *kPoints,
CvPoint ****partsDisplacement);
// INPUT
// filters - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// scoreThreshold - score threshold
// kLevels - array that contains number of levels processed
by each thread
// procLevels - array that contains lists of levels processed
by each thread
// threadsNum - the number of created threads
// OUTPUT
// score - score function values that exceed threshold
// points - the set of root filter positions (in the block space)
// kPoints - number of root filter positions
// partsDisplacement - displacement of part filters (in the block space)
// RESULT
//
*/
int tbbTasksThresholdFunctionalScore(const CvLSVMFilterObject **filters, const int n,
const CvLSVMFeaturePyramid *H, const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
int *kLevels, int **procLevels,
const int threadsNum,
float **score, CvPoint ***points,
int *kPoints,
CvPoint ****partsDisplacement)
{
tbb::task_list tasks;
int i;
for (i = 0; i < threadsNum; i++)
{
ScoreComputation& sc =
*new(tbb::task::allocate_root()) ScoreComputation(filters, n, H, b,
maxXBorder, maxYBorder, scoreThreshold, kLevels[i], procLevels[i],
score, points, kPoints, partsDisplacement);
tasks.push_back(sc);
}
tbb::task::spawn_root_and_wait(tasks);
return LATENT_SVM_OK;
};
#endif
#include "precomp.hpp"
#ifdef HAVE_TBB
#include "_lsvm_tbbversion.h"
/*
// Task class
*/
class ScoreComputation : public tbb::task
{
private:
const CvLSVMFilterObject **filters;
const int n;
const CvLSVMFeaturePyramid *H;
const float b;
const int maxXBorder;
const int maxYBorder;
const float scoreThreshold;
const int kLevels;
const int *procLevels;
public:
float **score;
CvPoint ***points;
CvPoint ****partsDisplacement;
int *kPoints;
public:
ScoreComputation(const CvLSVMFilterObject **_filters, int _n,
const CvLSVMFeaturePyramid *_H,
float _b, int _maxXBorder, int _maxYBorder,
float _scoreThreshold, int _kLevels, const int *_procLevels,
float **_score, CvPoint ***_points, int *_kPoints,
CvPoint ****_partsDisplacement) :
n(_n), b(_b), maxXBorder(_maxXBorder),
maxYBorder(_maxYBorder), scoreThreshold(_scoreThreshold),
kLevels(_kLevels), score(_score), points(_points),
partsDisplacement(_partsDisplacement), kPoints(_kPoints)
{
filters = _filters;
H = _H;
procLevels = _procLevels;
};
task* execute()
{
int i, level, partsLevel, res;
for (i = 0; i < kLevels; i++)
{
level = procLevels[i];
partsLevel = level - LAMBDA;//H->lambda;
res = thresholdFunctionalScoreFixedLevel(
filters, n, H, level, b,
maxXBorder, maxYBorder, scoreThreshold, &(score[partsLevel]),
points[partsLevel], &(kPoints[partsLevel]),
partsDisplacement[partsLevel]);
if (res != LATENT_SVM_OK)
{
continue;
}
}
return NULL;
}
};
/*
// Computation score function using TBB tasks
//
// API
// int tbbTasksThresholdFunctionalScore(const CvLSVMFilterObject **filters, const int n,
const CvLSVMFeatureMap *H, const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
int *kLevels, int **procLevels,
const int threadsNum,
float **score, CvPoint ***points,
int *kPoints,
CvPoint ****partsDisplacement);
// INPUT
// filters - the set of filters (the first element is root filter,
the other - part filters)
// n - the number of part filters
// H - feature pyramid
// b - linear term of the score function
// maxXBorder - the largest root filter size (X-direction)
// maxYBorder - the largest root filter size (Y-direction)
// scoreThreshold - score threshold
// kLevels - array that contains number of levels processed
by each thread
// procLevels - array that contains lists of levels processed
by each thread
// threadsNum - the number of created threads
// OUTPUT
// score - score function values that exceed threshold
// points - the set of root filter positions (in the block space)
// kPoints - number of root filter positions
// partsDisplacement - displacement of part filters (in the block space)
// RESULT
//
*/
int tbbTasksThresholdFunctionalScore(const CvLSVMFilterObject **filters, const int n,
const CvLSVMFeaturePyramid *H, const float b,
const int maxXBorder, const int maxYBorder,
const float scoreThreshold,
int *kLevels, int **procLevels,
const int threadsNum,
float **score, CvPoint ***points,
int *kPoints,
CvPoint ****partsDisplacement)
{
tbb::task_list tasks;
int i;
for (i = 0; i < threadsNum; i++)
{
ScoreComputation& sc =
*new(tbb::task::allocate_root()) ScoreComputation(filters, n, H, b,
maxXBorder, maxYBorder, scoreThreshold, kLevels[i], procLevels[i],
score, points, kPoints, partsDisplacement);
tasks.push_back(sc);
}
tbb::task::spawn_root_and_wait(tasks);
return LATENT_SVM_OK;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,241 +1,241 @@
#include "precomp.hpp"
#include "_lsvm_resizeimg.h"
#include <stdio.h>
#include <assert.h>
#include <math.h>
IplImage* resize_opencv(IplImage* img, float scale)
{
IplImage* imgTmp;
int W, H, tW, tH;
W = img->width;
H = img->height;
tW = (int)(((float)W) * scale + 0.5);
tH = (int)(((float)H) * scale + 0.5);
imgTmp = cvCreateImage(cvSize(tW , tH), img->depth, img->nChannels);
cvResize(img, imgTmp, CV_INTER_AREA);
return imgTmp;
}
//
///*
// * Fast image subsampling.
// * This is used to construct the feature pyramid.
// */
//
//// struct used for caching interpolation values
//typedef struct {
// int si, di;
// float alpha;
//}alphainfo;
//
//// copy src into dst using pre-computed interpolation values
//void alphacopy(float *src, float *dst, alphainfo *ofs, int n) {
// int i;
// for(i = 0; i < n; i++){
// dst[ofs[i].di] += ofs[i].alpha * src[ofs[i].si];
// }
//}
//
//int round(float val){
// return (int)(val + 0.5);
//}
//void bzero(float * arr, int cnt){
// int i;
// for(i = 0; i < cnt; i++){
// arr[i] = 0.0f;
// }
//}
//// resize along each column
//// result is transposed, so we can apply it twice for a complete resize
//void resize1dtran(float *src, int sheight, float *dst, int dheight,
// int width, int chan) {
// alphainfo *ofs;
// float scale = (float)dheight/(float)sheight;
// float invscale = (float)sheight/(float)dheight;
//
// // we cache the interpolation values since they can be
// // shared among different columns
// int len = (int)ceilf(dheight*invscale) + 2*dheight;
// int k = 0;
// int dy;
// float fsy1;
// float fsy2;
// int sy1;
// int sy2;
// int sy;
// int c, x;
// float *s, *d;
//
// ofs = (alphainfo *) malloc (sizeof(alphainfo) * len);
// for (dy = 0; dy < dheight; dy++) {
// fsy1 = dy * invscale;
// fsy2 = fsy1 + invscale;
// sy1 = (int)ceilf(fsy1);
// sy2 = (int)floorf(fsy2);
//
// if (sy1 - fsy1 > 1e-3) {
// assert(k < len);
// assert(sy1 - 1 >= 0);
// ofs[k].di = dy*width;
// ofs[k].si = sy1-1;
// ofs[k++].alpha = (sy1 - fsy1) * scale;
// }
//
// for (sy = sy1; sy < sy2; sy++) {
// assert(k < len);
// assert(sy < sheight);
// ofs[k].di = dy*width;
// ofs[k].si = sy;
// ofs[k++].alpha = scale;
// }
//
// if (fsy2 - sy2 > 1e-3) {
// assert(k < len);
// assert(sy2 < sheight);
// ofs[k].di = dy*width;
// ofs[k].si = sy2;
// ofs[k++].alpha = (fsy2 - sy2) * scale;
// }
// }
//
// // resize each column of each color channel
// bzero(dst, chan*width*dheight);
// for (c = 0; c < chan; c++) {
// for (x = 0; x < width; x++) {
// s = src + c*width*sheight + x*sheight;
// d = dst + c*width*dheight + x;
// alphacopy(s, d, ofs, k);
// }
// }
// free(ofs);
//}
//
//IplImage * resize_article_dp(IplImage * img, float scale, const int k){
// IplImage * imgTmp;
// float W, H;
// unsigned char *dataSrc;
// float * dataf;
// float *src, *dst, *tmp;
// int i, j, kk, channels;
// int index;
// int widthStep;
// int tW, tH;
//
// W = (float)img->width;
// H = (float)img->height;
// channels = img->nChannels;
// widthStep = img->widthStep;
//
// tW = (int)(((float)W) * scale + 0.5f);
// tH = (int)(((float)H) * scale + 0.5f);
//
// src = (float *)malloc(sizeof(float) * (int)(W * H * 3));
//
// dataSrc = (unsigned char*)(img->imageData);
// index = 0;
// for (kk = 0; kk < channels; kk++)
// {
// for (i = 0; i < W; i++)
// {
// for (j = 0; j < H; j++)
// {
// src[index++] = (float)dataSrc[j * widthStep + i * channels + kk];
// }
// }
// }
//
// imgTmp = cvCreateImage(cvSize(tW , tH), IPL_DEPTH_32F, channels);
//
// dst = (float *)malloc(sizeof(float) * (int)(tH * tW) * channels);
// tmp = (float *)malloc(sizeof(float) * (int)(tH * W) * channels);
//
// resize1dtran(src, (int)H, tmp, (int)tH, (int)W , 3);
//
// resize1dtran(tmp, (int)W, dst, (int)tW, (int)tH, 3);
//
// index = 0;
// //dataf = (float*)imgTmp->imageData;
// for (kk = 0; kk < channels; kk++)
// {
// for (i = 0; i < tW; i++)
// {
// for (j = 0; j < tH; j++)
// {
// dataf = (float*)(imgTmp->imageData + j * imgTmp->widthStep);
// dataf[ i * channels + kk] = dst[index++];
// }
// }
// }
//
// free(src);
// free(dst);
// free(tmp);
// return imgTmp;
//}
//
//IplImage * resize_article_dp1(IplImage * img, float scale, const int k){
// IplImage * imgTmp;
// float W, H;
// float * dataf;
// float *src, *dst, *tmp;
// int i, j, kk, channels;
// int index;
// int widthStep;
// int tW, tH;
//
// W = (float)img->width;
// H = (float)img->height;
// channels = img->nChannels;
// widthStep = img->widthStep;
//
// tW = (int)(((float)W) * scale + 0.5f);
// tH = (int)(((float)H) * scale + 0.5f);
//
// src = (float *)malloc(sizeof(float) * (int)(W * H) * 3);
//
// index = 0;
// for (kk = 0; kk < channels; kk++)
// {
// for (i = 0; i < W; i++)
// {
// for (j = 0; j < H; j++)
// {
// src[index++] = (float)(*( (float *)(img->imageData + j * widthStep) + i * channels + kk));
// }
// }
// }
//
// imgTmp = cvCreateImage(cvSize(tW , tH), IPL_DEPTH_32F, channels);
//
// dst = (float *)malloc(sizeof(float) * (int)(tH * tW) * channels);
// tmp = (float *)malloc(sizeof(float) * (int)(tH * W) * channels);
//
// resize1dtran(src, (int)H, tmp, (int)tH, (int)W , 3);
//
// resize1dtran(tmp, (int)W, dst, (int)tW, (int)tH, 3);
//
// index = 0;
// for (kk = 0; kk < channels; kk++)
// {
// for (i = 0; i < tW; i++)
// {
// for (j = 0; j < tH; j++)
// {
// dataf = (float *)(imgTmp->imageData + j * imgTmp->widthStep);
// dataf[ i * channels + kk] = dst[index++];
// }
// }
// }
//
// free(src);
// free(dst);
// free(tmp);
// return imgTmp;
//}
//
#include "precomp.hpp"
#include "_lsvm_resizeimg.h"
#include <stdio.h>
#include <assert.h>
#include <math.h>
IplImage* resize_opencv(IplImage* img, float scale)
{
IplImage* imgTmp;
int W, H, tW, tH;
W = img->width;
H = img->height;
tW = (int)(((float)W) * scale + 0.5);
tH = (int)(((float)H) * scale + 0.5);
imgTmp = cvCreateImage(cvSize(tW , tH), img->depth, img->nChannels);
cvResize(img, imgTmp, CV_INTER_AREA);
return imgTmp;
}
//
///*
// * Fast image subsampling.
// * This is used to construct the feature pyramid.
// */
//
//// struct used for caching interpolation values
//typedef struct {
// int si, di;
// float alpha;
//}alphainfo;
//
//// copy src into dst using pre-computed interpolation values
//void alphacopy(float *src, float *dst, alphainfo *ofs, int n) {
// int i;
// for(i = 0; i < n; i++){
// dst[ofs[i].di] += ofs[i].alpha * src[ofs[i].si];
// }
//}
//
//int round(float val){
// return (int)(val + 0.5);
//}
//void bzero(float * arr, int cnt){
// int i;
// for(i = 0; i < cnt; i++){
// arr[i] = 0.0f;
// }
//}
//// resize along each column
//// result is transposed, so we can apply it twice for a complete resize
//void resize1dtran(float *src, int sheight, float *dst, int dheight,
// int width, int chan) {
// alphainfo *ofs;
// float scale = (float)dheight/(float)sheight;
// float invscale = (float)sheight/(float)dheight;
//
// // we cache the interpolation values since they can be
// // shared among different columns
// int len = (int)ceilf(dheight*invscale) + 2*dheight;
// int k = 0;
// int dy;
// float fsy1;
// float fsy2;
// int sy1;
// int sy2;
// int sy;
// int c, x;
// float *s, *d;
//
// ofs = (alphainfo *) malloc (sizeof(alphainfo) * len);
// for (dy = 0; dy < dheight; dy++) {
// fsy1 = dy * invscale;
// fsy2 = fsy1 + invscale;
// sy1 = (int)ceilf(fsy1);
// sy2 = (int)floorf(fsy2);
//
// if (sy1 - fsy1 > 1e-3) {
// assert(k < len);
// assert(sy1 - 1 >= 0);
// ofs[k].di = dy*width;
// ofs[k].si = sy1-1;
// ofs[k++].alpha = (sy1 - fsy1) * scale;
// }
//
// for (sy = sy1; sy < sy2; sy++) {
// assert(k < len);
// assert(sy < sheight);
// ofs[k].di = dy*width;
// ofs[k].si = sy;
// ofs[k++].alpha = scale;
// }
//
// if (fsy2 - sy2 > 1e-3) {
// assert(k < len);
// assert(sy2 < sheight);
// ofs[k].di = dy*width;
// ofs[k].si = sy2;
// ofs[k++].alpha = (fsy2 - sy2) * scale;
// }
// }
//
// // resize each column of each color channel
// bzero(dst, chan*width*dheight);
// for (c = 0; c < chan; c++) {
// for (x = 0; x < width; x++) {
// s = src + c*width*sheight + x*sheight;
// d = dst + c*width*dheight + x;
// alphacopy(s, d, ofs, k);
// }
// }
// free(ofs);
//}
//
//IplImage * resize_article_dp(IplImage * img, float scale, const int k){
// IplImage * imgTmp;
// float W, H;
// unsigned char *dataSrc;
// float * dataf;
// float *src, *dst, *tmp;
// int i, j, kk, channels;
// int index;
// int widthStep;
// int tW, tH;
//
// W = (float)img->width;
// H = (float)img->height;
// channels = img->nChannels;
// widthStep = img->widthStep;
//
// tW = (int)(((float)W) * scale + 0.5f);
// tH = (int)(((float)H) * scale + 0.5f);
//
// src = (float *)malloc(sizeof(float) * (int)(W * H * 3));
//
// dataSrc = (unsigned char*)(img->imageData);
// index = 0;
// for (kk = 0; kk < channels; kk++)
// {
// for (i = 0; i < W; i++)
// {
// for (j = 0; j < H; j++)
// {
// src[index++] = (float)dataSrc[j * widthStep + i * channels + kk];
// }
// }
// }
//
// imgTmp = cvCreateImage(cvSize(tW , tH), IPL_DEPTH_32F, channels);
//
// dst = (float *)malloc(sizeof(float) * (int)(tH * tW) * channels);
// tmp = (float *)malloc(sizeof(float) * (int)(tH * W) * channels);
//
// resize1dtran(src, (int)H, tmp, (int)tH, (int)W , 3);
//
// resize1dtran(tmp, (int)W, dst, (int)tW, (int)tH, 3);
//
// index = 0;
// //dataf = (float*)imgTmp->imageData;
// for (kk = 0; kk < channels; kk++)
// {
// for (i = 0; i < tW; i++)
// {
// for (j = 0; j < tH; j++)
// {
// dataf = (float*)(imgTmp->imageData + j * imgTmp->widthStep);
// dataf[ i * channels + kk] = dst[index++];
// }
// }
// }
//
// free(src);
// free(dst);
// free(tmp);
// return imgTmp;
//}
//
//IplImage * resize_article_dp1(IplImage * img, float scale, const int k){
// IplImage * imgTmp;
// float W, H;
// float * dataf;
// float *src, *dst, *tmp;
// int i, j, kk, channels;
// int index;
// int widthStep;
// int tW, tH;
//
// W = (float)img->width;
// H = (float)img->height;
// channels = img->nChannels;
// widthStep = img->widthStep;
//
// tW = (int)(((float)W) * scale + 0.5f);
// tH = (int)(((float)H) * scale + 0.5f);
//
// src = (float *)malloc(sizeof(float) * (int)(W * H) * 3);
//
// index = 0;
// for (kk = 0; kk < channels; kk++)
// {
// for (i = 0; i < W; i++)
// {
// for (j = 0; j < H; j++)
// {
// src[index++] = (float)(*( (float *)(img->imageData + j * widthStep) + i * channels + kk));
// }
// }
// }
//
// imgTmp = cvCreateImage(cvSize(tW , tH), IPL_DEPTH_32F, channels);
//
// dst = (float *)malloc(sizeof(float) * (int)(tH * tW) * channels);
// tmp = (float *)malloc(sizeof(float) * (int)(tH * W) * channels);
//
// resize1dtran(src, (int)H, tmp, (int)tH, (int)W , 3);
//
// resize1dtran(tmp, (int)W, dst, (int)tW, (int)tH, 3);
//
// index = 0;
// for (kk = 0; kk < channels; kk++)
// {
// for (i = 0; i < tW; i++)
// {
// for (j = 0; j < tH; j++)
// {
// dataf = (float *)(imgTmp->imageData + j * imgTmp->widthStep);
// dataf[ i * channels + kk] = dst[index++];
// }
// }
// }
//
// free(src);
// free(dst);
// free(tmp);
// return imgTmp;
//}
//

View File

@@ -1,117 +1,117 @@
#include "precomp.hpp"
#include "_lsvm_routine.h"
int allocFilterObject(CvLSVMFilterObject **obj, const int sizeX,
const int sizeY, const int numFeatures)
{
int i;
(*obj) = (CvLSVMFilterObject *)malloc(sizeof(CvLSVMFilterObject));
(*obj)->sizeX = sizeX;
(*obj)->sizeY = sizeY;
(*obj)->numFeatures = numFeatures;
(*obj)->fineFunction[0] = 0.0f;
(*obj)->fineFunction[1] = 0.0f;
(*obj)->fineFunction[2] = 0.0f;
(*obj)->fineFunction[3] = 0.0f;
(*obj)->V.x = 0;
(*obj)->V.y = 0;
(*obj)->V.l = 0;
(*obj)->H = (float *) malloc(sizeof (float) *
(sizeX * sizeY * numFeatures));
for(i = 0; i < sizeX * sizeY * numFeatures; i++)
{
(*obj)->H[i] = 0.0f;
}
return LATENT_SVM_OK;
}
int freeFilterObject (CvLSVMFilterObject **obj)
{
if(*obj == NULL) return LATENT_SVM_MEM_NULL;
free((*obj)->H);
free(*obj);
(*obj) = NULL;
return LATENT_SVM_OK;
}
int allocFeatureMapObject(CvLSVMFeatureMap **obj, const int sizeX,
const int sizeY, const int numFeatures)
{
int i;
(*obj) = (CvLSVMFeatureMap *)malloc(sizeof(CvLSVMFeatureMap));
(*obj)->sizeX = sizeX;
(*obj)->sizeY = sizeY;
(*obj)->numFeatures = numFeatures;
(*obj)->map = (float *) malloc(sizeof (float) *
(sizeX * sizeY * numFeatures));
for(i = 0; i < sizeX * sizeY * numFeatures; i++)
{
(*obj)->map[i] = 0.0f;
}
return LATENT_SVM_OK;
}
int freeFeatureMapObject (CvLSVMFeatureMap **obj)
{
if(*obj == NULL) return LATENT_SVM_MEM_NULL;
free((*obj)->map);
free(*obj);
(*obj) = NULL;
return LATENT_SVM_OK;
}
int allocFeaturePyramidObject(CvLSVMFeaturePyramid **obj,
const int numLevels)
{
(*obj) = (CvLSVMFeaturePyramid *)malloc(sizeof(CvLSVMFeaturePyramid));
(*obj)->numLevels = numLevels;
(*obj)->pyramid = (CvLSVMFeatureMap **)malloc(
sizeof(CvLSVMFeatureMap *) * numLevels);
return LATENT_SVM_OK;
}
int freeFeaturePyramidObject (CvLSVMFeaturePyramid **obj)
{
int i;
if(*obj == NULL) return LATENT_SVM_MEM_NULL;
for(i = 0; i < (*obj)->numLevels; i++)
{
freeFeatureMapObject(&((*obj)->pyramid[i]));
}
free((*obj)->pyramid);
free(*obj);
(*obj) = NULL;
return LATENT_SVM_OK;
}
int allocFFTImage(CvLSVMFftImage **image, int numFeatures, int dimX, int dimY)
{
int i, j, size;
*image = (CvLSVMFftImage *)malloc(sizeof(CvLSVMFftImage));
(*image)->numFeatures = numFeatures;
(*image)->dimX = dimX;
(*image)->dimY = dimY;
(*image)->channels = (float **)malloc(sizeof(float *) * numFeatures);
size = 2 * dimX * dimY;
for (i = 0; i < numFeatures; i++)
{
(*image)->channels[i] = (float *)malloc(sizeof(float) * size);
for (j = 0; j < size; j++)
{
(*image)->channels[i][j] = 0.0f;
}
}
return LATENT_SVM_OK;
}
int freeFFTImage(CvLSVMFftImage **image)
{
int i;
if (*image == NULL) return LATENT_SVM_OK;
for (i = 0; i < (*image)->numFeatures; i++)
{
free((*image)->channels[i]);
(*image)->channels[i] = NULL;
}
free((*image)->channels);
(*image)->channels = NULL;
return LATENT_SVM_OK;
}
#include "precomp.hpp"
#include "_lsvm_routine.h"
int allocFilterObject(CvLSVMFilterObject **obj, const int sizeX,
const int sizeY, const int numFeatures)
{
int i;
(*obj) = (CvLSVMFilterObject *)malloc(sizeof(CvLSVMFilterObject));
(*obj)->sizeX = sizeX;
(*obj)->sizeY = sizeY;
(*obj)->numFeatures = numFeatures;
(*obj)->fineFunction[0] = 0.0f;
(*obj)->fineFunction[1] = 0.0f;
(*obj)->fineFunction[2] = 0.0f;
(*obj)->fineFunction[3] = 0.0f;
(*obj)->V.x = 0;
(*obj)->V.y = 0;
(*obj)->V.l = 0;
(*obj)->H = (float *) malloc(sizeof (float) *
(sizeX * sizeY * numFeatures));
for(i = 0; i < sizeX * sizeY * numFeatures; i++)
{
(*obj)->H[i] = 0.0f;
}
return LATENT_SVM_OK;
}
int freeFilterObject (CvLSVMFilterObject **obj)
{
if(*obj == NULL) return LATENT_SVM_MEM_NULL;
free((*obj)->H);
free(*obj);
(*obj) = NULL;
return LATENT_SVM_OK;
}
int allocFeatureMapObject(CvLSVMFeatureMap **obj, const int sizeX,
const int sizeY, const int numFeatures)
{
int i;
(*obj) = (CvLSVMFeatureMap *)malloc(sizeof(CvLSVMFeatureMap));
(*obj)->sizeX = sizeX;
(*obj)->sizeY = sizeY;
(*obj)->numFeatures = numFeatures;
(*obj)->map = (float *) malloc(sizeof (float) *
(sizeX * sizeY * numFeatures));
for(i = 0; i < sizeX * sizeY * numFeatures; i++)
{
(*obj)->map[i] = 0.0f;
}
return LATENT_SVM_OK;
}
int freeFeatureMapObject (CvLSVMFeatureMap **obj)
{
if(*obj == NULL) return LATENT_SVM_MEM_NULL;
free((*obj)->map);
free(*obj);
(*obj) = NULL;
return LATENT_SVM_OK;
}
int allocFeaturePyramidObject(CvLSVMFeaturePyramid **obj,
const int numLevels)
{
(*obj) = (CvLSVMFeaturePyramid *)malloc(sizeof(CvLSVMFeaturePyramid));
(*obj)->numLevels = numLevels;
(*obj)->pyramid = (CvLSVMFeatureMap **)malloc(
sizeof(CvLSVMFeatureMap *) * numLevels);
return LATENT_SVM_OK;
}
int freeFeaturePyramidObject (CvLSVMFeaturePyramid **obj)
{
int i;
if(*obj == NULL) return LATENT_SVM_MEM_NULL;
for(i = 0; i < (*obj)->numLevels; i++)
{
freeFeatureMapObject(&((*obj)->pyramid[i]));
}
free((*obj)->pyramid);
free(*obj);
(*obj) = NULL;
return LATENT_SVM_OK;
}
int allocFFTImage(CvLSVMFftImage **image, int numFeatures, int dimX, int dimY)
{
int i, j, size;
*image = (CvLSVMFftImage *)malloc(sizeof(CvLSVMFftImage));
(*image)->numFeatures = numFeatures;
(*image)->dimX = dimX;
(*image)->dimY = dimY;
(*image)->channels = (float **)malloc(sizeof(float *) * numFeatures);
size = 2 * dimX * dimY;
for (i = 0; i < numFeatures; i++)
{
(*image)->channels[i] = (float *)malloc(sizeof(float) * size);
for (j = 0; j < size; j++)
{
(*image)->channels[i][j] = 0.0f;
}
}
return LATENT_SVM_OK;
}
int freeFFTImage(CvLSVMFftImage **image)
{
int i;
if (*image == NULL) return LATENT_SVM_OK;
for (i = 0; i < (*image)->numFeatures; i++)
{
free((*image)->channels[i]);
(*image)->channels[i] = NULL;
}
free((*image)->channels);
(*image)->channels = NULL;
return LATENT_SVM_OK;
}