c++ - Significance of argc and argv in int main( int argc, char** argv ) in OpenCV -


in following program loading , displaying image in opencv

#include <opencv2/core/core.hpp>    #include <opencv2/highgui/highgui.hpp>   #include <iostream>  using namespace cv;   using namespace std;  int main( int argc, char** argv )   {       if( argc != 2)        {       cout <<" usage: display_image imagetoloadanddisplay" << endl;      return -1;     }      mat image;     image = imread(argv[1], cv_load_image_color);   // read file      if(! image.data )                              // check invalid input     {         cout <<  "could not open or find image" << std::endl ;         return -1;     }      namedwindow( "display window", cv_window_autosize );// create window display.     imshow( "display window", image );                   // show our image inside it.      waitkey(0);                                          // wait keystroke in window     return 0; } 

i not able understand how programmer specifying input image. because argv[1] array element , think has no relation image specified, , hasn't been defined anywhere in program. can clear doubts?

one more thing: being checked in "if" statement checks if(argc !=2)?

main( int argc, char** argv )            |            |            |            |            |            +----pointer supplied arguments            +--no. of arguments given @ command line (including executable name) 

example :

display_image image1.jpg 

here,

argc 2 argv[0] points display_image argv[1] points image1  if(argc !=2 )    ^^ checks whether no. of supplied argument not 2 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -