I am tryint to read an image with OpenCV 2.1 (started just today), C++ using the code below.
I can not see what is the problem in the following. Thank you if you can provide some help.
int main( int argc, char** argv )
{
int height,width,step,channels;
//Load the image and make sure that it loads correctly
IplImage* im = cvLoadImage("kermit.jpg", 1);
if(!im )
{
//Drop out if the image isn't found
cout << "Failed to load: "<<"kermit.jpg"<<"\n";
return 0;
}
else
{
cout<<"Image was loaded with success "<<"kermit.jpg"<<"\n";
return (0);
}
height=im->height;
width=im->width;
step=im->widthStep;
channels=im->nChannels;
cout<<"(height, width)"<<height<<width<<"\n";
cvNamedWindow("kermit.jpj",CV_WINDOW_AUTOSIZE);
cvShowImage( "kermit.jpg", im );
cvWaitKey(0);
cvDestroyWindow ("kermit.jpg");
return 0;
}
Since you didn’t tell us what the problem really is, I want to point out the following code:
This means that if the loading fails you quit the application, and if the loading succeeds, you also quit. Sounds wrong, right? You shouldn’t
returnon success.You don’t need the
elseblock, so please remove it and try again. The rest of the code seems to be OK.