Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
To display an image:

C++
#include <iostream>
#include <highgui.h>
using namespace std;
int main( int argc, char** argv ) {
IplImage* img = cvLoadImage( argv[1] );
cout<< argv[1];
const char* name = "window1";
cvNamedWindow(name, 0 );
cvShowImage( name, img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( name);
}


If I keep image at C:\Users\si765906\Documents\car.jpg , the output is correct. But if I keep it at C:\Users\si765906\Documents\Visual Studio 2010\Projects\new\car.jpg , I get a grey screen. I am using VisualStudio 2010 Express edition and am adding the argument from the properties.
Also, in printing argv,
in the first case, I get
C:\Users\si765906\Documents\car.jpg

While in the second case,
C:\Users\si765906\Documents\Visual

Please help/explain.
Posted

1 solution

The path is not too long. Enclose the full path in double quotation marks because of the blank space. It is a common problem in some old code.

Check that the app has the right to access the file if that doesnt help.
 
Share this answer
 
Comments
Member 11721565 27-May-15 2:20am    
Thank you. This has worked. :)
Sergey Alexandrovich Kryukov 27-May-15 2:39am    
Sure, a 5.
Also: see MAX_PATH.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900