Ask Your Question
2

CommandLineParser only gets True

asked 2016-03-16 13:38:26 -0600

willoughby gravatar image

So I am trying to use a CommandLineParser to parse arguments. I was having little luck so I tryed to create a simple case and see what was going on. Here is my code :

int main(int argc, const char* argv[])
{
   // Define and process cmdline arguments.
   CommandLineParser cmd(argc, argv,
       "{ i input            |           | Input video }"
       "{ ifd in_frame_dims  |           | Input frame dimensions }"
       "{ ifr in_frame_roi   |           | Input frame roi }"
       "{ ofd out_frame_dims |           | Output frame dimensions }"
       "{ o output           |           | Output video }"
       "{ s scale            | 4         | Scale factor }"
       "{ t temporal         | 4         | Radius of the temporal search area }"
       "{ h help             |           | Print help message }"
   );

   // Process cmd line help.
   if (cmd.get<bool>("help"))
   {
       cout << "Help" << endl;
       cmd.printMessage();
       return 0;
   }
   cout<<"string: "<<cmd.get<string>("input")<<endl;
   cout<<"bool: "<<cmd.get<bool>("input")<<endl;
   cout<<"int: "<<cmd.get<int>("input")<<endl;

   return 0;
}

now when I call this like so :

./ArgTest -i test.avi -ifd 320x240 -ifr 0x0+320x240 -ofd 640x480 -s 2 -t 2 -o testout.avi

I get :

string: true
bool: 1
OpenCV Error: Bad argument (can not convert: [true] to [int]) in from_str, file /Users/willoughby/Documents/packages/opencv-3.1.0/modules/core/src/command_line_parser.cpp, line 98
int: 0

It doesn't matter which key I used "cmd.get<string>("key") always returns true

what am I doing wrong

edit retag flag offensive close merge delete

Comments

did you take a look at documentation

sturkmen gravatar imagesturkmen ( 2016-03-16 15:46:50 -0600 )edit

I did read the documentation. Are you referring to a particular part of the documentation

willoughby gravatar imagewilloughby ( 2016-03-16 16:01:22 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-03-16 16:12:38 -0600

it seems you shoud type like

./ArgTest -i=test.avi -ifd=320x240 -ifr=0x0+320x240 -ofd=640x480 -s=2 -t=2 -o=testout.avi
edit flag offensive delete link more

Comments

This answer did the trick for me. I think that should be referenced in the documentation. Is there any way to pass the arguments without the equals "=" symbol?

dimimal gravatar imagedimimal ( 2018-12-27 11:57:26 -0600 )edit

with CommandLineParser no way to pass argument value without the equals "=" symbol except boolean arguments.if you really need you can write your own function like this

sturkmen gravatar imagesturkmen ( 2018-12-27 12:05:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-16 13:38:26 -0600

Seen: 2,518 times

Last updated: Mar 16 '16