Lv.Twelve. 2020-06-26 11:45 采纳率: 0%
浏览 1169

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遍,应该是不会出问题。

  • 写回答

2条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样