Commit a4ceb7b6 authored by Mathieu Barnachon's avatar Mathieu Barnachon

Fix compilation issues.

parent 0934344a
...@@ -10,6 +10,15 @@ ...@@ -10,6 +10,15 @@
using namespace cv; using namespace cv;
using namespace std; 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<float>& 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 ) 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 ) ...@@ -20,7 +29,9 @@ void get_svm_detector(const SVM& svm, vector< float > & hog_detector )
// get the decision function // get the decision function
const CvSVMDecisionFunc* decision_func = svm.get_decision_function(); const CvSVMDecisionFunc* decision_func = svm.get_decision_function();
// get the support vectors // 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 && CV_Assert( var_all > 0 &&
sv_total > 0 && sv_total > 0 &&
...@@ -50,6 +61,8 @@ void get_svm_detector(const SVM& svm, vector< float > & hog_detector ) ...@@ -50,6 +61,8 @@ void get_svm_detector(const SVM& svm, vector< float > & hog_detector )
hog_detector.push_back( svi ); hog_detector.push_back( svi );
} }
hog_detector.push_back( (float)-decision_func->rho ); 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 ...@@ -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 ); 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 cv::Mat tmp(1, cols, CV_32FC1); //< used for transposition if needed
trainData = cv::Mat(rows, cols, CV_32FC1 ); trainData = cv::Mat(rows, cols, CV_32FC1 );
auto& itr = train_samples.begin(); vector< Mat >::const_iterator itr = train_samples.begin();
auto& end = train_samples.end(); vector< Mat >::const_iterator end = train_samples.end();
for( int i = 0 ; itr != end ; ++itr, ++i ) for( int i = 0 ; itr != end ; ++itr, ++i )
{ {
CV_Assert( itr->cols == 1 || CV_Assert( itr->cols == 1 ||
...@@ -122,8 +135,8 @@ void sample_neg( const vector< Mat > & full_neg_lst, vector< Mat > & neg_lst, co ...@@ -122,8 +135,8 @@ void sample_neg( const vector< Mat > & full_neg_lst, vector< Mat > & neg_lst, co
srand( time( NULL ) ); srand( time( NULL ) );
auto& img = full_neg_lst.begin(); vector< Mat >::const_iterator img = full_neg_lst.begin();
auto& end = full_neg_lst.end(); vector< Mat >::const_iterator end = full_neg_lst.end();
for( ; img != end ; ++img ) for( ; img != end ; ++img )
{ {
box.x = rand() % (img->cols - size_x); box.x = rand() % (img->cols - size_x);
...@@ -221,9 +234,9 @@ Mat get_hogdescriptor_visu(Mat& color_origImg, vector<float>& descriptorValues, ...@@ -221,9 +234,9 @@ Mat get_hogdescriptor_visu(Mat& color_origImg, vector<float>& descriptorValues,
// compute average gradient strengths // compute average gradient strengths
for (int celly=0; celly<cells_in_y_dir; celly++) for (celly=0; celly<cells_in_y_dir; celly++)
{ {
for (int cellx=0; cellx<cells_in_x_dir; cellx++) for (cellx=0; cellx<cells_in_x_dir; cellx++)
{ {
float NrUpdatesForThisCell = (float)cellUpdateCounter[celly][cellx]; float NrUpdatesForThisCell = (float)cellUpdateCounter[celly][cellx];
...@@ -237,9 +250,9 @@ Mat get_hogdescriptor_visu(Mat& color_origImg, vector<float>& descriptorValues, ...@@ -237,9 +250,9 @@ Mat get_hogdescriptor_visu(Mat& color_origImg, vector<float>& descriptorValues,
} }
// draw cells // draw cells
for (int celly=0; celly<cells_in_y_dir; celly++) for (celly=0; celly<cells_in_y_dir; celly++)
{ {
for (int cellx=0; cellx<cells_in_x_dir; cellx++) for (cellx=0; cellx<cells_in_x_dir; cellx++)
{ {
int drawX = cellx * cellSize; int drawX = cellx * cellSize;
int drawY = celly * cellSize; int drawY = celly * cellSize;
...@@ -305,8 +318,8 @@ void compute_hog( const vector< Mat > & img_lst, vector< Mat > & gradient_lst, c ...@@ -305,8 +318,8 @@ void compute_hog( const vector< Mat > & img_lst, vector< Mat > & gradient_lst, c
vector< Point > location; vector< Point > location;
vector< float > descriptors; vector< float > descriptors;
auto& img = img_lst.begin(); vector< Mat >::const_iterator img = img_lst.begin();
auto& end = img_lst.end(); vector< Mat >::const_iterator end = img_lst.end();
for( ; img != end ; ++img ) for( ; img != end ; ++img )
{ {
cvtColor( *img, gray, COLOR_BGR2GRAY ); cvtColor( *img, gray, COLOR_BGR2GRAY );
...@@ -349,8 +362,8 @@ void draw_locations( Mat & img, const vector< Rect > & locations, const Scalar & ...@@ -349,8 +362,8 @@ void draw_locations( Mat & img, const vector< Rect > & locations, const Scalar &
{ {
if( !locations.empty() ) if( !locations.empty() )
{ {
auto& loc = locations.begin(); vector< Rect >::const_iterator loc = locations.begin();
auto& end = locations.end(); vector< Rect >::const_iterator end = locations.end();
for( ; loc != end ; ++loc ) for( ; loc != end ; ++loc )
{ {
rectangle( img, *loc, color, 2 ); rectangle( img, *loc, color, 2 );
...@@ -364,7 +377,7 @@ void test_it( const Size & size ) ...@@ -364,7 +377,7 @@ void test_it( const Size & size )
Scalar reference( 0, 255, 0 ); Scalar reference( 0, 255, 0 );
Scalar trained( 0, 0, 255 ); Scalar trained( 0, 0, 255 );
Mat img, draw; Mat img, draw;
MySVM svm; SVM svm;
HOGDescriptor hog; HOGDescriptor hog;
HOGDescriptor my_hog; HOGDescriptor my_hog;
my_hog.winSize = size; my_hog.winSize = size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment