Search code examples
c++opencvargv

Imread & argv image location?


I am new to coding in C++ and am currently working on an application that can clear all objects out of a picture except for the biggest one. I was looking on doing object size detection based on the bounding boxes tutorial I found here

But this code contains one line using the imread function and then an array to specify the path to the image

/// Load source image and convert it to gray
src = imread( argv[1], 1 );

How is it that argv[1] can be used in this situation to point out where the image is sourced from? I thought argv & argc had to do with the number of command lines that are called? Any information?

As stated earlier I am new to c++ so sorry if this is a silly question. Thanks in advance


Solution

  • argc contains number of command line arguments, wheren argv contains the commands themselves, where the first command is the program name itself. For example:

    ./program param1 param2
    

    will have argc=3 and

    argv[0] = program
    argv[1] = param1
    argv[2] = param2
    

    so if your program name is program and your file path is D:/folder/file then you should replace param1 with D:/folder/file and then argv[1] will contain the file path.