3

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

TheAlPaca02
  • 485
  • 3
  • 8
  • 20

2 Answers2

4

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.

Rakib
  • 7,435
  • 7
  • 29
  • 45
  • How do I add in those commands before executing the program itself then? Cmd only pops up right after debugging.. – TheAlPaca02 May 19 '14 at 11:50
  • @TheAlPaca02: this is no longer a C++ problem, but an environment problem. From your question you are probably using a code editor (such as Visual Studio) to develop your C++ program, and launching the program from your editor, I advise to check on SO how to add a command line in your particular editor (and if you cannot find it, ask a new question precising exactly which editor you use). – Matthieu M. May 19 '14 at 12:25
  • @TheAlPaca02, as Matthieu pointed out, search using the specific IDE you are using how can you set arguments. For Visual Studio, right click on the project, select properties and in the dialog, you will find an option *Command Arguments* where you can set them. Note: You don't need to specify the program name in case of using IDE. – Rakib May 19 '14 at 12:29
0

You may find the info on argc, argv here. So yes, imread can take one of the parameters in argv as a string which specifies the image file name/path.

Community
  • 1
  • 1
Яois
  • 3,838
  • 4
  • 28
  • 50