-4

I copy this code from openCV2 book and this code have argc and argv as arguments that I don't know what they are and why assign to 1 (argc=1) and terminate debugging ...my problem that why argc=1? And how I can fix it? because my argc should be 2 (argc==2)...

#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main( int argc, char** argv )
{
  if ( argc ! = 2 )
  {
    printf( " usage: DisplayImage.out <Image_Path>\n" );
    return - 1;
  }
  Mat image;
  image = imread( argv[ 1], 1 );
  if ( ! image.data )
  {
    printf( " No image data \n" );
    return - 1;
  }
  namedWindow( " Display Image" , WINDOW_AUTOSIZE );
  imshow( " Display Image" , image);
  waitKey( 0);
  return 0;
}

I try to wrote this code without argc and argv but the debugger has a runtime error that i think its cause be argc.

Saeed Masoomi
  • 1,703
  • 1
  • 19
  • 33

1 Answers1

0

If you run it by command line, you can call it as

DisplayImage "path_to_image"

If you want to run from VS, be sure to add the "path_to_image" in your command arguments:

  1. PROJECT -> Properties -> Configuration Properties -> Debugging
  2. Put the "path_to_image" in Command Arguments

Be sure that "path_to_image" is a valid path, check here for reference.

As already pointed out in comments, it's a very bad example! OpenCV 3.0.0 has also CommandLineParser for more complex input arguments.

Community
  • 1
  • 1
Miki
  • 40,887
  • 13
  • 123
  • 202