批处理

1、获取文件夹里图片列表

  编写一个bat程序(get route.batbat是避免每次都需要去dos框输入),如下所示:

在你的图片文件夹里,编写一个bat程序(get route.bat,bat是避免每次都需要去dos框输入,那里又不能复制又不能粘贴!),如下所示: 
这里写图片描述

运行bat文件,就会生成如下dat(txt)文件: 
这里写图片描述 


运行bat文件,就会生成txt文件:

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 2、编写程序顺序读取Img.txt文件中的名字,即可一次处理图片。  

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #include <opencv2/opencv.hpp>  
  2. #include <fstream>  
  3.   
  4.   
  5. #include <iostream>  
  6. #include <vector>  
  7. #include <string.h>  
  8. #include <time.h>  
  9. using namespace std;  
  10. using namespace cv;  
[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. int main()  
  2. {  
  3.     string list_file = "F://Img.txt";  
  4.   
  5.     //检测测试样本  
  6.     ifstream fin(list_file); //打开记录样本名的文件  
  7.     //ifstream fin(person_neg_test_file); //打开记录样本名的文件  
  8.   
  9.     char img_name[256]; //存储文件名  
  10.     string path;   
  11.     int sample_count = 0;  
  12.   
  13.     while(!fin.eof())  
  14.     {  
  15.   
  16.         memset(img_name, '/0', 256*sizeof(char));    
  17.         fin>>img_name;  
  18.         int len = strlen(img_name);  
  19.         if (len<=3)  
  20.         {  
  21.             break;  
  22.         }  
  23.         string tempStr = img_name;    
  24.         path = list_file.substr(0,list_file.find_last_of("/")+1) + tempStr;  
  25.   
  26.         //读取图像  
  27.         cv::Mat img = cv::imread(path);    
  28.         Mat grayImg;  
  29.   
  30.         if (img.data)  
  31.         {  
  32.             //resize(img,img,Size(32,32));  
  33.             cvtColor(img,grayImg,CV_BGR2GRAY);  
  34.             imwrite(path,grayImg);  
  35.             imshow("img",grayImg);  
  36.         }  
  37.   
  38.     }     
  39.   
  40.   
  41.     return 0;   
  42. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值