OPENCV не открывает изображение, ошибка - check file/path integrity

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

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    // Read the image file
    Mat image = imread("C:/Users/user/Desktop/orig.jpg");

    // Check for failure
    if (image.empty())
    {
        cout << "C:/Users/user/Desktop/orig.jpg" << endl;
        cin.get(); //wait for any key press
        return -1;
    }

    String windowName = "The Guitar"; //Name of the window

    namedWindow(windowName); // Create a window

    imshow(windowName, image); // Show our image inside the created window.

    waitKey(1000); // Wait for any keystroke in the window

    destroyWindow(windowName); //destroy the created window

    return 0;

Ответы (1 шт):

Автор решения: NunOfIt

Проблема скорее всего кроется в том, что вы используете правый слеш, а пути к файлам в windows записываются через левый слеш, но как вы правильно заметили, c++ ругается на его использование...

Проблема в том, что в пути файла слеш повернут налево, а плюсы ругаются и заставляют писать слешы, повернутые направо

Это можно исправить следующими способами:

  1. Через двойной слеш "C:\\Users\\user\\Desktop\\orig.jpg"
  2. Через raw string literal R"(C:\Users\user\Desktop\orig.jpg)"

Подробнее про raw string literal: тык

P.S. Я тут немного в примерах для openCV покопался (тык) и по идее нужно добавлять вот такие библиотеки (модули)

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>

In OpenCV 3 we have multiple modules. Each one takes care of a different area or approach towards image processing. You could already observe this in the structure of the user guide of these tutorials itself. Before you use any of them you first need to include the header files where the content of each individual module is declared.

You'll almost always end up using the:

  • core section, as here are defined the basic building blocks of the library
  • imgcodecs module, which provides functions for reading and writing
  • highgui module, as this contains the functions to show an image in a window

Попробуйте ещё добавить флаг IMREAD_COLOR: imread("C:\\Users\\user\\Desktop\\orig.jpg", IMREAD_COLOR), вроде как в той же документации написано, что он и так по дефолту соит, но лучше всё-таки проверить

Тут ещё вам в @andreymal писал про русские символы в названии, т.е. например буквы 'c' и 'p' в русском и английском алфавите выглядят одинаково, но представлены они в двоичном виде по разному... Тоже проверьте.

Вот парочка похожих вопросов, просмотрите там ответы, может вам, что поможет: (тык)(тык)

→ Ссылка