imread, command line arguments in VS13

asked 2015-08-19 06:31:06 -0600

Salman gravatar image

updated 2018-09-02 14:54:18 -0600

I'm trying to run this code in VS13 that uses command line argument I'm following this method but its nt working.

Solution Explorer Properties Debugging Command Arguments "D:/Images/image1.jpeg" "D:/Images/image2.jpeg"

Code:

#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <stdio.h>
#include <iostream>


using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{

Mat img;
Mat img2;

img = imread(argv[1], CV_LOAD_IMAGE_COLOR);
img2 = imread(argv[2], CV_LOAD_IMAGE_COLOR);

if (img.empty() || img2.empty)
{
    cout << "Error: Image cannot be loaded!" << endl;
    system("pause");
    return -1;
}

namedWindow("Image", CV_WINDOW_AUTOSIZE);
imshow("Image", img);
namedWindow("Imag2", CV_WINDOW_AUTOSIZE);
imshow("Image2", img2);

waitKey(0);
return 0;

}

edit retag flag offensive close merge delete

Comments

What do you mean by "not working"?

I think that's a small mistake

namedWindow("Imag**e**2", CV_WINDOW_AUTOSIZE);
imshow("Image2", img2);
LBerger gravatar imageLBerger ( 2015-08-19 07:26:54 -0600 )edit

sorry friend @LBerger you pointed out the right mistake but unfortunately the code even doesn't reach there. It gives "Error The image can't be loaded" as i mentioned i'm unable to load my images by command line arguments.

Salman gravatar imageSalman ( 2015-08-19 08:57:30 -0600 )edit

There is an another error with empty img2.empty()

may be you should try like this to check some values :

cout << "argc ="<<argc<<"\n";
cout<<"Try to load "<<argv[1];
img = imread(argv[1], CV_LOAD_IMAGE_COLOR);
if (img.empty() )
{
    cout << "\nError: Image cannot be loaded!" << endl;
    system("pause");
    return -1;
}
cout<<"\nTry to load "<<argv[2];
img2 = imread(argv[2], CV_LOAD_IMAGE_COLOR);

if (img2.empty())
{
    cout << "\nError: Image cannot be loaded!" << endl;
    system("pause");
    return -1;
}
LBerger gravatar imageLBerger ( 2015-08-19 09:37:57 -0600 )edit

@LBerger: these errors doesn't matter unless at least single image is read, which is not done :/ and i'm confused why is that.. :(

Salman gravatar imageSalman ( 2015-08-19 11:43:55 -0600 )edit

You shouldn't use duplicate post. About your problem know there is no problem in your program.

Problem is in given path. Can you check what happen using debugger for example? I think somebody give you a remark like don't use / in cmd line argument. Use windows path "D:\Images\image1.jpeg".

You can use / when you path is written like imread("D:/Images/image1.jpeg", CV_LOAD_IMAGE_COLOR); and of course check path ( don't forget white space, ...)

LBerger gravatar imageLBerger ( 2015-08-20 02:37:53 -0600 )edit