Ask Your Question
0

Loading image

asked 2013-02-12 10:27:14 -0600

project_310 gravatar image

updated 2013-02-12 11:12:21 -0600

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

    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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-02-12 10:41:46 -0600

updated 2013-02-12 10:42:58 -0600

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.

edit flag offensive delete link more

Comments

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 ...

Usage: display_image ImageToLoadAndDisplay

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 !

project_310 gravatar imageproject_310 ( 2013-02-13 05:15:49 -0600 )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.

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-02-13 06:51:28 -0600 )edit
1

answered 2013-02-12 10:53:20 -0600

unxnut gravatar image

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.

edit flag offensive delete link more

Comments

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 !

project_310 gravatar imageproject_310 ( 2013-02-13 07:45:49 -0600 )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.

unxnut gravatar imageunxnut ( 2013-02-13 09:01:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-02-12 10:27:14 -0600

Seen: 1,092 times

Last updated: Aug 21 '13