First time here? Check out the FAQ!

Ask Your Question
1

Loading images in Argument

asked Sep 22 '13

GiulSDU gravatar image

updated Sep 22 '13

berak gravatar image

Hi, i have to load 4 images that i uploaded in the Argument section(run-run properties- arguments) and i am trying to load them with "argv[i]". I always have the same input: Usage: display_image ImageToLoadAndDisplay

Can you please tell me where is the error? i think it may be in the Arguments field, maybe there is some special character to divide arguments, by now i am just writing the location of the image with one space within every location. This is my code.

int main( int argc, char** argv )
{
    if( argc != 2)
    {
        cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }

    Mat  images[4];
    Mat spectrum[4];
    for (int i=1;i<5;i++)
    {
        images[i-1]=imread(argv[i], CV_LOAD_IMAGE_GRAYSCALE );

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

    Fourier(images[i-1],spectrum[i-1]);

    string name="image number "+ i;
    string nameSpectrum= "spectrum number " + i;
    namedWindow(name, CV_WINDOW_AUTOSIZE );
    imshow(name, images[i] );

    namedWindow(nameSpectrum, CV_WINDOW_AUTOSIZE );
    imshow(nameSpectrum, spectrum[i] );
    waitKey(0);

    }
Preview: (hide)

Comments

2

if you want 4 images, change if( argc != 2) to if( argc != 5) // 4 images + progname

berak gravatar imageberak (Sep 22 '13)edit

1 answer

Sort by » oldest newest most voted
1

answered Sep 23 '13

Just a quick tip, when dealing with arguments, make sure you know how the argv and argc values actually work.

Argc gives you the amount of arguments that were passed to the algorithm.

Argv consists of an array of parameters, stored as char arrays, with the executable name as first parameter on the 0 index. Knowing that you will be able to handle it all in the feature.

Indeed, in your case, the solution proposed by @berak is correct.

Preview: (hide)

Question Tools

Stats

Asked: Sep 22 '13

Seen: 150 times

Last updated: Sep 23 '13