From b973b73ae749e376879cf72d815cb2e9604744e1 Mon Sep 17 00:00:00 2001 From: Bob Paulin Date: Wed, 20 Apr 2016 21:53:52 -0500 Subject: [PATCH] Add -maxscale parameter to limit the amount sample images can scale in background images --- apps/createsamples/createsamples.cpp | 13 ++++++++++--- apps/createsamples/utility.cpp | 12 +++++++----- apps/createsamples/utility.hpp | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/createsamples/createsamples.cpp b/apps/createsamples/createsamples.cpp index 9f05e41..1660ade 100644 --- a/apps/createsamples/createsamples.cpp +++ b/apps/createsamples/createsamples.cpp @@ -76,6 +76,7 @@ int main( int argc, char* argv[] ) double scale = 4.0; int width = 24; int height = 24; + double maxscale = -1.0; srand((unsigned int)time(0)); @@ -92,9 +93,10 @@ int main( int argc, char* argv[] ) " [-maxyangle ]\n" " [-maxzangle ]\n" " [-show []]\n" - " [-w ]\n [-h ]\n", + " [-w ]\n [-h ]\n" + " [-maxscale ]\n", argv[0], num, bgcolor, bgthreshold, maxintensitydev, - maxxangle, maxyangle, maxzangle, scale, width, height ); + maxxangle, maxyangle, maxzangle, scale, width, height, maxscale ); return 0; } @@ -172,6 +174,10 @@ int main( int argc, char* argv[] ) { height = atoi( argv[++i] ); } + else if( !strcmp( argv[i], "-maxscale" ) ) + { + maxscale = atof( argv[++i] ); + } } printf( "Info file name: %s\n", ((infoname == NULL) ? nullname : infoname ) ); @@ -194,6 +200,7 @@ int main( int argc, char* argv[] ) } printf( "Width: %d\n", width ); printf( "Height: %d\n", height ); + printf( "Max Scale: %g\n", maxscale); /* determine action */ if( imagename && vecname ) @@ -213,7 +220,7 @@ int main( int argc, char* argv[] ) cvCreateTestSamples( infoname, imagename, bgcolor, bgthreshold, bgfilename, num, invert, maxintensitydev, - maxxangle, maxyangle, maxzangle, showsamples, width, height ); + maxxangle, maxyangle, maxzangle, showsamples, width, height, maxscale); printf( "Done\n" ); } diff --git a/apps/createsamples/utility.cpp b/apps/createsamples/utility.cpp index b5834f3..ddcc1eb 100644 --- a/apps/createsamples/utility.cpp +++ b/apps/createsamples/utility.cpp @@ -38,7 +38,6 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ - #include #include @@ -1308,7 +1307,7 @@ void cvCreateTestSamples( const char* infoname, int invert, int maxintensitydev, double maxxangle, double maxyangle, double maxzangle, int showsamples, - int winwidth, int winheight ) + int winwidth, int winheight, double maxscale ) { CvSampleDistortionData data; @@ -1337,7 +1336,6 @@ void cvCreateTestSamples( const char* infoname, int i; int x, y, width, height; float scale; - float maxscale; int inverse; if( showsamples ) @@ -1366,12 +1364,16 @@ void cvCreateTestSamples( const char* infoname, for( i = 0; i < count; i++ ) { icvGetNextFromBackgroundData( cvbgdata, cvbgreader ); - - maxscale = MIN( 0.7F * cvbgreader->src.cols / winwidth, + if( maxscale < 0.0 ) + { + maxscale = MIN( 0.7F * cvbgreader->src.cols / winwidth, 0.7F * cvbgreader->src.rows / winheight ); + } + if( maxscale < 1.0F ) continue; scale = (maxscale - 1.0F) * rand() / RAND_MAX + 1.0F; + width = (int) (scale * winwidth); height = (int) (scale * winheight); x = (int) ((0.1+0.8 * rand()/RAND_MAX) * (cvbgreader->src.cols - width)); diff --git a/apps/createsamples/utility.hpp b/apps/createsamples/utility.hpp index 9367778..d04947c 100644 --- a/apps/createsamples/utility.hpp +++ b/apps/createsamples/utility.hpp @@ -86,7 +86,7 @@ void cvCreateTestSamples( const char* infoname, int invert, int maxintensitydev, double maxxangle, double maxyangle, double maxzangle, int showsamples, - int winwidth, int winheight ); + int winwidth, int winheight, double maxscale ); /* * cvCreateTrainingSamplesFromInfo -- 2.7.4