Search code examples
c++opencvimread

C++ OpenCV imread file path format for windows


I've tried to google this to no avail. Please help me understand what is wrong with this file path:

Mat lena = imread("C:\Users\dasboomer\Desktop\Building-Computer-Vision-Projects-with-OpenCV4-and-CPlusPlus-master\Chapter03/lena.jpg");

I've tried changing:

  • backslash to double backslash
  • backslash to forward slash
  • backslash to double forward slash

Thank you for your assistance


Solution

  • \ is used for an escape sequence.

    Instead, use the below lines of code:

    Mat lena = imread("C:\\Users\\dasboomer\\Desktop\\Building-Computer-Vision-Projects-with-OpenCV4-and-CPlusPlus-master\\Chapter03\\lena.jpg");
    

    or

    Mat lena = imread("C:/Users/dasboomer/Desktop/Building-Computer-Vision-Projects-with-OpenCV4-and-CPlusPlus-master/Chapter03/lena.jpg");