Herr Song 2019-03-07 11:15 采纳率: 0%
浏览 467
已结题

opencv批量处理图片出现警告

1.代码如下

#include<iostream>
#include<time.h>
#include<opencv2/opencv.hpp>
#include<fstream>

using namespace std;
using namespace cv;

void main()
{
    ifstream file("d:/filelist.txt");

    int img_index = 0;

    while (!file.eof())
    {
        char txt_cont[24];
        file.getline(txt_cont,24);

        char img_file[24],save_file[24];

        sprintf(img_file, "d:/pic2/%s", txt_cont);
        sprintf(save_file, "d:/pic3/%d.jpg", img_index);

        Mat src = imread(img_file);
        Mat crs;
        cvtColor(src,crs,CV_RGB2GRAY);
        img_index++;

        imwrite(save_file,crs);
    }

}

运行完出现了如下警告

图片说明
这是什么意思,该怎么办啊?

2第二种批量处理代码如下

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using namespace cv;
using namespace std;
int main() 
{
    std::string pattern_jpg = "D:/pic2/*.png";
    std::string savefile="D:/pic3";
    std::vector<cv::String> image_files;
    cv::glob(pattern_jpg, image_files);

    for (unsigned int frame = 0; frame < image_files.size(); ++frame) //image_file.size()代表文件中总共的图片个数
    {
        Mat image = cv::imread(image_files[frame]);
        Mat dst;
        cvtColor(image,dst,CV_RGB2GRAY);
        imshow("1",dst);
        imwrite(savefile,dst);

        waitKey(30);
    }


}

出现了相同警告,请问该如何修改?
谢谢。

  • 写回答

1条回答

  • yxdmyf 2019-03-15 10:31
    关注

    文件路径应该是"\"而不是“/"吧。而且字符串中要注意转义符的问题”D:\pic2\*.png"。
    可能跟这个有关

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用