1、得到图片的namelist.txt
将所有图片放到一个文件内,建立txt 输入
dir *.jpg/B > namelist.txt
保存好后,修改后缀名为.bat,运行,得到文件夹内所有jpg图片的namelist.(也可以是.png .bmp)
2、在VS中输入以下代码,运行
#include<iostream>
#include<time.h>
#include<fstream>
#include <highgui.h>
using namespace std;
using namespace cv;
int main()
{
ifstream file("C:\\Users\\1031-VIRB0667-2\\namelist.txt");//namelist所在路径,所有路径按需修改
int img_index = 0;
//while (!file.eof())
while (file.peek()!=EOF)
{
char txt_cont[5000];
file.getline(txt_cont, 5000);
char img_file[5000], save_file[5000];
sprintf(img_file, "C:\\Users\\1031-VIRB0667-2\\%s", txt_cont);
printf("crrent path: %s",img_file);
sprintf(save_file, "C:\\Users\\1031-VIRB0667-2\\save\\%d.jpg", img_index);
IplImage *src = cvLoadImage(img_file)