I have a problem with my c++ opencv program. It should show a picture I loaded in, but after debugging only a grey window pops up. Here is my code:
#include <cv.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
IplImage* img = cvLoadImage( "IMG_7321_.jpg" );
cvNamedWindow( "IMG_7321_", CV_WINDOW_AUTOSIZE );
cvShowImage("IMG_7321_", img);
cvWaitKey(0);
cvReleaseImage(开发者_StackOverflow社区 &img );
cvDestroyWindow( "IMG_7321_" );
return 0;
}
The .jpg file is in the project folder.
Can anybody tell me what I have to do to get the picture to be shown. Help would be much appreciated!
You should check to see if you are successfully loading the file. Try this:
int main(int argc, char* argv[])
{
IplImage* img = cvLoadImage( "IMG_7321_.jpg" );
if (!img) {
fprintf(stderr, "Image not found\n");
return -1;
}
cvNamedWindow( "IMG_7321_", CV_WINDOW_AUTOSIZE );
cvShowImage("IMG_7321_", img);
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "IMG_7321_" );
return 0;
}
精彩评论