Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

CommandLineParser only gets True

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