Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Read an image with imread()

Hi people, I have this part of code and I d like to undrestand better it.

  Mat img=imread(".....");   //... is a path

  if(argc>1)
    img=imread(argv[1]);

  if(img.empty(){
    cerr <<" Error message:" << argv[1];
    return 1;
  }

  if (img.empty(){
    cout << "the image is empty\n";
    return -1;
  }

First line load an image by passing directly the path of the image. After it load an image if is passed by command line, as cmd, or terminal. Can I understand better how. Why is it used argv[1]? Is it a need to use 2 time the control about if the imafe is loaded? I understand is a control firstly for the second kind of loading image and after for the 1st (load by adding path)

click to hide/show revision 2
retagged

updated 2014-03-11 04:06:04 -0600

berak gravatar image

Read an image with imread()

Hi people, I have this part of code and I d like to undrestand better it.

  Mat img=imread(".....");   //... is a path

  if(argc>1)
    img=imread(argv[1]);

  if(img.empty(){
    cerr <<" Error message:" << argv[1];
    return 1;
  }

  if (img.empty(){
    cout << "the image is empty\n";
    return -1;
  }

First line load an image by passing directly the path of the image. After it load an image if is passed by command line, as cmd, or terminal. Can I understand better how. Why is it used argv[1]? Is it a need to use 2 time the control about if the imafe is loaded? I understand is a control firstly for the second kind of loading image and after for the 1st (load by adding path)