cv::imread() 在 OpenCV 中没有读取我的 .png

cv::imread() in OpenCV not reading my .png

我真的是 OpenCV 的新手,我想知道为什么当我检查我的目录中是否有 png 时,我的空矩阵调试字符串是 运行ning。我可以确认我确实在指定目录中有一个给定名称的图像。

相关代码:

    cv::Mat imgTrainingNumbers;
    imgTrainingNumbers = cv::imread("C:/Users/.../source/repos/AutoTrader/training_chars2.png");
    if (imgTrainingNumbers.empty()) {                               // if unable to open image
        std::cout << "error: image not read from file\n\n";         // show error message on command line
        return(0);                                                  // and exit program
    }

目录:

程序会执行 运行 直到它尝试打开图像。我很困惑,为什么它会这样做,我做错了什么?

您使用的图像可能是损坏的数据。 imread() 函数不会 return 任何你的 imgTrainingNumbers 矩阵,如果你...... a. have not specified the path correctly b. the image is not in a proper format/is corrupted c. some linking issue

用其他东西替换图像以验证理论。