0

I have just started learning opencv and i am stuck at the very first example of just loading an image.

#include <cv.h>
#include <highgui.h>
int main( int argc, char** argv )
{
  IplImage* imageName =cvLoadImage( argv[1]);

what task is argv and argc carrying out?

Amit Bisht
  • 131
  • 3
  • since you're just starting, if you see any code that uses IplImages, that's outdated. use c++, cv::Mat, cv::imread() and such. – berak Jan 08 '14 at 10:31
  • Actually i don't know c++ properly. I have knowledge of c only. Should i learn c++ now? – Amit Bisht Jan 08 '14 at 12:04

1 Answers1

0

This is not really about OpenCV. This is a feature of the C language.

argv and argc are the parameters of the main() function, which allow your program to take command line arguments. argv is an array of c-style strings, and argc is the number of strings in argv. argv[0] is the name of your executable, and argv[1] through argv[argc-1] are the command line arguments to your program. In your example, argv[1] is the first command line argument, that contains the file name of the image to be loaded.

Let's say the name of your executable is myOpencvProgram. If you invoke it from the command line like this:

> myOpencvProgram image1.jpg

then argv[0] will contain the string "myOpencvProgram", argv[1] will contain "image1.jpg", and argc will be equal to 2.

Dima
  • 38,860
  • 14
  • 75
  • 115