-1

I am new to OpenCV. I appreciate if somebody answers this question. I try to read an image and display it. Below is a copy of the code I copied from documentation. However, a window just pops up without the actual image:

#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat img = imread("myimage.jpg", CV_LOAD_IMAGE_UNCHANGED);

    if (img.empty()) 
    {
        cout << "Error : Image cannot be loaded..!!" << endl;
        return -1;
    }
    else
    {
        namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); 
        imshow("MyWindow", img); 
        waitKey(5000); 
    }      

    return 0;
}
Keugyeol
  • 2,355
  • 1
  • 28
  • 36

2 Answers2

-1

I have copied over your code, and changed the image to my local one, and it displays correctly.
Looks like the program cannot read the image for some reason.
Why don't you try with the full path to the image?

Keugyeol
  • 2,355
  • 1
  • 28
  • 36
  • If the program couldn't load the image, it wouldn't get to the `imshow` part, so no windows ought to be popping up. IMHO this is yet another occurrence of [a know bug](https://github.com/opencv/opencv/issues/8885), as this sort of questions shows here on pretty much daily basis lately. – Dan Mašek Jun 26 '17 at 12:13
-1

The code is pretty correct, make sure you got myimage.jpg in the same folder with your binary. Try with full path to an image or provide a path to your image as argv[1].

f4f
  • 891
  • 5
  • 13
  • Thanks a lot for your help. I used the full path and it did not work. But when I close the image, I can see a copy in the same directory. – LuisBachelier81 Jun 27 '17 at 05:05