@@ -74,9 +74,9 @@ void load_images( const String & dirname, vector< Mat > & img_lst, bool showImag
74
74
for ( size_t i = 0 ; i < files.size (); ++i )
75
75
{
76
76
Mat img = imread ( files[i] ); // load the image
77
- if ( img.empty () ) // invalid image, skip it.
77
+ if ( img.empty () )
78
78
{
79
- cout << files[i] << " is invalid!" << endl;
79
+ cout << files[i] << " is invalid!" << endl; // invalid image, skip it.
80
80
continue ;
81
81
}
82
82
@@ -95,16 +95,13 @@ void sample_neg( const vector< Mat > & full_neg_lst, vector< Mat > & neg_lst, co
95
95
box.width = size.width ;
96
96
box.height = size.height ;
97
97
98
- const int size_x = box.width ;
99
- const int size_y = box.height ;
100
-
101
98
srand ( (unsigned int )time ( NULL ) );
102
99
103
100
for ( size_t i = 0 ; i < full_neg_lst.size (); i++ )
104
101
if ( full_neg_lst[i].cols > box.width && full_neg_lst[i].rows > box.height )
105
102
{
106
- box.x = rand () % ( full_neg_lst[i].cols - size_x );
107
- box.y = rand () % ( full_neg_lst[i].rows - size_y );
103
+ box.x = rand () % ( full_neg_lst[i].cols - box. width );
104
+ box.y = rand () % ( full_neg_lst[i].rows - box. height );
108
105
Mat roi = full_neg_lst[i]( box );
109
106
neg_lst.push_back ( roi.clone () );
110
107
}
@@ -259,7 +256,7 @@ int main( int argc, char** argv )
259
256
load_images ( pos_dir, pos_lst, visualization );
260
257
if ( pos_lst.size () > 0 )
261
258
{
262
- clog << " ...[done]" << endl;
259
+ clog << " ...[done] " << pos_lst. size () << " files. " << endl;
263
260
}
264
261
else
265
262
{
@@ -287,22 +284,25 @@ int main( int argc, char** argv )
287
284
}
288
285
289
286
clog << " Negative images are being loaded..." ;
290
- load_images ( neg_dir, full_neg_lst, false );
287
+ load_images ( neg_dir, full_neg_lst, visualization );
288
+ clog << " ...[done] " << full_neg_lst.size () << " files." << endl;
289
+
290
+ clog << " Negative images are being processed..." ;
291
291
sample_neg ( full_neg_lst, neg_lst, pos_image_size );
292
- clog << " ...[done]" << endl;
292
+ clog << " ...[done] " << neg_lst. size () << " files. " << endl;
293
293
294
294
clog << " Histogram of Gradients are being calculated for positive images..." ;
295
295
computeHOGs ( pos_image_size, pos_lst, gradient_lst, flip_samples );
296
296
size_t positive_count = gradient_lst.size ();
297
297
labels.assign ( positive_count, +1 );
298
- clog << " ...[done] ( positive count : " << positive_count << " )" << endl;
298
+ clog << " ...[done] ( positive images count : " << positive_count << " )" << endl;
299
299
300
300
clog << " Histogram of Gradients are being calculated for negative images..." ;
301
301
computeHOGs ( pos_image_size, neg_lst, gradient_lst, flip_samples );
302
302
size_t negative_count = gradient_lst.size () - positive_count;
303
303
labels.insert ( labels.end (), negative_count, -1 );
304
304
CV_Assert ( positive_count < labels.size () );
305
- clog << " ...[done] ( negative count : " << negative_count << " )" << endl;
305
+ clog << " ...[done] ( negative images count : " << negative_count << " )" << endl;
306
306
307
307
Mat train_data;
308
308
convert_to_ml ( gradient_lst, train_data );
@@ -324,7 +324,7 @@ int main( int argc, char** argv )
324
324
325
325
if ( train_twice )
326
326
{
327
- clog << " Testing trained detector on negative images. This may take a few minutes..." ;
327
+ clog << " Testing trained detector on negative images. This might take a few minutes..." ;
328
328
HOGDescriptor my_hog;
329
329
my_hog.winSize = pos_image_size;
330
330
0 commit comments