Ask Your Question
1

Loading images in Argument

asked 2013-09-22 10:37:57 -0600

GiulSDU gravatar image

updated 2013-09-22 11:12:51 -0600

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

    }
edit retag flag offensive close merge delete

Comments

2

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

berak gravatar imageberak ( 2013-09-22 11:11:30 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-09-23 04:36:53 -0600

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.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-09-22 10:37:57 -0600

Seen: 138 times

Last updated: Sep 23 '13