mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge remote-tracking branch 'upstream/master' into svm_hog
This commit is contained in:
@@ -318,4 +318,3 @@ decision tree.
|
||||
|
||||
|
||||
.. [Breiman84] Breiman, L., Friedman, J. Olshen, R. and Stone, C. (1984), *Classification and Regression Trees*, Wadsworth.
|
||||
|
||||
|
||||
@@ -11,6 +11,12 @@ CvKNearest
|
||||
|
||||
The class implements K-Nearest Neighbors model as described in the beginning of this section.
|
||||
|
||||
.. note::
|
||||
|
||||
* (Python) An example of digit recognition using KNearest can be found at opencv_source/samples/python2/digits.py
|
||||
* (Python) An example of grid search digit recognition using KNearest can be found at opencv_source/samples/python2/digits_adjust.py
|
||||
* (Python) An example of video digit recognition using KNearest can be found at opencv_source/samples/python2/digits_video.py
|
||||
|
||||
CvKNearest::CvKNearest
|
||||
----------------------
|
||||
Default and training constructors.
|
||||
@@ -188,5 +194,3 @@ The sample below (currently using the obsolete ``CvMat`` structures) demonstrate
|
||||
cvReleaseMat( &trainData );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -278,4 +278,3 @@ Returns neurons weights of the particular layer.
|
||||
.. ocv:function:: double* CvANN_MLP::get_weights(int layer)
|
||||
|
||||
:param layer: Index of the particular layer.
|
||||
|
||||
|
||||
@@ -161,4 +161,3 @@ Predicts the response for a sample.
|
||||
The method is used to predict the response for a new sample. In case of a classification, the method returns the class label. In case of a regression, the method returns the output function value. The input sample must have as many components as the ``train_data`` passed to ``train`` contains. If the ``var_idx`` parameter is passed to ``train``, it is remembered and then is used to extract only the necessary components from the input sample in the method ``predict``.
|
||||
|
||||
The suffix ``const`` means that prediction does not affect the internal model state, so the method can be safely called from within different threads.
|
||||
|
||||
|
||||
@@ -158,6 +158,12 @@ CvSVM
|
||||
|
||||
Support Vector Machines.
|
||||
|
||||
.. note::
|
||||
|
||||
* (Python) An example of digit recognition using SVM can be found at opencv_source/samples/python2/digits.py
|
||||
* (Python) An example of grid search digit recognition using SVM can be found at opencv_source/samples/python2/digits_adjust.py
|
||||
* (Python) An example of video digit recognition using SVM can be found at opencv_source/samples/python2/digits_video.py
|
||||
|
||||
CvSVM::CvSVM
|
||||
------------
|
||||
Default and training constructors.
|
||||
|
||||
@@ -944,6 +944,8 @@ protected:
|
||||
CvDTreeNode* root;
|
||||
CvMat* var_importance;
|
||||
CvDTreeTrainData* data;
|
||||
CvMat train_data_hdr, responses_hdr;
|
||||
cv::Mat train_data_mat, responses_mat;
|
||||
|
||||
public:
|
||||
int pruned_tree_idx;
|
||||
@@ -1055,6 +1057,8 @@ protected:
|
||||
// array of the trees of the forest
|
||||
CvForestTree** trees;
|
||||
CvDTreeTrainData* data;
|
||||
CvMat train_data_hdr, responses_hdr;
|
||||
cv::Mat train_data_mat, responses_mat;
|
||||
int ntrees;
|
||||
int nclasses;
|
||||
double oob_error;
|
||||
@@ -1270,6 +1274,8 @@ protected:
|
||||
virtual void initialize_weights(double (&p)[2]);
|
||||
|
||||
CvDTreeTrainData* data;
|
||||
CvMat train_data_hdr, responses_hdr;
|
||||
cv::Mat train_data_mat, responses_mat;
|
||||
CvBoostParams params;
|
||||
CvSeq* weak;
|
||||
|
||||
@@ -2144,7 +2150,7 @@ typedef CvANN_MLP NeuralNet_MLP;
|
||||
typedef CvGBTreesParams GradientBoostingTreeParams;
|
||||
typedef CvGBTrees GradientBoostingTrees;
|
||||
|
||||
template<> CV_EXPORTS void Ptr<CvDTreeSplit>::delete_obj();
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvDTreeSplit>::operator ()(CvDTreeSplit* obj) const;
|
||||
|
||||
CV_EXPORTS bool initModule_ml(void);
|
||||
}
|
||||
|
||||
@@ -45,4 +45,4 @@
|
||||
#error this is a compatibility header which should not be used inside the OpenCV library
|
||||
#endif
|
||||
|
||||
#include "opencv2/ml.hpp"
|
||||
#include "opencv2/ml.hpp"
|
||||
|
||||
@@ -2122,9 +2122,14 @@ CvBoost::train( const Mat& _train_data, int _tflag,
|
||||
const Mat& _missing_mask,
|
||||
CvBoostParams _params, bool _update )
|
||||
{
|
||||
CvMat tdata = _train_data, responses = _responses, vidx = _var_idx,
|
||||
sidx = _sample_idx, vtype = _var_type, mmask = _missing_mask;
|
||||
return train(&tdata, _tflag, &responses, vidx.data.ptr ? &vidx : 0,
|
||||
train_data_hdr = _train_data;
|
||||
train_data_mat = _train_data;
|
||||
responses_hdr = _responses;
|
||||
responses_mat = _responses;
|
||||
|
||||
CvMat vidx = _var_idx, sidx = _sample_idx, vtype = _var_type, mmask = _missing_mask;
|
||||
|
||||
return train(&train_data_hdr, _tflag, &responses_hdr, vidx.data.ptr ? &vidx : 0,
|
||||
sidx.data.ptr ? &sidx : 0, vtype.data.ptr ? &vtype : 0,
|
||||
mmask.data.ptr ? &mmask : 0, _params, _update);
|
||||
}
|
||||
|
||||
@@ -1844,12 +1844,16 @@ bool CvERTrees::train( const Mat& _train_data, int _tflag,
|
||||
const Mat& _sample_idx, const Mat& _var_type,
|
||||
const Mat& _missing_mask, CvRTParams params )
|
||||
{
|
||||
CvMat tdata = _train_data, responses = _responses, vidx = _var_idx,
|
||||
sidx = _sample_idx, vtype = _var_type, mmask = _missing_mask;
|
||||
return train(&tdata, _tflag, &responses, vidx.data.ptr ? &vidx : 0,
|
||||
train_data_hdr = _train_data;
|
||||
train_data_mat = _train_data;
|
||||
responses_hdr = _responses;
|
||||
responses_mat = _responses;
|
||||
|
||||
CvMat vidx = _var_idx, sidx = _sample_idx, vtype = _var_type, mmask = _missing_mask;
|
||||
|
||||
return train(&train_data_hdr, _tflag, &responses_hdr, vidx.data.ptr ? &vidx : 0,
|
||||
sidx.data.ptr ? &sidx : 0, vtype.data.ptr ? &vtype : 0,
|
||||
mmask.data.ptr ? &mmask : 0, params);
|
||||
}
|
||||
|
||||
// End of file.
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ bool CvKNearest::train( const CvMat* _train_data, const CvMat* _responses,
|
||||
|
||||
if( !responses )
|
||||
CV_ERROR( CV_StsNoMem, "Could not allocate memory for responses" );
|
||||
|
||||
|
||||
if( _update_base && _dims != var_count )
|
||||
CV_ERROR( CV_StsBadArg, "The newly added data have different dimensionality" );
|
||||
|
||||
@@ -480,4 +480,3 @@ float CvKNearest::find_nearest( const cv::Mat& _samples, int k, CV_OUT cv::Mat&
|
||||
}
|
||||
|
||||
/* End of file */
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ CV_INIT_ALGORITHM(EM, "StatModel.EM",
|
||||
|
||||
bool initModule_ml(void)
|
||||
{
|
||||
Ptr<Algorithm> em = createEM_hidden();
|
||||
Ptr<Algorithm> em = createEM_ptr_hidden();
|
||||
return em->info() != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -210,6 +210,8 @@ bool CvNormalBayesClassifier::train( const CvMat* _train_data, const CvMat* _res
|
||||
prod_data[c2] += train_vec[c2]*val1;
|
||||
}
|
||||
}
|
||||
cvReleaseMat( &responses );
|
||||
responses = 0;
|
||||
|
||||
/* calculate avg, covariance matrix, c */
|
||||
for( cls = 0; cls < nclasses; cls++ )
|
||||
@@ -623,4 +625,3 @@ float CvNormalBayesClassifier::predict( const Mat& _samples, Mat* _results ) con
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
||||
|
||||
@@ -1,45 +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) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., 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"
|
||||
|
||||
/* End of file. */
|
||||
@@ -41,7 +41,6 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/ml.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
|
||||
@@ -126,7 +126,7 @@ void ForestTreeBestSplitFinder::operator()(const BlockedRange& range)
|
||||
}
|
||||
|
||||
if( res && bestSplit->quality < split->quality )
|
||||
memcpy( (CvDTreeSplit*)bestSplit, (CvDTreeSplit*)split, splitSize );
|
||||
memcpy( bestSplit.get(), split.get(), splitSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -839,9 +839,14 @@ bool CvRTrees::train( const Mat& _train_data, int _tflag,
|
||||
const Mat& _sample_idx, const Mat& _var_type,
|
||||
const Mat& _missing_mask, CvRTParams _params )
|
||||
{
|
||||
CvMat tdata = _train_data, responses = _responses, vidx = _var_idx,
|
||||
sidx = _sample_idx, vtype = _var_type, mmask = _missing_mask;
|
||||
return train(&tdata, _tflag, &responses, vidx.data.ptr ? &vidx : 0,
|
||||
train_data_hdr = _train_data;
|
||||
train_data_mat = _train_data;
|
||||
responses_hdr = _responses;
|
||||
responses_mat = _responses;
|
||||
|
||||
CvMat vidx = _var_idx, sidx = _sample_idx, vtype = _var_type, mmask = _missing_mask;
|
||||
|
||||
return train(&train_data_hdr, _tflag, &responses_hdr, vidx.data.ptr ? &vidx : 0,
|
||||
sidx.data.ptr ? &sidx : 0, vtype.data.ptr ? &vtype : 0,
|
||||
mmask.data.ptr ? &mmask : 0, _params);
|
||||
}
|
||||
|
||||
@@ -1391,6 +1391,8 @@ bool CvSVM::do_train( int svm_type, int sample_count, int var_count, const float
|
||||
for( i = 0; i < sample_count; i++ )
|
||||
sv_count += fabs(alpha[i]) > 0;
|
||||
|
||||
CV_Assert(sv_count != 0);
|
||||
|
||||
sv_total = df->sv_count = sv_count;
|
||||
CV_CALL( df->alpha = (double*)cvMemStorageAlloc( storage, sv_count*sizeof(df->alpha[0])) );
|
||||
CV_CALL( sv = (float**)cvMemStorageAlloc( storage, sv_count*sizeof(sv[0])));
|
||||
@@ -2997,4 +2999,3 @@ cvTrainSVM_CrossValidation( const CvMat* train_data, int tflag,
|
||||
#endif
|
||||
|
||||
/* End of file. */
|
||||
|
||||
|
||||
+19
-14
@@ -1594,9 +1594,14 @@ bool CvDTree::train( const Mat& _train_data, int _tflag,
|
||||
const Mat& _sample_idx, const Mat& _var_type,
|
||||
const Mat& _missing_mask, CvDTreeParams _params )
|
||||
{
|
||||
CvMat tdata = _train_data, responses = _responses, vidx=_var_idx,
|
||||
sidx=_sample_idx, vtype=_var_type, mmask=_missing_mask;
|
||||
return train(&tdata, _tflag, &responses, vidx.data.ptr ? &vidx : 0, sidx.data.ptr ? &sidx : 0,
|
||||
train_data_hdr = _train_data;
|
||||
train_data_mat = _train_data;
|
||||
responses_hdr = _responses;
|
||||
responses_mat = _responses;
|
||||
|
||||
CvMat vidx=_var_idx, sidx=_sample_idx, vtype=_var_type, mmask=_missing_mask;
|
||||
|
||||
return train(&train_data_hdr, _tflag, &responses_hdr, vidx.data.ptr ? &vidx : 0, sidx.data.ptr ? &sidx : 0,
|
||||
vtype.data.ptr ? &vtype : 0, mmask.data.ptr ? &mmask : 0, _params);
|
||||
}
|
||||
|
||||
@@ -1877,7 +1882,7 @@ double CvDTree::calc_node_dir( CvDTreeNode* node )
|
||||
namespace cv
|
||||
{
|
||||
|
||||
template<> CV_EXPORTS void Ptr<CvDTreeSplit>::delete_obj()
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvDTreeSplit>::operator ()(CvDTreeSplit* obj) const
|
||||
{
|
||||
fastFree(obj);
|
||||
}
|
||||
@@ -1888,12 +1893,12 @@ DTreeBestSplitFinder::DTreeBestSplitFinder( CvDTree* _tree, CvDTreeNode* _node)
|
||||
node = _node;
|
||||
splitSize = tree->get_data()->split_heap->elem_size;
|
||||
|
||||
bestSplit = (CvDTreeSplit*)fastMalloc(splitSize);
|
||||
memset((CvDTreeSplit*)bestSplit, 0, splitSize);
|
||||
bestSplit.reset((CvDTreeSplit*)fastMalloc(splitSize));
|
||||
memset(bestSplit.get(), 0, splitSize);
|
||||
bestSplit->quality = -1;
|
||||
bestSplit->condensed_idx = INT_MIN;
|
||||
split = (CvDTreeSplit*)fastMalloc(splitSize);
|
||||
memset((CvDTreeSplit*)split, 0, splitSize);
|
||||
split.reset((CvDTreeSplit*)fastMalloc(splitSize));
|
||||
memset(split.get(), 0, splitSize);
|
||||
//haveSplit = false;
|
||||
}
|
||||
|
||||
@@ -1903,10 +1908,10 @@ DTreeBestSplitFinder::DTreeBestSplitFinder( const DTreeBestSplitFinder& finder,
|
||||
node = finder.node;
|
||||
splitSize = tree->get_data()->split_heap->elem_size;
|
||||
|
||||
bestSplit = (CvDTreeSplit*)fastMalloc(splitSize);
|
||||
memcpy((CvDTreeSplit*)(bestSplit), (const CvDTreeSplit*)finder.bestSplit, splitSize);
|
||||
split = (CvDTreeSplit*)fastMalloc(splitSize);
|
||||
memset((CvDTreeSplit*)split, 0, splitSize);
|
||||
bestSplit.reset((CvDTreeSplit*)fastMalloc(splitSize));
|
||||
memcpy(bestSplit.get(), finder.bestSplit.get(), splitSize);
|
||||
split.reset((CvDTreeSplit*)fastMalloc(splitSize));
|
||||
memset(split.get(), 0, splitSize);
|
||||
}
|
||||
|
||||
void DTreeBestSplitFinder::operator()(const BlockedRange& range)
|
||||
@@ -1939,14 +1944,14 @@ void DTreeBestSplitFinder::operator()(const BlockedRange& range)
|
||||
}
|
||||
|
||||
if( res && bestSplit->quality < split->quality )
|
||||
memcpy( (CvDTreeSplit*)bestSplit, (CvDTreeSplit*)split, splitSize );
|
||||
memcpy( bestSplit.get(), split.get(), splitSize );
|
||||
}
|
||||
}
|
||||
|
||||
void DTreeBestSplitFinder::join( DTreeBestSplitFinder& rhs )
|
||||
{
|
||||
if( bestSplit->quality < rhs.bestSplit->quality )
|
||||
memcpy( (CvDTreeSplit*)bestSplit, (CvDTreeSplit*)rhs.bestSplit, splitSize );
|
||||
memcpy( bestSplit.get(), rhs.bestSplit.get(), splitSize );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -678,4 +678,3 @@ TEST(ML_KNearest, accuracy) { CV_KNearestTest test; test.safe_run(); }
|
||||
TEST(ML_EM, accuracy) { CV_EMTest test; test.safe_run(); }
|
||||
TEST(ML_EM, save_load) { CV_EMTest_SaveLoad test; test.safe_run(); }
|
||||
TEST(ML_EM, classification) { CV_EMTest_Classification test; test.safe_run(); }
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
#include "test_precomp.hpp"
|
||||
Reference in New Issue
Block a user