First of all, you are using the C and C++ libraries interchangeably - IpIImage belongs to C and Mat belongs to C++, this could be the source of your problem. Instead, try just using the C++ interface and your code will be as follows :
Mat image = imread("Black&White.jpg");
imshow("Image",image);
waitKey(0);
That should fix your problem, if not, try using the C interface
IplImage* image = cvLoadImage("Black&White.jpg");
cvNamedWindow( "Image", CV_WINDOW_AUTOSIZE );
cvShowImage("Image", image);
cvWaitKey(0);
Answer from MattTheHack on Stack OverflowFirst of all, you are using the C and C++ libraries interchangeably - IpIImage belongs to C and Mat belongs to C++, this could be the source of your problem. Instead, try just using the C++ interface and your code will be as follows :
Mat image = imread("Black&White.jpg");
imshow("Image",image);
waitKey(0);
That should fix your problem, if not, try using the C interface
IplImage* image = cvLoadImage("Black&White.jpg");
cvNamedWindow( "Image", CV_WINDOW_AUTOSIZE );
cvShowImage("Image", image);
cvWaitKey(0);
Have you really checked that you used the proper link to the file? In my case, I usually check it by doing:
image = imread( "C:\\\CloudStation\\\Bestanden\\\VisualStudio2010\\\Projects\\\TMerger\\\Debug\\\black_and_white.tif")
So in my case, I have to use a double backward slash.
Hope it helps.
greetings, Floris.
If you need to show an image that is bigger than the screen resolution, you will need to call
namedWindow("Display frame", WINDOW_NORMAL)
before the imshow.
To set desirable size of the window call please
cv::resizeWindow("Display frame", WIDTH, HEIGHT);
For more details see http://docs.opencv.org/modules/highgui/doc/user_interface.html#imshow
Passing CV_WINDOW_AUTOSIZE to namedWindow() will make the window size automatically adjust to fit the displayed image. And you see part of the image is probably because the image is too large for your screen.
To work out, you can first resize the image to smaller size. Like this:
Mat image=imread("...");
resize(image, image, Size(image.cols/2, image.rows/2)); // to half size or even smaller
namedWindow( "Display frame",CV_WINDOW_AUTOSIZE);
imshow("Display frame", image);