I've talked about this so many times before, I guess it's pointless to do it again, but code defensively: if a method/function call can fail, make sure you know when it happens:

Mat I = imread("C:\\images\\apple.jpg", 0);
if (I.empty())
{
    std::cout << "!!! Failed imread(): image not found" << std::endl;
    // don't let the execution continue, else imshow() will crash.
}

namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", I ); 
waitKey(0);

Note that Windows' path uses backslash \ instead of the standard / used on *nix systems. You need to escape the backslash when passing the filename: C:\\images\\apple.jpg

Calling waitKey() is mandatory if you use imshow().

EDIT:

If it's cv::imread() that is throwing the exception the only solution I know to work is downloading OpenCV sources and building it on the machine, since re-installing OpenCV doesn't fix the issue.

Answer from karlphillip on Stack Overflow
๐ŸŒ
YouTube
youtube.com โ€บ watch
OPENCV & C++ TUTORIAL - 1 | imshow() - imread() - waitKey() - YouTube
If youโ€™d like to buy me a coffee โ˜•๐Ÿ‘‰ https://buymeacoffee.com/yunustemurlenkI will continue to this tutorial series with this plan : https://docs.opencv.org/...
Published: February 28, 2021
๐ŸŒ
OpenCV
docs.opencv.org โ€บ 4.13.0 โ€บ d4 โ€บ da8 โ€บ group__imgcodecs.html
OpenCV: Image file reading and writing
The function imencode compresses ... formats and flags description. ... Loads an image from a file. The imread function loads an image from the specified file and returns OpenCV matrix....
๐ŸŒ
LearnOpenCV
learnopencv.com โ€บ home โ€บ read an image in opencv ( python, c++ )
Read an Image in OpenCV ( Python, C++ ) | LearnOpenCV
October 23, 2025 - In all the examples below, make sure you use the right namespace for C++ and import OpenCV for Python. C++ ... A vast majority of images are 8-bit per channel ( or 24-bit ) images. They can be read using default flags. ... Most digital SLR cameras are capable of recording images at a higher bit depth than 8-bits / channel. The raw images from these cameras can be converted to 16-bit / channel PNG or TIFF images. These 16-bit / channel images can be read using C++ Mat image = imread("image.png", IMREAD_ANYCOLOR | IMREAD_ANYDEPTH);
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c++ โ€บ reading-and-displaying-an-image-in-opencv-using-c
Reading and Displaying an image in OpenCV using C++ - GeeksforGeeks
July 26, 2025 - The only change seen from a standard ... required for reading and displaying an image in OPenCV: imread(): This function is used to read images and takes the ......
๐ŸŒ
OpenCV
docs.opencv.org โ€บ 4.13.0 โ€บ db โ€บ deb โ€บ tutorial_display_image.html
OpenCV: Getting Started with Images
As a first step, we read the image "starry_night.jpg" from the OpenCV samples. In order to do so, a call to the cv::imread function loads the image using the file path specified by the first argument. The second argument is optional and specifies the format in which we want the image.
๐ŸŒ
OpenCV
opencv.org โ€บ home โ€บ news โ€บ read, display and write an image using opencv
Read, Display and Write an Image using OpenCV
March 28, 2025 - To read an image in OpenCV, we use the imread() function. This function loads an image from the specified file path and returns it as a NumPy array, allowing further processing or analysis.
๐ŸŒ
LearnOpenCV
learnopencv.com โ€บ home โ€บ image processing โ€บ read, display and write an image using opencv
Read, Display and Write an Image using OpenCV - LearnOpenCV
July 31, 2026 - Letโ€™s begin by importing the OpenCV library in Python and C++ (as shown below). ... In C++, use #include (as shown below) to accomplish the same. Also specifying the namespaces for it lets you refer to function names directly. No need to prepend them with the namespace (e.g. instead of cv::imread(), you can just directly use read()).
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ opencv โ€บ opencv_reading_images.htm
OpenCV - Reading Images
Load the OpenCV native library using the load() method, as shown below. //Loading the core library System.loadLibrary(Core.NATIVE_LIBRARY_NAME); Instantiate the Imgcodecs class. //Instantiating the Imgcodecs class Imgcodecs imageCodecs = new Imgcodecs(); Read the image using the method imread().
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ opencv cv2.imread()
OpenCV cv2.imread() method - Scaler Topics
May 26, 2023 - The cv2.imread() method in OpenCV returns a NumPy array representing the image read from the file.
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ programming languages tutorial โ€บ opencv imread
OpenCV imread | How does imread Function Work?
April 10, 2023 - OpenCV is a technique or library ... a number of functions which include imread. The imread function helps in loading an image from a specified folder....
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Opencv-srf
opencv-srf.com โ€บ 2017 โ€บ 11 โ€บ load-and-display-image.html
Load & Display Image - OpenCV Tutorial C++
For more information, please refer OpenCV C++ API. We have to use the std namespace also because cout, endl and cin functions are inside the std namespace. Mat image = imread("D:/My OpenCV Website/Lady with a Guitar.jpg"); The function loads an image from the file "D:/My OpenCV Website/Lady with a Guitar.jpg" and returns it as a Mat object.
๐ŸŒ
Jancy Standard Library
vovkos.github.io โ€บ doxyrest-showcase โ€บ opencv โ€บ sphinx_rtd_theme โ€บ group_imgcodecs.html
Image file reading and writing โ€” OpenCV Documentation
The function imencode compresses the image and stores it in the memory buffer that is resized to fit the result. See cv::imwrite for the list of supported formats and flags description. ... Loads an image from a file. The function imread loads an image from the specified file and returns it.
๐ŸŒ
OpenCV
docs.opencv.org โ€บ 3.4.20 โ€บ d8 โ€บ d6a โ€บ group__imgcodecs__flags.html
OpenCV: Flags used for image file reading and writing
The strategy parameter only affects the compression ratio but not the correctness of the compressed output even if it is not set appropriately.
๐ŸŒ
Rust
docs.rs โ€บ opencv โ€บ latest โ€บ opencv โ€บ imgcodecs โ€บ fn.imread.html
imread in opencv::imgcodecs - Rust
The imread function loads an image from the specified file and returns OpenCV matrix. If the image cannot be read (because of a missing file, improper permissions, or unsupported/invalid format), the function returns an empty matrix.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-opencv-cv2-imread-method
cv2.imread() method - Python OpenCV - GeeksforGeeks
July 12, 2025 - OpenCV-Python is a Python library used to solve computer vision tasks. cv2.imread() method loads an image from the specified file.
๐ŸŒ
OpenCV Q&A Forum
answers.opencv.org โ€บ question โ€บ 122936 โ€บ library-to-link-for-imread
library to link for imread - OpenCV Q&A Forum
January 17, 2017 - You can use imread doc : imread is here with in link imgcodecs you will need opencv_imgcodecs320.lib