Ask Your Question

Revision history [back]

Basically like Guanta just suggested, place

waitKey(20);

behind the imshow. It makes sure that the draw and update function of the window are properly called before closing down the window. Place a 0 if you want the window only to close when pressing a key.

Basically like Guanta just suggested, place

waitKey(20);
cv::Mat img = cv::imread("C:/test/R0010054.JPG"); //it is better to use absolute paths first

if(img.empty())
{
     cout << "Image not loaded";
     return -1; //i guess this isn't throwed, add a print statement none the less
}

cv::imshow("image", img);
waitKey(0); //time added here counts in milliseconds --> needed for processing

behind the imshow. It makes sure that the draw and update function of the window are properly called before closing down the window. Place a 0 if you want the window only to close when pressing a key.

Some more tips

  • Always add debug output, it will show you where it goes wrong
  • When loading of images doesn't work, try with absolute path first, then experiment with relative paths. Sometimes a relative path isn't recognized due to faulty environment variables.

Basically like Guanta just suggested, place a waitKey command

cv::Mat img = cv::imread("C:/test/R0010054.JPG"); //it is better to use absolute paths first

if(img.empty())
{
     cout << "Image not loaded";
     return -1; //i guess this isn't throwed, add a print statement none the less
}

cv::imshow("image", img);
waitKey(0); //time added here counts in milliseconds --> needed for processing

behind the imshow. It makes sure that the draw and update function of the window are properly called before closing down the window. Place a 0 if you want the window only to close when pressing a key.

Some more tips

  • Always add debug output, it will show you where it goes wrong
  • When loading of images doesn't work, try with absolute path first, then experiment with relative paths. Sometimes a relative path isn't recognized due to faulty environment variables.