1

Thanks for all the replies!
I've added the ..\wavFile.wav in the command argument.

But I still cant use the command window.
It still pops up and close immediately.
Maybe its because I use the console application to run this program?
Or are there other reasons?


I am new to opencv and I tried the following code to load and display an image
(using visual studio 2012)
I ran it using the debug mode, but I always get a window shows that
Usage: display_image ImageToLoadAndDisplay,and the window close immediately
(seems like argc is always equal to 2?)
The window wont stay there and wait for a command to load my image.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
   if( argc != 2)
    {
      cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
      return 0;
    }
    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

    if(! image.data )                         // Check for invalid input
    {
     cout <<  "Could not open or find the image" << std::endl ;
     return -1;
    }
    cvNamedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.
    waitKey(0);                                          // Wait for a    keystroke in the window
    return 0;
 }

Might be a really stupid question but I really cant figure it out for a long time.
Hope someone can help me! THANKS A LOT!

Colin
  • 33
  • 5

1 Answers1

3
  • Right click your project in Solution Explorer and select Properties from the menu
  • Go to Configuration Properties -> Debugging
  • Set the Command Arguments in the property list. enter image description here

source : https://stackoverflow.com/a/3697320/4499919

OR

The Mozilla.org FAQ on debugging Mozilla on Windows is of interest here.

In short, the Visual Studio debugger can be invoked on a program from the command line, allowing one to specify the command line arguments when invoking a command line program, directly on the command line.

This looks like the following for Visual Studio 8 or 9

devenv /debugexe 'program name' 'program arguments' It is also possible to have an explorer action to start a program in the Visual Studio debugger.

source : Debugging with command-line parameters in Visual Studio

OR

https://stackoverflow.com/questions/24202291/opencv-imread-from-command-line-argv1

Community
  • 1
  • 1
udit043
  • 1,610
  • 3
  • 22
  • 40
  • If the answer to this question is found in an older question, then this is a duplicate. You should mark as duplicate instead of copying other answers. (I'm not downvoting you because you correctly give credit to the authors of the answers.) – Miki Nov 13 '15 at 11:25
  • I put the ..\wavFile.wav in the command argument but it still reacts the same – Colin Nov 13 '15 at 11:37
  • 1
    .wav is a audio format file , opencv is for image processing – udit043 Nov 13 '15 at 13:12
  • @Miki i will take care about this next time :) ,thnx – udit043 Nov 13 '15 at 13:14