From a4ceb7b6ee9aa7c9507195de34ed3a67ff014ace Mon Sep 17 00:00:00 2001 From: Mathieu Barnachon Date: Mon, 11 Nov 2013 19:29:39 +0100 Subject: [PATCH] Fix compilation issues. --- samples/cpp/train_HOG.cpp | 41 ++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/samples/cpp/train_HOG.cpp b/samples/cpp/train_HOG.cpp index ae2d1963bf..2cc15db115 100644 --- a/samples/cpp/train_HOG.cpp +++ b/samples/cpp/train_HOG.cpp @@ -10,6 +10,15 @@ using namespace cv; using namespace std; +void get_svm_detector(const SVM& svm, vector< float > & hog_detector ); +void convert_to_ml(const std::vector< cv::Mat > & train_samples, cv::Mat& trainData ); +void load_images( const string & prefix, const string & filename, vector< Mat > & img_lst ); +void sample_neg( const vector< Mat > & full_neg_lst, vector< Mat > & neg_lst, const Size & size ); +Mat get_hogdescriptor_visu(Mat& color_origImg, vector& descriptorValues, const Size & size ); +void compute_hog( const vector< Mat > & img_lst, vector< Mat > & gradient_lst, const Size & size ); +void train_svm( const vector< Mat > & gradient_lst, const vector< int > & labels ); +void draw_locations( Mat & img, const vector< Rect > & locations, const Scalar & color ); +void test_it( const Size & size ); void get_svm_detector(const SVM& svm, vector< float > & hog_detector ) { @@ -20,7 +29,9 @@ void get_svm_detector(const SVM& svm, vector< float > & hog_detector ) // get the decision function const CvSVMDecisionFunc* decision_func = svm.get_decision_function(); // get the support vectors - const float** sv = &(svm.get_support_vector(0)); + const float** sv = new const float*[ sv_total ]; + for( int i = 0 ; i < sv_total ; ++i ) + sv[ i ] = svm.get_support_vector(i); CV_Assert( var_all > 0 && sv_total > 0 && @@ -50,6 +61,8 @@ void get_svm_detector(const SVM& svm, vector< float > & hog_detector ) hog_detector.push_back( svi ); } hog_detector.push_back( (float)-decision_func->rho ); + + delete[] sv; } @@ -65,8 +78,8 @@ void convert_to_ml(const std::vector< cv::Mat > & train_samples, cv::Mat& trainD const int cols = (int)std::max( train_samples[0].cols, train_samples[0].rows ); cv::Mat tmp(1, cols, CV_32FC1); //< used for transposition if needed trainData = cv::Mat(rows, cols, CV_32FC1 ); - auto& itr = train_samples.begin(); - auto& end = train_samples.end(); + vector< Mat >::const_iterator itr = train_samples.begin(); + vector< Mat >::const_iterator end = train_samples.end(); for( int i = 0 ; itr != end ; ++itr, ++i ) { CV_Assert( itr->cols == 1 || @@ -122,8 +135,8 @@ void sample_neg( const vector< Mat > & full_neg_lst, vector< Mat > & neg_lst, co srand( time( NULL ) ); - auto& img = full_neg_lst.begin(); - auto& end = full_neg_lst.end(); + vector< Mat >::const_iterator img = full_neg_lst.begin(); + vector< Mat >::const_iterator end = full_neg_lst.end(); for( ; img != end ; ++img ) { box.x = rand() % (img->cols - size_x); @@ -221,9 +234,9 @@ Mat get_hogdescriptor_visu(Mat& color_origImg, vector& descriptorValues, // compute average gradient strengths - for (int celly=0; celly& descriptorValues, } // draw cells - for (int celly=0; celly & img_lst, vector< Mat > & gradient_lst, c vector< Point > location; vector< float > descriptors; - auto& img = img_lst.begin(); - auto& end = img_lst.end(); + vector< Mat >::const_iterator img = img_lst.begin(); + vector< Mat >::const_iterator end = img_lst.end(); for( ; img != end ; ++img ) { cvtColor( *img, gray, COLOR_BGR2GRAY ); @@ -349,8 +362,8 @@ void draw_locations( Mat & img, const vector< Rect > & locations, const Scalar & { if( !locations.empty() ) { - auto& loc = locations.begin(); - auto& end = locations.end(); + vector< Rect >::const_iterator loc = locations.begin(); + vector< Rect >::const_iterator end = locations.end(); for( ; loc != end ; ++loc ) { rectangle( img, *loc, color, 2 ); @@ -364,7 +377,7 @@ void test_it( const Size & size ) Scalar reference( 0, 255, 0 ); Scalar trained( 0, 0, 255 ); Mat img, draw; - MySVM svm; + SVM svm; HOGDescriptor hog; HOGDescriptor my_hog; my_hog.winSize = size;