c++批量读取一个文件夹中的所有照片
读取一个文件夹中的所有图片,对图像进行操作之后,将操作后的图片存储到一个文件夹中;
_findfirst返回的参数是intptr_t类型的,定义成long类型的,程序会报错。
int main(int argc, char **argv) { if (argc != 2) { std::cout << "Usage: images file path error" << std::endl; } struct _finddata_t file; intptr_t If; std::string path,tempPath; //遍历文件夹中的所有图片 path = path.assign(argv[1]); //文件的路径 tempPath = path.assign(argv[1]); if ((If = _findfirst(path.append("\*").c_str(), &file)) == -1) //不加*也会报错 { std::cout << "Not find image file" << std::endl; } else { while (_findnext(If, &file) == 0) { std::cout << "file name: " << path.substr(0, path.length() - 1) << file.name << std::endl; cv::Mat srcImage = cv::imread(tempPath + "\" + file.name, 0);//第一个图片路径..是打不开的 if (!srcImage.data) { printf("picture read error"); continue; } cv::Mat vecImage(srcImage.rows, srcImage.cols, CV_8UC3, cv::Scalar::all(0)); /* 对图像进行处理操作 */ std::string resFiles = "resluts/"; //将矢量化图片保存在reslut文件中 cv::imwrite(resFiles + file.name, vecImage); // 遍历所有图片并写出 } } _findclose(If); system("PAUSE"); return 0; }
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了