Merge pull request #169 from mshabunin/remove-algorithm-factory
Remove algorithm factorypull/139/merge
commit
23314751aa
39 changed files with 1461 additions and 1758 deletions
@ -0,0 +1,144 @@ |
||||
/*
|
||||
* Copyright (c) 2011,2012. Philipp Wagner <bytefish[at]gmx[dot]de>. |
||||
* Released to public domain under terms of the BSD Simplified license. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of the organization nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* See <http://www.opensource.org/licenses/bsd-license>
|
||||
*/ |
||||
#include "precomp.hpp" |
||||
#include "face_basic.hpp" |
||||
#include <set> |
||||
#include <limits> |
||||
#include <iostream> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace face |
||||
{ |
||||
|
||||
// Turk, M., and Pentland, A. "Eigenfaces for recognition.". Journal of
|
||||
// Cognitive Neuroscience 3 (1991), 71–86.
|
||||
class Eigenfaces : public BasicFaceRecognizerImpl |
||||
{ |
||||
|
||||
public: |
||||
// Initializes an empty Eigenfaces model.
|
||||
Eigenfaces(int num_components = 0, double threshold = DBL_MAX) |
||||
: BasicFaceRecognizerImpl(num_components, threshold) |
||||
{} |
||||
|
||||
// Computes an Eigenfaces model with images in src and corresponding labels
|
||||
// in labels.
|
||||
void train(InputArrayOfArrays src, InputArray labels); |
||||
|
||||
// Predicts the label of a query image in src.
|
||||
int predict(InputArray src) const; |
||||
|
||||
// Predicts the label and confidence for a given sample.
|
||||
void predict(InputArray _src, int &label, double &dist) const; |
||||
}; |
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Eigenfaces
|
||||
//------------------------------------------------------------------------------
|
||||
void Eigenfaces::train(InputArrayOfArrays _src, InputArray _local_labels) { |
||||
if(_src.total() == 0) { |
||||
String error_message = format("Empty training data was given. You'll need more than one sample to learn a model."); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} else if(_local_labels.getMat().type() != CV_32SC1) { |
||||
String error_message = format("Labels must be given as integer (CV_32SC1). Expected %d, but was %d.", CV_32SC1, _local_labels.type()); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
// make sure data has correct size
|
||||
if(_src.total() > 1) { |
||||
for(int i = 1; i < static_cast<int>(_src.total()); i++) { |
||||
if(_src.getMat(i-1).total() != _src.getMat(i).total()) { |
||||
String error_message = format("In the Eigenfaces method all input samples (training images) must be of equal size! Expected %d pixels, but was %d pixels.", _src.getMat(i-1).total(), _src.getMat(i).total()); |
||||
CV_Error(Error::StsUnsupportedFormat, error_message); |
||||
} |
||||
} |
||||
} |
||||
// get labels
|
||||
Mat labels = _local_labels.getMat(); |
||||
// observations in row
|
||||
Mat data = asRowMatrix(_src, CV_64FC1); |
||||
|
||||
// number of samples
|
||||
int n = data.rows; |
||||
// assert there are as much samples as labels
|
||||
if(static_cast<int>(labels.total()) != n) { |
||||
String error_message = format("The number of samples (src) must equal the number of labels (labels)! len(src)=%d, len(labels)=%d.", n, labels.total()); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
// clear existing model data
|
||||
_labels.release(); |
||||
_projections.clear(); |
||||
// clip number of components to be valid
|
||||
if((_num_components <= 0) || (_num_components > n)) |
||||
_num_components = n; |
||||
|
||||
// perform the PCA
|
||||
PCA pca(data, Mat(), PCA::DATA_AS_ROW, _num_components); |
||||
// copy the PCA results
|
||||
_mean = pca.mean.reshape(1,1); // store the mean vector
|
||||
_eigenvalues = pca.eigenvalues.clone(); // eigenvalues by row
|
||||
transpose(pca.eigenvectors, _eigenvectors); // eigenvectors by column
|
||||
// store labels for prediction
|
||||
_labels = labels.clone(); |
||||
// save projections
|
||||
for(int sampleIdx = 0; sampleIdx < data.rows; sampleIdx++) { |
||||
Mat p = LDA::subspaceProject(_eigenvectors, _mean, data.row(sampleIdx)); |
||||
_projections.push_back(p); |
||||
} |
||||
} |
||||
|
||||
void Eigenfaces::predict(InputArray _src, int &minClass, double &minDist) const { |
||||
// get data
|
||||
Mat src = _src.getMat(); |
||||
// make sure the user is passing correct data
|
||||
if(_projections.empty()) { |
||||
// throw error if no data (or simply return -1?)
|
||||
String error_message = "This Eigenfaces model is not computed yet. Did you call Eigenfaces::train?"; |
||||
CV_Error(Error::StsError, error_message); |
||||
} else if(_eigenvectors.rows != static_cast<int>(src.total())) { |
||||
// check data alignment just for clearer exception messages
|
||||
String error_message = format("Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with %d elements, but got %d.", _eigenvectors.rows, src.total()); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
// project into PCA subspace
|
||||
Mat q = LDA::subspaceProject(_eigenvectors, _mean, src.reshape(1,1)); |
||||
minDist = DBL_MAX; |
||||
minClass = -1; |
||||
for(size_t sampleIdx = 0; sampleIdx < _projections.size(); sampleIdx++) { |
||||
double dist = norm(_projections[sampleIdx], q, NORM_L2); |
||||
if((dist < minDist) && (dist < _threshold)) { |
||||
minDist = dist; |
||||
minClass = _labels.at<int>((int)sampleIdx); |
||||
} |
||||
} |
||||
} |
||||
|
||||
int Eigenfaces::predict(InputArray _src) const { |
||||
int label; |
||||
double dummy; |
||||
predict(_src, label, dummy); |
||||
return label; |
||||
} |
||||
|
||||
Ptr<BasicFaceRecognizer> createEigenFaceRecognizer(int num_components, double threshold) |
||||
{ |
||||
return makePtr<Eigenfaces>(num_components, threshold); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,175 @@ |
||||
#ifndef __OPENCV_FACE_BASIC_HPP |
||||
#define __OPENCV_FACE_BASIC_HPP |
||||
|
||||
#include "opencv2/face.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
#include <set> |
||||
#include <limits> |
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
|
||||
// Reads a sequence from a FileNode::SEQ with type _Tp into a result vector.
|
||||
template<typename _Tp> |
||||
inline void readFileNodeList(const FileNode& fn, std::vector<_Tp>& result) { |
||||
if (fn.type() == FileNode::SEQ) { |
||||
for (FileNodeIterator it = fn.begin(); it != fn.end();) { |
||||
_Tp item; |
||||
it >> item; |
||||
result.push_back(item); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Writes the a list of given items to a cv::FileStorage.
|
||||
template<typename _Tp> |
||||
inline void writeFileNodeList(FileStorage& fs, const String& name, |
||||
const std::vector<_Tp>& items) { |
||||
// typedefs
|
||||
typedef typename std::vector<_Tp>::const_iterator constVecIterator; |
||||
// write the elements in item to fs
|
||||
fs << name << "["; |
||||
for (constVecIterator it = items.begin(); it != items.end(); ++it) { |
||||
fs << *it; |
||||
} |
||||
fs << "]"; |
||||
} |
||||
|
||||
inline Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double beta=0) { |
||||
// make sure the input data is a vector of matrices or vector of vector
|
||||
if(src.kind() != _InputArray::STD_VECTOR_MAT && src.kind() != _InputArray::STD_VECTOR_VECTOR) { |
||||
String error_message = "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< std::vector<...> >)."; |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
// number of samples
|
||||
size_t n = src.total(); |
||||
// return empty matrix if no matrices given
|
||||
if(n == 0) |
||||
return Mat(); |
||||
// dimensionality of (reshaped) samples
|
||||
size_t d = src.getMat(0).total(); |
||||
// create data matrix
|
||||
Mat data((int)n, (int)d, rtype); |
||||
// now copy data
|
||||
for(unsigned int i = 0; i < n; i++) { |
||||
// make sure data can be reshaped, throw exception if not!
|
||||
if(src.getMat(i).total() != d) { |
||||
String error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, d, src.getMat(i).total()); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
// get a hold of the current row
|
||||
Mat xi = data.row(i); |
||||
// make reshape happy by cloning for non-continuous matrices
|
||||
if(src.getMat(i).isContinuous()) { |
||||
src.getMat(i).reshape(1, 1).convertTo(xi, rtype, alpha, beta); |
||||
} else { |
||||
src.getMat(i).clone().reshape(1, 1).convertTo(xi, rtype, alpha, beta); |
||||
} |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
// Utility structure to load/save face label info (a pair of int and string) via FileStorage
|
||||
struct LabelInfo |
||||
{ |
||||
LabelInfo():label(-1), value("") {} |
||||
LabelInfo(int _label, const String &_value): label(_label), value(_value) {} |
||||
int label; |
||||
String value; |
||||
void write(cv::FileStorage& fs) const |
||||
{ |
||||
fs << "{" << "label" << label << "value" << value << "}"; |
||||
} |
||||
void read(const cv::FileNode& node) |
||||
{ |
||||
label = (int)node["label"]; |
||||
value = (String)node["value"]; |
||||
} |
||||
std::ostream& operator<<(std::ostream& out) |
||||
{ |
||||
out << "{ label = " << label << ", " << "value = " << value.c_str() << "}"; |
||||
return out; |
||||
} |
||||
}; |
||||
|
||||
inline void write(cv::FileStorage& fs, const String&, const LabelInfo& x) |
||||
{ |
||||
x.write(fs); |
||||
} |
||||
|
||||
inline void read(const cv::FileNode& node, LabelInfo& x, const LabelInfo& default_value = LabelInfo()) |
||||
{ |
||||
if(node.empty()) |
||||
x = default_value; |
||||
else |
||||
x.read(node); |
||||
} |
||||
|
||||
|
||||
class BasicFaceRecognizerImpl : public cv::face::BasicFaceRecognizer |
||||
{ |
||||
public: |
||||
BasicFaceRecognizerImpl(int num_components = 0, double threshold = DBL_MAX) |
||||
: _num_components(num_components), _threshold(threshold) |
||||
{} |
||||
|
||||
void load(const FileStorage& fs) |
||||
{ |
||||
//read matrices
|
||||
fs["num_components"] >> _num_components; |
||||
fs["mean"] >> _mean; |
||||
fs["eigenvalues"] >> _eigenvalues; |
||||
fs["eigenvectors"] >> _eigenvectors; |
||||
// read sequences
|
||||
readFileNodeList(fs["projections"], _projections); |
||||
fs["labels"] >> _labels; |
||||
const FileNode& fn = fs["labelsInfo"]; |
||||
if (fn.type() == FileNode::SEQ) |
||||
{ |
||||
_labelsInfo.clear(); |
||||
for (FileNodeIterator it = fn.begin(); it != fn.end();) |
||||
{ |
||||
LabelInfo item; |
||||
it >> item; |
||||
_labelsInfo.insert(std::make_pair(item.label, item.value)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void save(FileStorage& fs) const |
||||
{ |
||||
// write matrices
|
||||
fs << "num_components" << _num_components; |
||||
fs << "mean" << _mean; |
||||
fs << "eigenvalues" << _eigenvalues; |
||||
fs << "eigenvectors" << _eigenvectors; |
||||
// write sequences
|
||||
writeFileNodeList(fs, "projections", _projections); |
||||
fs << "labels" << _labels; |
||||
fs << "labelsInfo" << "["; |
||||
for (std::map<int, String>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++) |
||||
fs << LabelInfo(it->first, it->second); |
||||
fs << "]"; |
||||
} |
||||
|
||||
CV_IMPL_PROPERTY(int, NumComponents, _num_components) |
||||
CV_IMPL_PROPERTY(double, Threshold, _threshold) |
||||
CV_IMPL_PROPERTY_RO(std::vector<cv::Mat>, Projections, _projections) |
||||
CV_IMPL_PROPERTY_RO(cv::Mat, Labels, _labels) |
||||
CV_IMPL_PROPERTY_RO(cv::Mat, EigenValues, _eigenvalues) |
||||
CV_IMPL_PROPERTY_RO(cv::Mat, EigenVectors, _eigenvectors) |
||||
CV_IMPL_PROPERTY_RO(cv::Mat, Mean, _mean) |
||||
|
||||
protected: |
||||
int _num_components; |
||||
double _threshold; |
||||
std::vector<Mat> _projections; |
||||
Mat _labels; |
||||
Mat _eigenvectors; |
||||
Mat _eigenvalues; |
||||
Mat _mean; |
||||
}; |
||||
|
||||
#endif // __OPENCV_FACE_BASIC_HPP
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,163 @@ |
||||
/*
|
||||
* Copyright (c) 2011,2012. Philipp Wagner <bytefish[at]gmx[dot]de>. |
||||
* Released to public domain under terms of the BSD Simplified license. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of the organization nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* See <http://www.opensource.org/licenses/bsd-license>
|
||||
*/ |
||||
#include "precomp.hpp" |
||||
#include "face_basic.hpp" |
||||
|
||||
namespace cv { namespace face { |
||||
|
||||
// Belhumeur, P. N., Hespanha, J., and Kriegman, D. "Eigenfaces vs. Fisher-
|
||||
// faces: Recognition using class specific linear projection.". IEEE
|
||||
// Transactions on Pattern Analysis and Machine Intelligence 19, 7 (1997),
|
||||
// 711–720.
|
||||
class Fisherfaces: public BasicFaceRecognizerImpl |
||||
{ |
||||
public: |
||||
// Initializes an empty Fisherfaces model.
|
||||
Fisherfaces(int num_components = 0, double threshold = DBL_MAX) |
||||
: BasicFaceRecognizerImpl(num_components, threshold) |
||||
{ } |
||||
|
||||
// Computes a Fisherfaces model with images in src and corresponding labels
|
||||
// in labels.
|
||||
void train(InputArrayOfArrays src, InputArray labels); |
||||
|
||||
// Predicts the label of a query image in src.
|
||||
int predict(InputArray src) const; |
||||
|
||||
// Predicts the label and confidence for a given sample.
|
||||
void predict(InputArray _src, int &label, double &dist) const; |
||||
}; |
||||
|
||||
// Removes duplicate elements in a given vector.
|
||||
template<typename _Tp> |
||||
inline std::vector<_Tp> remove_dups(const std::vector<_Tp>& src) { |
||||
typedef typename std::set<_Tp>::const_iterator constSetIterator; |
||||
typedef typename std::vector<_Tp>::const_iterator constVecIterator; |
||||
std::set<_Tp> set_elems; |
||||
for (constVecIterator it = src.begin(); it != src.end(); ++it) |
||||
set_elems.insert(*it); |
||||
std::vector<_Tp> elems; |
||||
for (constSetIterator it = set_elems.begin(); it != set_elems.end(); ++it) |
||||
elems.push_back(*it); |
||||
return elems; |
||||
} |
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Fisherfaces
|
||||
//------------------------------------------------------------------------------
|
||||
void Fisherfaces::train(InputArrayOfArrays src, InputArray _lbls) { |
||||
if(src.total() == 0) { |
||||
String error_message = format("Empty training data was given. You'll need more than one sample to learn a model."); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} else if(_lbls.getMat().type() != CV_32SC1) { |
||||
String error_message = format("Labels must be given as integer (CV_32SC1). Expected %d, but was %d.", CV_32SC1, _lbls.type()); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
// make sure data has correct size
|
||||
if(src.total() > 1) { |
||||
for(int i = 1; i < static_cast<int>(src.total()); i++) { |
||||
if(src.getMat(i-1).total() != src.getMat(i).total()) { |
||||
String error_message = format("In the Fisherfaces method all input samples (training images) must be of equal size! Expected %d pixels, but was %d pixels.", src.getMat(i-1).total(), src.getMat(i).total()); |
||||
CV_Error(Error::StsUnsupportedFormat, error_message); |
||||
} |
||||
} |
||||
} |
||||
// get data
|
||||
Mat labels = _lbls.getMat(); |
||||
Mat data = asRowMatrix(src, CV_64FC1); |
||||
// number of samples
|
||||
int N = data.rows; |
||||
// make sure labels are passed in correct shape
|
||||
if(labels.total() != (size_t) N) { |
||||
String error_message = format("The number of samples (src) must equal the number of labels (labels)! len(src)=%d, len(labels)=%d.", N, labels.total()); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} else if(labels.rows != 1 && labels.cols != 1) { |
||||
String error_message = format("Expected the labels in a matrix with one row or column! Given dimensions are rows=%s, cols=%d.", labels.rows, labels.cols); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
// clear existing model data
|
||||
_labels.release(); |
||||
_projections.clear(); |
||||
// safely copy from cv::Mat to std::vector
|
||||
std::vector<int> ll; |
||||
for(unsigned int i = 0; i < labels.total(); i++) { |
||||
ll.push_back(labels.at<int>(i)); |
||||
} |
||||
// get the number of unique classes
|
||||
int C = (int) remove_dups(ll).size(); |
||||
// clip number of components to be a valid number
|
||||
if((_num_components <= 0) || (_num_components > (C-1))) |
||||
_num_components = (C-1); |
||||
// perform a PCA and keep (N-C) components
|
||||
PCA pca(data, Mat(), PCA::DATA_AS_ROW, (N-C)); |
||||
// project the data and perform a LDA on it
|
||||
LDA lda(pca.project(data),labels, _num_components); |
||||
// store the total mean vector
|
||||
_mean = pca.mean.reshape(1,1); |
||||
// store labels
|
||||
_labels = labels.clone(); |
||||
// store the eigenvalues of the discriminants
|
||||
lda.eigenvalues().convertTo(_eigenvalues, CV_64FC1); |
||||
// Now calculate the projection matrix as pca.eigenvectors * lda.eigenvectors.
|
||||
// Note: OpenCV stores the eigenvectors by row, so we need to transpose it!
|
||||
gemm(pca.eigenvectors, lda.eigenvectors(), 1.0, Mat(), 0.0, _eigenvectors, GEMM_1_T); |
||||
// store the projections of the original data
|
||||
for(int sampleIdx = 0; sampleIdx < data.rows; sampleIdx++) { |
||||
Mat p = LDA::subspaceProject(_eigenvectors, _mean, data.row(sampleIdx)); |
||||
_projections.push_back(p); |
||||
} |
||||
} |
||||
|
||||
void Fisherfaces::predict(InputArray _src, int &minClass, double &minDist) const { |
||||
Mat src = _src.getMat(); |
||||
// check data alignment just for clearer exception messages
|
||||
if(_projections.empty()) { |
||||
// throw error if no data (or simply return -1?)
|
||||
String error_message = "This Fisherfaces model is not computed yet. Did you call Fisherfaces::train?"; |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} else if(src.total() != (size_t) _eigenvectors.rows) { |
||||
String error_message = format("Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with %d elements, but got %d.", _eigenvectors.rows, src.total()); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
// project into LDA subspace
|
||||
Mat q = LDA::subspaceProject(_eigenvectors, _mean, src.reshape(1,1)); |
||||
// find 1-nearest neighbor
|
||||
minDist = DBL_MAX; |
||||
minClass = -1; |
||||
for(size_t sampleIdx = 0; sampleIdx < _projections.size(); sampleIdx++) { |
||||
double dist = norm(_projections[sampleIdx], q, NORM_L2); |
||||
if((dist < minDist) && (dist < _threshold)) { |
||||
minDist = dist; |
||||
minClass = _labels.at<int>((int)sampleIdx); |
||||
} |
||||
} |
||||
} |
||||
|
||||
int Fisherfaces::predict(InputArray _src) const { |
||||
int label; |
||||
double dummy; |
||||
predict(_src, label, dummy); |
||||
return label; |
||||
} |
||||
|
||||
Ptr<BasicFaceRecognizer> createFisherFaceRecognizer(int num_components, double threshold) |
||||
{ |
||||
return makePtr<Fisherfaces>(num_components, threshold); |
||||
} |
||||
|
||||
} } |
@ -0,0 +1,430 @@ |
||||
/*
|
||||
* Copyright (c) 2011,2012. Philipp Wagner <bytefish[at]gmx[dot]de>. |
||||
* Released to public domain under terms of the BSD Simplified license. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of the organization nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* See <http://www.opensource.org/licenses/bsd-license>
|
||||
*/ |
||||
#include "precomp.hpp" |
||||
#include "opencv2/face.hpp" |
||||
#include "face_basic.hpp" |
||||
|
||||
namespace cv { namespace face { |
||||
|
||||
// Face Recognition based on Local Binary Patterns.
|
||||
//
|
||||
// Ahonen T, Hadid A. and Pietikäinen M. "Face description with local binary
|
||||
// patterns: Application to face recognition." IEEE Transactions on Pattern
|
||||
// Analysis and Machine Intelligence, 28(12):2037-2041.
|
||||
//
|
||||
class LBPH : public LBPHFaceRecognizer |
||||
{ |
||||
private: |
||||
int _grid_x; |
||||
int _grid_y; |
||||
int _radius; |
||||
int _neighbors; |
||||
double _threshold; |
||||
|
||||
std::vector<Mat> _histograms; |
||||
Mat _labels; |
||||
|
||||
// Computes a LBPH model with images in src and
|
||||
// corresponding labels in labels, possibly preserving
|
||||
// old model data.
|
||||
void train(InputArrayOfArrays src, InputArray labels, bool preserveData); |
||||
|
||||
|
||||
public: |
||||
using FaceRecognizer::save; |
||||
using FaceRecognizer::load; |
||||
|
||||
// Initializes this LBPH Model. The current implementation is rather fixed
|
||||
// as it uses the Extended Local Binary Patterns per default.
|
||||
//
|
||||
// radius, neighbors are used in the local binary patterns creation.
|
||||
// grid_x, grid_y control the grid size of the spatial histograms.
|
||||
LBPH(int radius_=1, int neighbors_=8, |
||||
int gridx=8, int gridy=8, |
||||
double threshold = DBL_MAX) : |
||||
_grid_x(gridx), |
||||
_grid_y(gridy), |
||||
_radius(radius_), |
||||
_neighbors(neighbors_), |
||||
_threshold(threshold) {} |
||||
|
||||
// Initializes and computes this LBPH Model. The current implementation is
|
||||
// rather fixed as it uses the Extended Local Binary Patterns per default.
|
||||
//
|
||||
// (radius=1), (neighbors=8) are used in the local binary patterns creation.
|
||||
// (grid_x=8), (grid_y=8) controls the grid size of the spatial histograms.
|
||||
LBPH(InputArrayOfArrays src, |
||||
InputArray labels, |
||||
int radius_=1, int neighbors_=8, |
||||
int gridx=8, int gridy=8, |
||||
double threshold = DBL_MAX) : |
||||
_grid_x(gridx), |
||||
_grid_y(gridy), |
||||
_radius(radius_), |
||||
_neighbors(neighbors_), |
||||
_threshold(threshold) { |
||||
train(src, labels); |
||||
} |
||||
|
||||
~LBPH() { } |
||||
|
||||
// Computes a LBPH model with images in src and
|
||||
// corresponding labels in labels.
|
||||
void train(InputArrayOfArrays src, InputArray labels); |
||||
|
||||
// Updates this LBPH model with images in src and
|
||||
// corresponding labels in labels.
|
||||
void update(InputArrayOfArrays src, InputArray labels); |
||||
|
||||
// Predicts the label of a query image in src.
|
||||
int predict(InputArray src) const; |
||||
|
||||
// Predicts the label and confidence for a given sample.
|
||||
void predict(InputArray _src, int &label, double &dist) const; |
||||
|
||||
// See FaceRecognizer::load.
|
||||
void load(const FileStorage& fs); |
||||
|
||||
// See FaceRecognizer::save.
|
||||
void save(FileStorage& fs) const; |
||||
|
||||
CV_IMPL_PROPERTY(int, GridX, _grid_x) |
||||
CV_IMPL_PROPERTY(int, GridY, _grid_y) |
||||
CV_IMPL_PROPERTY(int, Radius, _radius) |
||||
CV_IMPL_PROPERTY(int, Neighbors, _neighbors) |
||||
CV_IMPL_PROPERTY(double, Threshold, _threshold) |
||||
CV_IMPL_PROPERTY_RO(std::vector<cv::Mat>, Histograms, _histograms) |
||||
CV_IMPL_PROPERTY_RO(cv::Mat, Labels, _labels) |
||||
}; |
||||
|
||||
|
||||
void LBPH::load(const FileStorage& fs) { |
||||
fs["radius"] >> _radius; |
||||
fs["neighbors"] >> _neighbors; |
||||
fs["grid_x"] >> _grid_x; |
||||
fs["grid_y"] >> _grid_y; |
||||
//read matrices
|
||||
readFileNodeList(fs["histograms"], _histograms); |
||||
fs["labels"] >> _labels; |
||||
const FileNode& fn = fs["labelsInfo"]; |
||||
if (fn.type() == FileNode::SEQ) |
||||
{ |
||||
_labelsInfo.clear(); |
||||
for (FileNodeIterator it = fn.begin(); it != fn.end();) |
||||
{ |
||||
LabelInfo item; |
||||
it >> item; |
||||
_labelsInfo.insert(std::make_pair(item.label, item.value)); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// See FaceRecognizer::save.
|
||||
void LBPH::save(FileStorage& fs) const { |
||||
fs << "radius" << _radius; |
||||
fs << "neighbors" << _neighbors; |
||||
fs << "grid_x" << _grid_x; |
||||
fs << "grid_y" << _grid_y; |
||||
// write matrices
|
||||
writeFileNodeList(fs, "histograms", _histograms); |
||||
fs << "labels" << _labels; |
||||
fs << "labelsInfo" << "["; |
||||
for (std::map<int, String>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++) |
||||
fs << LabelInfo(it->first, it->second); |
||||
fs << "]"; |
||||
} |
||||
|
||||
void LBPH::train(InputArrayOfArrays _in_src, InputArray _in_labels) { |
||||
this->train(_in_src, _in_labels, false); |
||||
} |
||||
|
||||
void LBPH::update(InputArrayOfArrays _in_src, InputArray _in_labels) { |
||||
// got no data, just return
|
||||
if(_in_src.total() == 0) |
||||
return; |
||||
|
||||
this->train(_in_src, _in_labels, true); |
||||
} |
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// LBPH
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template <typename _Tp> static |
||||
void olbp_(InputArray _src, OutputArray _dst) { |
||||
// get matrices
|
||||
Mat src = _src.getMat(); |
||||
// allocate memory for result
|
||||
_dst.create(src.rows-2, src.cols-2, CV_8UC1); |
||||
Mat dst = _dst.getMat(); |
||||
// zero the result matrix
|
||||
dst.setTo(0); |
||||
// calculate patterns
|
||||
for(int i=1;i<src.rows-1;i++) { |
||||
for(int j=1;j<src.cols-1;j++) { |
||||
_Tp center = src.at<_Tp>(i,j); |
||||
unsigned char code = 0; |
||||
code |= (src.at<_Tp>(i-1,j-1) >= center) << 7; |
||||
code |= (src.at<_Tp>(i-1,j) >= center) << 6; |
||||
code |= (src.at<_Tp>(i-1,j+1) >= center) << 5; |
||||
code |= (src.at<_Tp>(i,j+1) >= center) << 4; |
||||
code |= (src.at<_Tp>(i+1,j+1) >= center) << 3; |
||||
code |= (src.at<_Tp>(i+1,j) >= center) << 2; |
||||
code |= (src.at<_Tp>(i+1,j-1) >= center) << 1; |
||||
code |= (src.at<_Tp>(i,j-1) >= center) << 0; |
||||
dst.at<unsigned char>(i-1,j-1) = code; |
||||
} |
||||
} |
||||
} |
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// cv::elbp
|
||||
//------------------------------------------------------------------------------
|
||||
template <typename _Tp> static |
||||
inline void elbp_(InputArray _src, OutputArray _dst, int radius, int neighbors) { |
||||
//get matrices
|
||||
Mat src = _src.getMat(); |
||||
// allocate memory for result
|
||||
_dst.create(src.rows-2*radius, src.cols-2*radius, CV_32SC1); |
||||
Mat dst = _dst.getMat(); |
||||
// zero
|
||||
dst.setTo(0); |
||||
for(int n=0; n<neighbors; n++) { |
||||
// sample points
|
||||
float x = static_cast<float>(radius * cos(2.0*CV_PI*n/static_cast<float>(neighbors))); |
||||
float y = static_cast<float>(-radius * sin(2.0*CV_PI*n/static_cast<float>(neighbors))); |
||||
// relative indices
|
||||
int fx = static_cast<int>(floor(x)); |
||||
int fy = static_cast<int>(floor(y)); |
||||
int cx = static_cast<int>(ceil(x)); |
||||
int cy = static_cast<int>(ceil(y)); |
||||
// fractional part
|
||||
float ty = y - fy; |
||||
float tx = x - fx; |
||||
// set interpolation weights
|
||||
float w1 = (1 - tx) * (1 - ty); |
||||
float w2 = tx * (1 - ty); |
||||
float w3 = (1 - tx) * ty; |
||||
float w4 = tx * ty; |
||||
// iterate through your data
|
||||
for(int i=radius; i < src.rows-radius;i++) { |
||||
for(int j=radius;j < src.cols-radius;j++) { |
||||
// calculate interpolated value
|
||||
float t = static_cast<float>(w1*src.at<_Tp>(i+fy,j+fx) + w2*src.at<_Tp>(i+fy,j+cx) + w3*src.at<_Tp>(i+cy,j+fx) + w4*src.at<_Tp>(i+cy,j+cx)); |
||||
// floating point precision, so check some machine-dependent epsilon
|
||||
dst.at<int>(i-radius,j-radius) += ((t > src.at<_Tp>(i,j)) || (std::abs(t-src.at<_Tp>(i,j)) < std::numeric_limits<float>::epsilon())) << n; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
static void elbp(InputArray src, OutputArray dst, int radius, int neighbors) |
||||
{ |
||||
int type = src.type(); |
||||
switch (type) { |
||||
case CV_8SC1: elbp_<char>(src,dst, radius, neighbors); break; |
||||
case CV_8UC1: elbp_<unsigned char>(src, dst, radius, neighbors); break; |
||||
case CV_16SC1: elbp_<short>(src,dst, radius, neighbors); break; |
||||
case CV_16UC1: elbp_<unsigned short>(src,dst, radius, neighbors); break; |
||||
case CV_32SC1: elbp_<int>(src,dst, radius, neighbors); break; |
||||
case CV_32FC1: elbp_<float>(src,dst, radius, neighbors); break; |
||||
case CV_64FC1: elbp_<double>(src,dst, radius, neighbors); break; |
||||
default: |
||||
String error_msg = format("Using Original Local Binary Patterns for feature extraction only works on single-channel images (given %d). Please pass the image data as a grayscale image!", type); |
||||
CV_Error(Error::StsNotImplemented, error_msg); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
static Mat |
||||
histc_(const Mat& src, int minVal=0, int maxVal=255, bool normed=false) |
||||
{ |
||||
Mat result; |
||||
// Establish the number of bins.
|
||||
int histSize = maxVal-minVal+1; |
||||
// Set the ranges.
|
||||
float range[] = { static_cast<float>(minVal), static_cast<float>(maxVal+1) }; |
||||
const float* histRange = { range }; |
||||
// calc histogram
|
||||
calcHist(&src, 1, 0, Mat(), result, 1, &histSize, &histRange, true, false); |
||||
// normalize
|
||||
if(normed) { |
||||
result /= (int)src.total(); |
||||
} |
||||
return result.reshape(1,1); |
||||
} |
||||
|
||||
static Mat histc(InputArray _src, int minVal, int maxVal, bool normed) |
||||
{ |
||||
Mat src = _src.getMat(); |
||||
switch (src.type()) { |
||||
case CV_8SC1: |
||||
return histc_(Mat_<float>(src), minVal, maxVal, normed); |
||||
break; |
||||
case CV_8UC1: |
||||
return histc_(src, minVal, maxVal, normed); |
||||
break; |
||||
case CV_16SC1: |
||||
return histc_(Mat_<float>(src), minVal, maxVal, normed); |
||||
break; |
||||
case CV_16UC1: |
||||
return histc_(src, minVal, maxVal, normed); |
||||
break; |
||||
case CV_32SC1: |
||||
return histc_(Mat_<float>(src), minVal, maxVal, normed); |
||||
break; |
||||
case CV_32FC1: |
||||
return histc_(src, minVal, maxVal, normed); |
||||
break; |
||||
default: |
||||
CV_Error(Error::StsUnmatchedFormats, "This type is not implemented yet."); break; |
||||
} |
||||
return Mat(); |
||||
} |
||||
|
||||
|
||||
static Mat spatial_histogram(InputArray _src, int numPatterns, |
||||
int grid_x, int grid_y, bool /*normed*/) |
||||
{ |
||||
Mat src = _src.getMat(); |
||||
// calculate LBP patch size
|
||||
int width = src.cols/grid_x; |
||||
int height = src.rows/grid_y; |
||||
// allocate memory for the spatial histogram
|
||||
Mat result = Mat::zeros(grid_x * grid_y, numPatterns, CV_32FC1); |
||||
// return matrix with zeros if no data was given
|
||||
if(src.empty()) |
||||
return result.reshape(1,1); |
||||
// initial result_row
|
||||
int resultRowIdx = 0; |
||||
// iterate through grid
|
||||
for(int i = 0; i < grid_y; i++) { |
||||
for(int j = 0; j < grid_x; j++) { |
||||
Mat src_cell = Mat(src, Range(i*height,(i+1)*height), Range(j*width,(j+1)*width)); |
||||
Mat cell_hist = histc(src_cell, 0, (numPatterns-1), true); |
||||
// copy to the result matrix
|
||||
Mat result_row = result.row(resultRowIdx); |
||||
cell_hist.reshape(1,1).convertTo(result_row, CV_32FC1); |
||||
// increase row count in result matrix
|
||||
resultRowIdx++; |
||||
} |
||||
} |
||||
// return result as reshaped feature vector
|
||||
return result.reshape(1,1); |
||||
} |
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// wrapper to cv::elbp (extended local binary patterns)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static Mat elbp(InputArray src, int radius, int neighbors) { |
||||
Mat dst; |
||||
elbp(src, dst, radius, neighbors); |
||||
return dst; |
||||
} |
||||
|
||||
void LBPH::train(InputArrayOfArrays _in_src, InputArray _in_labels, bool preserveData) { |
||||
if(_in_src.kind() != _InputArray::STD_VECTOR_MAT && _in_src.kind() != _InputArray::STD_VECTOR_VECTOR) { |
||||
String error_message = "The images are expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< std::vector<...> >)."; |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
if(_in_src.total() == 0) { |
||||
String error_message = format("Empty training data was given. You'll need more than one sample to learn a model."); |
||||
CV_Error(Error::StsUnsupportedFormat, error_message); |
||||
} else if(_in_labels.getMat().type() != CV_32SC1) { |
||||
String error_message = format("Labels must be given as integer (CV_32SC1). Expected %d, but was %d.", CV_32SC1, _in_labels.type()); |
||||
CV_Error(Error::StsUnsupportedFormat, error_message); |
||||
} |
||||
// get the vector of matrices
|
||||
std::vector<Mat> src; |
||||
_in_src.getMatVector(src); |
||||
// get the label matrix
|
||||
Mat labels = _in_labels.getMat(); |
||||
// check if data is well- aligned
|
||||
if(labels.total() != src.size()) { |
||||
String error_message = format("The number of samples (src) must equal the number of labels (labels). Was len(samples)=%d, len(labels)=%d.", src.size(), _labels.total()); |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
// if this model should be trained without preserving old data, delete old model data
|
||||
if(!preserveData) { |
||||
_labels.release(); |
||||
_histograms.clear(); |
||||
} |
||||
// append labels to _labels matrix
|
||||
for(size_t labelIdx = 0; labelIdx < labels.total(); labelIdx++) { |
||||
_labels.push_back(labels.at<int>((int)labelIdx)); |
||||
} |
||||
// store the spatial histograms of the original data
|
||||
for(size_t sampleIdx = 0; sampleIdx < src.size(); sampleIdx++) { |
||||
// calculate lbp image
|
||||
Mat lbp_image = elbp(src[sampleIdx], _radius, _neighbors); |
||||
// get spatial histogram from this lbp image
|
||||
Mat p = spatial_histogram( |
||||
lbp_image, /* lbp_image */ |
||||
static_cast<int>(std::pow(2.0, static_cast<double>(_neighbors))), /* number of possible patterns */ |
||||
_grid_x, /* grid size x */ |
||||
_grid_y, /* grid size y */ |
||||
true); |
||||
// add to templates
|
||||
_histograms.push_back(p); |
||||
} |
||||
} |
||||
|
||||
void LBPH::predict(InputArray _src, int &minClass, double &minDist) const { |
||||
if(_histograms.empty()) { |
||||
// throw error if no data (or simply return -1?)
|
||||
String error_message = "This LBPH model is not computed yet. Did you call the train method?"; |
||||
CV_Error(Error::StsBadArg, error_message); |
||||
} |
||||
Mat src = _src.getMat(); |
||||
// get the spatial histogram from input image
|
||||
Mat lbp_image = elbp(src, _radius, _neighbors); |
||||
Mat query = spatial_histogram( |
||||
lbp_image, /* lbp_image */ |
||||
static_cast<int>(std::pow(2.0, static_cast<double>(_neighbors))), /* number of possible patterns */ |
||||
_grid_x, /* grid size x */ |
||||
_grid_y, /* grid size y */ |
||||
true /* normed histograms */); |
||||
// find 1-nearest neighbor
|
||||
minDist = DBL_MAX; |
||||
minClass = -1; |
||||
for(size_t sampleIdx = 0; sampleIdx < _histograms.size(); sampleIdx++) { |
||||
double dist = compareHist(_histograms[sampleIdx], query, HISTCMP_CHISQR_ALT); |
||||
if((dist < minDist) && (dist < _threshold)) { |
||||
minDist = dist; |
||||
minClass = _labels.at<int>((int) sampleIdx); |
||||
} |
||||
} |
||||
} |
||||
|
||||
int LBPH::predict(InputArray _src) const { |
||||
int label; |
||||
double dummy; |
||||
predict(_src, label, dummy); |
||||
return label; |
||||
} |
||||
|
||||
Ptr<LBPHFaceRecognizer> createLBPHFaceRecognizer(int radius, int neighbors, |
||||
int grid_x, int grid_y, double threshold) |
||||
{ |
||||
return makePtr<LBPH>(radius, neighbors, grid_x, grid_y, threshold); |
||||
} |
||||
|
||||
|
||||
}} |
@ -1,64 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, Biagio Montesano, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace line_descriptor |
||||
{ |
||||
|
||||
CV_INIT_ALGORITHM( BinaryDescriptor, "BINARY.DESCRIPTOR", ); |
||||
CV_INIT_ALGORITHM( BinaryDescriptorMatcher, "BINARY.DESCRIPTOR.MATCHER", ); |
||||
CV_INIT_ALGORITHM( LSDDetector, "LSDDETECTOR", ); |
||||
|
||||
bool initModule_line_descriptor( void ) |
||||
{ |
||||
bool all = true; |
||||
all &= !BinaryDescriptor_info_auto.name().empty(); |
||||
all &= !BinaryDescriptorMatcher_info_auto.name().empty(); |
||||
all &= !LSDDetector_info_auto.name().empty(); |
||||
|
||||
return all; |
||||
} |
||||
|
||||
} |
||||
} |
@ -1,119 +0,0 @@ |
||||
/*
|
||||
* Software License Agreement (BSD License) |
||||
* |
||||
* Copyright (c) 2012, Willow Garage, Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following |
||||
* disclaimer in the documentation and/or other materials provided |
||||
* with the distribution. |
||||
* * Neither the name of Willow Garage, Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived |
||||
* from this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||||
* POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <opencv2/core.hpp> |
||||
#include <opencv2/rgbd.hpp> |
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/core/private.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace rgbd |
||||
{ |
||||
CV_INIT_ALGORITHM(DepthCleaner, "RGBD.DepthCleaner", |
||||
obj.info()->addParam(obj, "window_size", obj.window_size_); |
||||
obj.info()->addParam(obj, "depth", obj.depth_); |
||||
obj.info()->addParam(obj, "method", obj.method_)) |
||||
|
||||
CV_INIT_ALGORITHM(RgbdNormals, "RGBD.RgbdNormals", |
||||
obj.info()->addParam(obj, "rows", obj.rows_); |
||||
obj.info()->addParam(obj, "cols", obj.cols_); |
||||
obj.info()->addParam(obj, "window_size", obj.window_size_); |
||||
obj.info()->addParam(obj, "depth", obj.depth_); |
||||
obj.info()->addParam(obj, "K", obj.K_); |
||||
obj.info()->addParam(obj, "method", obj.method_)) |
||||
|
||||
CV_INIT_ALGORITHM(RgbdPlane, "RGBD.RgbdPlane", |
||||
obj.info()->addParam(obj, "block_size", obj.block_size_); |
||||
obj.info()->addParam(obj, "min_size", obj.min_size_); |
||||
obj.info()->addParam(obj, "method", obj.method_); |
||||
obj.info()->addParam(obj, "threshold", obj.threshold_); |
||||
obj.info()->addParam(obj, "sensor_error_a", obj.sensor_error_a_); |
||||
obj.info()->addParam(obj, "sensor_error_b", obj.sensor_error_b_); |
||||
obj.info()->addParam(obj, "sensor_error_c", obj.sensor_error_c_)) |
||||
|
||||
CV_INIT_ALGORITHM(RgbdOdometry, "RGBD.RgbdOdometry", |
||||
obj.info()->addParam(obj, "cameraMatrix", obj.cameraMatrix); |
||||
obj.info()->addParam(obj, "minDepth", obj.minDepth); |
||||
obj.info()->addParam(obj, "maxDepth", obj.maxDepth); |
||||
obj.info()->addParam(obj, "maxDepthDiff", obj.maxDepthDiff); |
||||
obj.info()->addParam(obj, "iterCounts", obj.iterCounts); |
||||
obj.info()->addParam(obj, "minGradientMagnitudes", obj.minGradientMagnitudes); |
||||
obj.info()->addParam(obj, "maxPointsPart", obj.maxPointsPart); |
||||
obj.info()->addParam(obj, "transformType", obj.transformType); |
||||
obj.info()->addParam(obj, "maxTranslation", obj.maxTranslation); |
||||
obj.info()->addParam(obj, "maxRotation", obj.maxRotation);) |
||||
|
||||
CV_INIT_ALGORITHM(ICPOdometry, "RGBD.ICPOdometry", |
||||
obj.info()->addParam(obj, "cameraMatrix", obj.cameraMatrix); |
||||
obj.info()->addParam(obj, "minDepth", obj.minDepth); |
||||
obj.info()->addParam(obj, "maxDepth", obj.maxDepth); |
||||
obj.info()->addParam(obj, "maxDepthDiff", obj.maxDepthDiff); |
||||
obj.info()->addParam(obj, "maxPointsPart", obj.maxPointsPart); |
||||
obj.info()->addParam(obj, "iterCounts", obj.iterCounts); |
||||
obj.info()->addParam(obj, "transformType", obj.transformType); |
||||
obj.info()->addParam(obj, "maxTranslation", obj.maxTranslation); |
||||
obj.info()->addParam(obj, "maxRotation", obj.maxRotation); |
||||
obj.info()->addParam<RgbdNormals>(obj, "normalsComputer", obj.normalsComputer, true, NULL, NULL);) |
||||
|
||||
CV_INIT_ALGORITHM(RgbdICPOdometry, "RGBD.RgbdICPOdometry", |
||||
obj.info()->addParam(obj, "cameraMatrix", obj.cameraMatrix); |
||||
obj.info()->addParam(obj, "minDepth", obj.minDepth); |
||||
obj.info()->addParam(obj, "maxDepth", obj.maxDepth); |
||||
obj.info()->addParam(obj, "maxDepthDiff", obj.maxDepthDiff); |
||||
obj.info()->addParam(obj, "maxPointsPart", obj.maxPointsPart); |
||||
obj.info()->addParam(obj, "iterCounts", obj.iterCounts); |
||||
obj.info()->addParam(obj, "minGradientMagnitudes", obj.minGradientMagnitudes); |
||||
obj.info()->addParam(obj, "transformType", obj.transformType); |
||||
obj.info()->addParam(obj, "maxTranslation", obj.maxTranslation); |
||||
obj.info()->addParam(obj, "maxRotation", obj.maxRotation); |
||||
obj.info()->addParam<RgbdNormals>(obj, "normalsComputer", obj.normalsComputer, true, NULL, NULL);) |
||||
|
||||
bool |
||||
initModule_rgbd(void); |
||||
bool |
||||
initModule_rgbd(void) |
||||
{ |
||||
bool all = true; |
||||
all &= !RgbdNormals_info_auto.name().empty(); |
||||
all &= !RgbdPlane_info_auto.name().empty(); |
||||
all &= !RgbdOdometry_info_auto.name().empty(); |
||||
all &= !ICPOdometry_info_auto.name().empty(); |
||||
all &= !RgbdICPOdometry_info_auto.name().empty(); |
||||
return all; |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,73 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2014, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include "opencv2/saliency.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace saliency |
||||
{ |
||||
|
||||
CV_INIT_ALGORITHM( StaticSaliencySpectralResidual, "SALIENCY.SPECTRAL_RESIDUAL", |
||||
obj.info()->addParam( obj, "resImWidth", obj.resImWidth); obj.info()->addParam( obj, "resImHeight", obj.resImHeight) ); |
||||
|
||||
|
||||
CV_INIT_ALGORITHM( |
||||
ObjectnessBING, "SALIENCY.BING", |
||||
obj.info()->addParam(obj, "_base", obj._base); obj.info()->addParam(obj, "_NSS", obj._NSS); obj.info()->addParam(obj, "_W", obj._W) ); |
||||
|
||||
CV_INIT_ALGORITHM( MotionSaliencyBinWangApr2014, "SALIENCY.BinWangApr2014", |
||||
obj.info()->addParam( obj, "imageWidth", obj.imageWidth); obj.info()->addParam( obj, "imageHeight", obj.imageHeight) ); |
||||
|
||||
bool initModule_saliency( void ) |
||||
{ |
||||
bool all = true; |
||||
all &= !StaticSaliencySpectralResidual_info_auto.name().empty(); |
||||
//all &= !MotionSaliencySuBSENSE_info_auto.name().empty();
|
||||
all &= !MotionSaliencyBinWangApr2014_info_auto.name().empty(); |
||||
all &= !ObjectnessBING_info_auto.name().empty(); |
||||
|
||||
return all; |
||||
} |
||||
|
||||
} // namespace saliency
|
||||
} // namespace cv
|
@ -1,53 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include "opencv2/tracking.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
|
||||
bool initModule_tracking(void) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue