Read an image with imread()

asked 2014-03-10 14:11:37 -0500

residentelvio gravatar image

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

berak gravatar image

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)

edit retag flag offensive close merge delete

Comments

First, what are you trying to accomplish, what is the goal you are trying to achieve?

Will Stewart gravatar imageWill Stewart ( 2014-03-10 15:07:18 -0500 )edit

Load an image by passing the path or by a command line interface (I don t know if the right term in English) . Howewer the code works.I just want to understand better why is used in that way. How is used about the command line loading in that way

residentelvio gravatar imageresidentelvio ( 2014-03-11 06:35:00 -0500 )edit

I mean why argv[1] is the path of an image passed by command line?

residentelvio gravatar imageresidentelvio ( 2014-03-11 06:37:22 -0500 )edit
1

This seems more like a C/C++ question than an OpenCV question. You need to figure out about argv.

unxnut gravatar imageunxnut ( 2014-03-11 07:04:49 -0500 )edit
1

Yes, argv[1] is the first command line parameter.

GilLevi gravatar imageGilLevi ( 2014-03-11 08:52:39 -0500 )edit