Hello

I dont understand where exactly do i write the filename or pathname of image in the most basic code , I have tried different versions of code and successsfulyl loaded images ..bt the documentation has the following code :

#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 -1;
}

Mat image;

if(! image.data )                              // Check for invalid input
{
cout <<  "Could not open or find the image" << std::endl ;
return -1;
}

namedWindow( "Display window", CV_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;
}


PLS tell me where do i write the pathname/filename to load my image.

edit retag close merge delete

Sort by » oldest newest most voted

Right now your are loading image given as first argument to your program (argv[1]) If you want to load a default image in the code, just replace argv[1] by "c:\\Where\\MyImage\\IS\\image.jpg" or "/home/myself/myimage/is/here.png" for example, in the imread function.

more

I keep trying that again and again and I still cant load the image using the Mat operator I tried the method via Iplimage one , that works good but after reading documentation it's an old method and the memory management is not good !

So pls help me with this MAT method as it still isnt working , it builds successfully , but shows Command prompt with following line ...

Either give me a different code using Mat operator or help me out with this one code one. I am using all codes from documentation , still they dont work ..serious problems and frustrating !

( 2013-02-13 05:15:49 -0500 )edit
1

If you see "Usage: display_image ImageToLoadAndDisplay" that because you don't use argument to launch your program. The code with Mat should work, but you have to define the argument to the command line (see @unxmut answer below to specify it). Take care that under Visual Studio, you have to specify arguments for Debug and Release separately.

( 2013-02-13 06:51:28 -0500 )edit

If you are executing from within Visual Studio, there is an option to specify command line arguments in Project Configuration Settings. If you are trying to run it from a command line window, you will be better off specifying the absolute (or relative) path on the command line argument. Make sure you enclose the path in double quotes because of spaces in the path if you have any.

more

I cant find this setting , can u pls elaborate and explain where to find and activate the above settings?

Sorry for troubling you on this trivial problem , but it's really not working !

( 2013-02-13 07:45:49 -0500 )edit

It is in: Project->Properties->Debugging->Command Arguments. You can also specify working directory over there just to make sure that your image is in the appropriate directory.

( 2013-02-13 09:01:08 -0500 )edit

Official site

GitHub

Wiki

Documentation