Image-CCV
view release on metacpan or search on metacpan
ccv-src/lib/ccv.h view on Meta::CPAN
} ccv_decimal_pose_t;
inline static ccv_decimal_pose_t ccv_decimal_pose(float x, float y, float a, float b, float roll, float pitch, float yaw)
{
ccv_decimal_pose_t pose;
pose.x = x;
pose.y = y;
pose.a = a;
pose.b = b;
pose.roll = roll;
pose.pitch = pitch;
pose.yaw = yaw;
return pose;
}
typedef struct {
ccv_rect_t rect;
int size;
ccv_array_t* set;
long m10, m01, m11, m20, m02;
} ccv_contour_t;
/**
* Create a new contour object.
* @param set The initial capacity of the contour.
*/
ccv_contour_t* ccv_contour_new(int set);
/**
* Push a point into the contour object.
* @param contour The contour.
* @param point The point.
*/
void ccv_contour_push(ccv_contour_t* contour, ccv_point_t point);
/**
* Free up the contour object.
* @param contour The contour.
*/
void ccv_contour_free(ccv_contour_t* contour);
/** @} */
/* numerical algorithms ccv_numeric.c */
/**
* @defgroup ccv_numeric numerical algorithms
* @{
*/
/* clarification about algebra and numerical algorithms:
* when using the word "algebra", I assume the operation is well established in Mathematic sense
* and can be calculated with a straight-forward, finite sequence of operation. The "numerical"
* in other word, refer to a class of algorithm that can only approximate/or iteratively found the
* solution. Thus, "invert" would be classified as numerical because of the sense that in some case,
* it can only be "approximate" (in least-square sense), so to "solve". */
void ccv_invert(ccv_matrix_t* a, ccv_matrix_t** b, int type);
void ccv_solve(ccv_matrix_t* a, ccv_matrix_t* b, ccv_matrix_t** d, int type);
void ccv_eigen(ccv_dense_matrix_t* a, ccv_dense_matrix_t** vector, ccv_dense_matrix_t** lambda, int type, double epsilon);
typedef struct {
double interp; /**< Interpolate value. */
double extrap; /**< Extrapolate value. */
int max_iter; /**< Maximum iterations. */
double ratio; /**< Increase ratio. */
double rho; /**< Decrease ratio. */
double sig; /**< Sigma. */
} ccv_minimize_param_t;
extern const ccv_minimize_param_t ccv_minimize_default_params;
typedef int(*ccv_minimize_f)(const ccv_dense_matrix_t* x, double* f, ccv_dense_matrix_t* df, void*);
/**
* Linear-search to minimize function with partial derivatives. It is formed after [minimize.m](http://www.gatsby.ucl.ac.uk/~edward/code/minimize/example.html).
* @param x The input vector.
* @param length The length of line.
* @param red The step size.
* @param func (int ccv_minimize_f)(const ccv_dense_matrix_t* x, double* f, ccv_dense_matrix_t* df, void* data). Compute the function value, and its partial derivatives.
* @param params A **ccv_minimize_param_t** structure that defines various aspect of the minimize function.
* @param data Any extra user data.
*/
void ccv_minimize(ccv_dense_matrix_t* x, int length, double red, ccv_minimize_f func, ccv_minimize_param_t params, void* data);
/**
* Convolve on dense matrix a with dense matrix b. This function has a soft dependency on [FFTW3](http://fftw.org/). If no FFTW3 exists, ccv will use [KissFFT](http://sourceforge.net/projects/kissfft/) shipped with it. FFTW3 is about 35% faster than ...
* @param a Dense matrix a.
* @param b Dense matrix b.
* @param d The output matrix.
* @param type The type of output matrix, if 0, ccv will try to match the input matrix for appropriate type.
* @param padding_pattern ccv doesn't support padding pattern for now.
*/
void ccv_filter(ccv_dense_matrix_t* a, ccv_dense_matrix_t* b, ccv_dense_matrix_t** d, int type, int padding_pattern);
typedef double(*ccv_filter_kernel_f)(double x, double y, void*);
/**
* Fill a given dense matrix with a kernel function.
* @param x The matrix to be filled with.
* @param func (double ccv_filter_kernel_f(double x, double y, void* data), compute the value with given x, y.
* @param data Any extra user data.
*/
void ccv_filter_kernel(ccv_dense_matrix_t* x, ccv_filter_kernel_f func, void* data);
/* modern numerical algorithms */
/**
* [Distance transform](https://en.wikipedia.org/wiki/Distance_transform). The current implementation follows [Distance Transforms of Sampled Functions](http://www.cs.cornell.edu/~dph/papers/dt.pdf). The dynamic programming technique has O(n) time co...
* @param a The input matrix.
* @param b The output matrix.
* @param type The type of output matrix, if 0, ccv will try to match the input matrix for appropriate type.
* @param x The x coordinate offset.
* @param x_type The type of output x coordinate offset, if 0, ccv will default to CCV_32S | CCV_C1.
* @param y The y coordinate offset.
* @param y_type The type of output x coordinate offset, if 0, ccv will default to CCV_32S | CCV_C1.
* @param dx The x coefficient.
* @param dy The y coefficient.
* @param dxx The x^2 coefficient.
* @param dyy The y^2 coefficient.
* @param flag CCV_GSEDT, generalized squared Euclidean distance transform. CCV_NEGATIVE, negate value in input matrix for computation; effectively, this enables us to compute the maximum distance transform rather than minimum (default one).
*/
void ccv_distance_transform(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type, ccv_dense_matrix_t** x, int x_type, ccv_dense_matrix_t** y, int y_type, double dx, double dy, double dxx, double dyy, int flag);
/** @} */
void ccv_sparse_coding(ccv_matrix_t* x, int k, ccv_matrix_t** A, int typeA, ccv_matrix_t** y, int typey);
void ccv_compressive_sensing_reconstruct(ccv_matrix_t* a, ccv_matrix_t* x, ccv_matrix_t** y, int type);
/**
* @defgroup ccv_basic basic image pre-processing utilities
* The utilities in this file provides basic pre-processing which, most-likely, are the first steps for computer vision algorithms.
ccv-src/lib/ccv.h view on Meta::CPAN
/**
* @defgroup ccv_dpm deformable parts model
* @{
*/
#define CCV_DPM_PART_MAX (10)
typedef struct {
int id;
float confidence;
} ccv_classification_t;
typedef struct {
ccv_rect_t rect;
int neighbors;
ccv_classification_t classification;
} ccv_comp_t;
typedef struct {
ccv_rect_t rect;
int neighbors;
ccv_classification_t classification;
int pnum;
ccv_comp_t part[CCV_DPM_PART_MAX];
} ccv_root_comp_t;
typedef struct {
ccv_dense_matrix_t* w;
double dx, dy, dxx, dyy;
int x, y, z;
int counterpart;
float alpha[6];
} ccv_dpm_part_classifier_t;
typedef struct {
int count;
ccv_dpm_part_classifier_t root;
ccv_dpm_part_classifier_t* part;
float alpha[3], beta;
} ccv_dpm_root_classifier_t;
typedef struct {
int count;
ccv_dpm_root_classifier_t* root;
} ccv_dpm_mixture_model_t;
typedef struct {
int interval; /**< Interval images between the full size image and the half size one. e.g. 2 will generate 2 images in between full size image and half size one: image with full size, image with 5/6 size, image with 2/3 size, image with 1/2 size. */
int min_neighbors; /**< 0: no grouping afterwards. 1: group objects that intersects each other. > 1: group objects that intersects each other, and only passes these that have at least **min_neighbors** intersected objects. */
int flags; /**< CCV_DPM_NO_NESTED, if one class of object is inside another class of object, this flag will reject the first object. */
float threshold; /**< The threshold the determines the acceptance of an object. */
} ccv_dpm_param_t;
typedef struct {
int components; /**< The number of root filters in the mixture model. */
int parts; /**< The number of part filters for each root filter. */
int grayscale; /**< Whether to exploit color in a given image. */
int symmetric; /**< Whether to exploit symmetric property of the object. */
int min_area; /**< The minimum area that one part classifier can occupy, 3000 is a reasonable number. */
int max_area; /**< The maximum area that one part classifier can occupy. 5000 is a reasonable number. */
int iterations; /**< How many iterations needed for stochastic gradient descent. */
int data_minings; /**< How many data mining procedures are needed for discovering hard examples. */
int root_relabels; /**< How many relabel procedures for root classifier are needed. */
int relabels; /**< How many relabel procedures are needed. */
int discard_estimating_constant; // 1
int negative_cache_size; /**< The cache size for negative examples. 1000 is a reasonable number. */
double include_overlap; /**< The percentage of overlap between expected bounding box and the bounding box from detection. Beyond this threshold, it is ensured to be the same object. 0.7 is a reasonable number. */
double alpha; /**< The step size for stochastic gradient descent. */
double alpha_ratio; /**< Decrease the step size for each iteration. 0.85 is a reasonable number. */
double balance; /**< To balance the weight of positive examples and negative examples. 1.5 is a reasonable number. */
double C; /**< C in SVM. */
double percentile_breakdown; /**< The percentile use for breakdown threshold. 0.05 is the default. */
ccv_dpm_param_t detector; /**< A **ccv_dpm_params_t** structure that will be used to search positive examples and negative examples from background images. */
} ccv_dpm_new_param_t;
enum {
CCV_DPM_NO_NESTED = 0x10000000,
};
extern const ccv_dpm_param_t ccv_dpm_default_params;
/**
* Create a new DPM mixture model from given positive examples and background images. This function has hard dependencies on [GSL](http://www.gnu.org/software/gsl/) and [LibLinear](http://www.csie.ntu.edu.tw/~cjlin/liblinear/).
* @param posfiles An array of positive images.
* @param bboxes An array of bounding boxes for positive images.
* @param posnum Number of positive examples.
* @param bgfiles An array of background images.
* @param bgnum Number of background images.
* @param negnum Number of negative examples that is harvested from background images.
* @param dir The working directory to store/retrieve intermediate data.
* @param params A **ccv_dpm_new_param_t** structure that defines various aspects of the training function.
*/
void ccv_dpm_mixture_model_new(char** posfiles, ccv_rect_t* bboxes, int posnum, char** bgfiles, int bgnum, int negnum, const char* dir, ccv_dpm_new_param_t params);
/**
* Using a DPM mixture model to detect objects in a given image. If you have several DPM mixture models, it is better to use them in one method call. In this way, ccv will try to optimize the overall performance.
* @param a The input image.
* @param model An array of mixture models.
* @param count How many mixture models you've passed in.
* @param params A **ccv_dpm_param_t** structure that defines various aspects of the detector.
* @return A **ccv_array_t** of **ccv_root_comp_t** that contains the root bounding box as well as its parts.
*/
CCV_WARN_UNUSED(ccv_array_t*) ccv_dpm_detect_objects(ccv_dense_matrix_t* a, ccv_dpm_mixture_model_t** model, int count, ccv_dpm_param_t params);
/**
* Read DPM mixture model from a model file.
* @param directory The model file for DPM mixture model.
* @return A DPM mixture model, 0 if no valid DPM mixture model available.
*/
CCV_WARN_UNUSED(ccv_dpm_mixture_model_t*) ccv_dpm_read_mixture_model(const char* directory);
/**
* Free up the memory of DPM mixture model.
* @param model The DPM mixture model.
*/
void ccv_dpm_mixture_model_free(ccv_dpm_mixture_model_t* model);
/** @} */
/**
* @defgroup ccv_bbf binary brightness feature
* this is open source implementation of object detection algorithm: brightness binary feature
* it is an extension/modification of original HAAR-like feature with Adaboost, featured faster
* computation and higher accuracy (current highest accuracy close-source face detector is based
* on the same algorithm)
ccv-src/lib/ccv.h view on Meta::CPAN
} matrix;
struct {
int count; /**< [node.count] The number of nodes. You should either use **node** or **matrix** to specify the input structure. */
} node;
} ccv_convnet_input_t;
typedef struct {
int type; /**< One of following value to specify the network layer type, **CCV_CONVNET_CONVOLUTIONAL**, **CCV_CONVNET_FULL_CONNECT**, **CCV_CONVNET_MAX_POOL**, **CCV_CONVNET_AVERAGE_POOL**, **CCV_CONVNET_LOCAL_RESPONSE_NORM**. */
float bias; /**< The initialization value for bias if applicable (for convolutional layer and full connect layer). */
float glorot; /**< The truncated uniform distribution coefficients for weights if applicable (for convolutional layer and full connect layer, glorot / sqrt(in + out)). */
ccv_convnet_input_t input; /**< A **ccv_convnet_input_t** specifies the input structure. */
ccv_convnet_type_t output; /**< A **ccv_convnet_type_t** specifies the output parameters and structure. */
} ccv_convnet_layer_param_t;
typedef struct {
int type;
float* w; // weight
float* bias; // bias
size_t wnum; // the number of weights
ccv_convnet_input_t input; // the input requirement
ccv_convnet_type_t net; // network configuration
void* reserved;
} ccv_convnet_layer_t;
typedef struct {
int use_cwc_accel; // use "ccv with cuda" acceleration
// this is redundant, but good to enforcing what the input should look like
ccv_size_t input;
int rows;
int cols;
int channels;
// count and layer of the convnet
int count;
ccv_dense_matrix_t* mean_activity; // mean activity to subtract from
ccv_convnet_layer_t* layers; // the layer configuration
// these can be reused and we don't need to reallocate memory
ccv_dense_matrix_t** denoms; // denominators
ccv_dense_matrix_t** acts; // hidden layers and output layers
void* reserved;
} ccv_convnet_t;
typedef struct {
float decay; /**< See **learn_rate**. */
float learn_rate; /**< New velocity = **momentum** * old velocity - **decay** * **learn_rate** * old value + **learn_rate** * delta, new value = old value + new velocity */
float momentum; /**< See **learn_rate**. */
} ccv_convnet_layer_sgd_param_t;
typedef struct {
// the dropout rate, I find that dor is better looking than dropout_rate,
// and drop out is happened on the input neuron (so that when the network
// is used in real-world, I simply need to multiply its weights to 1 - dor
// to get the real one)
float dor; /**< The dropout rate for this layer, it is only applicable for full connect layer. */
ccv_convnet_layer_sgd_param_t w; /**< A **ccv_convnet_layer_sgd_param_t** specifies the stochastic gradient descent update rule for weight, it is only applicable for full connect layer and convolutional layer. */
ccv_convnet_layer_sgd_param_t bias; /**< A **ccv_convnet_layer_sgd_param_t** specifies the stochastic gradient descent update rule for bias, it is only applicable for full connect layer and convolutional layer weight. */
} ccv_convnet_layer_train_param_t;
typedef struct {
int max_epoch; /**< The number of epoch (an epoch sweeps through all the examples) to go through before end the training. */
int mini_batch; /**< The number of examples for a batch in stochastic gradient descent. */
int iterations; /**< The number of iterations (an iteration is for one batch) before save the progress. */
int sgd_frequency; /**< After how many batches when we do a SGD update. */
int symmetric; /**< Whether to exploit the symmetric property of the provided examples. */
int device_count; /**< Use how many GPU devices, this is capped by available CUDA devices on your system. For now, ccv's implementation only support up to 4 GPUs */
int peer_access; /**< Enable peer access for cross device communications or not, this will enable faster multiple device training. */
float image_manipulation; /**< The value for image brightness / contrast / saturation manipulations. */
float color_gain; /**< The color variance for data augmentation (0 means no such augmentation). */
struct {
int min_dim; /**< [input.min_dim] The minimum dimensions for random resize of training images. */
int max_dim; /**< [input.max_dim] The maximum dimensions for random resize of training images. */
} input;
ccv_convnet_layer_train_param_t* layer_params; /**< An C-array of **ccv_convnet_layer_train_param_t** training parameters for each layer. */
} ccv_convnet_train_param_t;
typedef struct {
int half_precision; /**< Use half precision float point to represent network parameters. */
} ccv_convnet_write_param_t;
/**
* Create a new (deep) convolutional network with specified parameters. ccv only supports convolutional layer (shared weights), max pooling layer, average pooling layer, full connect layer and local response normalization layer.
* @param use_cwc_accel Whether use CUDA-enabled GPU to accelerate various computations for convolutional network.
* @param input Ihe input size of the image, it is not necessarily the input size of the first convolutional layer.
* @param params[] The C-array of **ccv_convnet_layer_param_t** that specifies the parameters for each layer.
* @param count The size of params[] C-array.
* @return A new deep convolutional network structs
*/
CCV_WARN_UNUSED(ccv_convnet_t*) ccv_convnet_new(int use_cwc_accel, ccv_size_t input, ccv_convnet_layer_param_t params[], int count);
/**
* Verify the specified parameters make sense as a deep convolutional network.
* @param convnet A deep convolutional network to verify.
* @param output The output number of nodes (for the last full connect layer).
* @return 0 if the given deep convolutional network making sense.
*/
int ccv_convnet_verify(ccv_convnet_t* convnet, int output);
/**
* Start to train a deep convolutional network with given parameters and data.
* @param convnet A deep convolutional network that is initialized.
* @param categorizeds An array of images with its category information for training.
* @param tests An array of images with its category information for validating.
* @param filename The working file to save progress and the trained convolutional network.
* @param params A ccv_convnet_train_param_t that specifies the training parameters.
*/
void ccv_convnet_supervised_train(ccv_convnet_t* convnet, ccv_array_t* categorizeds, ccv_array_t* tests, const char* filename, ccv_convnet_train_param_t params);
/**
* Use a convolutional network to encode an image into a compact representation.
* @param convnet The given convolutional network.
* @param a A C-array of input images.
* @param b A C-array of output matrix of compact representation.
* @param batch The number of input images.
*/
void ccv_convnet_encode(ccv_convnet_t* convnet, ccv_dense_matrix_t** a, ccv_dense_matrix_t** b, int batch);
void ccv_convnet_input_formation(ccv_size_t input, ccv_dense_matrix_t* a, ccv_dense_matrix_t** b);
/**
* Use a convolutional network to classify an image into categories.
* @param convnet The given convolutional network.
* @param a A C-array of input images.
* @param symmetric Whether the input is symmetric.
* @param ranks A C-array of **ccv_array_t** contains top categories by the convolutional network.
* @param tops The number of top categories return for each image.
* @param batch The number of input images.
*/
void ccv_convnet_classify(ccv_convnet_t* convnet, ccv_dense_matrix_t** a, int symmetric, ccv_array_t** ranks, int tops, int batch);
/**
* Read a convolutional network that persisted on the disk.
* @param use_cwc_accel Use CUDA-enabled GPU acceleration.
* @param filename The file on the disk.
*/
CCV_WARN_UNUSED(ccv_convnet_t*) ccv_convnet_read(int use_cwc_accel, const char* filename);
/**
* Write a convolutional network to a disk.
* @param convnet A given convolutional network.
* @param filename The file on the disk.
* @param params A **ccv_convnet_write_param_t** to specify the write parameters.
*/
void ccv_convnet_write(ccv_convnet_t* convnet, const char* filename, ccv_convnet_write_param_t params);
/**
* Free up temporary resources of a given convolutional network.
* @param convnet A convolutional network.
*/
void ccv_convnet_compact(ccv_convnet_t* convnet);
/**
* Free up the memory of a given convolutional network.
* @param convnet A convolutional network.
*/
void ccv_convnet_free(ccv_convnet_t* convnet);
/** @} */
/* add for command-line outputs, b/c ccv's training steps has a ton of outputs,
* and in the future, it can be piped into callback functions for critical information
* (such as the on-going missing rate, or iterations etc.) */
enum {
CCV_CLI_ERROR = 1 << 2,
CCV_CLI_INFO = 1 << 1,
CCV_CLI_VERBOSE = 1,
CCV_CLI_NONE = 0,
};
int ccv_cli_output_level_and_above(int level);
void ccv_cli_set_output_levels(int level);
int ccv_cli_get_output_levels(void);
#define CCV_CLI_SET_OUTPUT_LEVEL_AND_ABOVE(level) ccv_cli_set_output_levels(ccv_cli_output_level_and_above(level))
#define CCV_CLI_OUTPUT_LEVEL_IS(a) (a & ccv_cli_get_output_levels())
#endif
( run in 1.019 second using v1.01-cache-2.11-cpan-71847e10f99 )