C++ VS OpenCV 提示:(!_src.empty()) in cv::cvtColor 但是路径没问题 求解决!

问题:

图片说明

网上搜索了一遍,都是说路径问题,我特意修改到D盘下,还是会报错。

#include<iostream>
#include <fstream>

#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

using namespace std;
using namespace cv;

int main()
{
    const char character[] = "@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\\|()1{}[]?-_+~<>i!lI;:,\"^`'. ";

    //const char * img_path = R"(‪D:\1.jpg)";
    const char* txt_path = R"(D:\txt.txt)";

    Mat img = imread("D://1.jpg");
    Mat gray_img;
    cvtColor(img, gray_img, COLOR_RGB2GRAY);

    string str;
    for (int y = 0; y < gray_img.rows; y++)
    {
        for (int x = 0; x < gray_img.cols; x++)
        {
            int grayVal = (int)gray_img.at<uchar>(y, x);
            int index = 69.0 / 255.0 * grayVal;
            str += character[index];
        }
        str += "\r\n";
    }


    ofstream outStream;
    outStream.open(txt_path);
    outStream << str << endl;
    outStream.close();

    return 0;
}

现在完全不知道问题出在哪里?
配置OpenCV时,我认真校对了3遍,应该是不会出问题。

查看全部
weixin_44983545
Lv.Twelve.
2020/06/26 11:45
  • c++
  • 点赞
  • 收藏
  • 回答
    私信

1个回复