opencv 遍历文件夹里面图像--实现

思路来自http://blog.csdn.net/watkinsong/article/details/9227439,后来,我自己用VS2012+Opencv2.4.8实现了一下,只是没有显示图像。后来,稍微修改了一下,可以显示图像喽,这样就可以批处理指定目录文件夹里面的图像了。

1.head.h头文件

#ifndef _HEAD_H_
#define _HEAD_H_

//OpencvDirTraverse.cpp : Defines the entry point for the console application.
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <vector>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>

#include "opencv\cv.h"
#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"
#include "opencv2\contrib\contrib.hpp"

using namespace std;
using namespace cv;

#endif // !_HEAD_H_


2.main.cpp源文件

#include "head.h"

int main(int argc, char * argv[])
{
	string dir_path = "D:/Test/";
	Directory dir;
	vector<string> fileNames = dir.GetListFiles(dir_path, "*.jpg", false);

	for(int i = 0; i < fileNames.size(); i++)
	{
		string fileName = fileNames[i];
		string fileFullName = dir_path + fileName;
		cout<<"file name:"<<fileName<<endl;
		cout<<"file paht:"<<fileFullName<<endl<<endl;

		//Image processing
		Mat pScr;
		pScr=imread(fileFullName,1); //以文件名命名窗口 
		imshow(fileName,pScr);
		waitKey(1000);


	}

	//system("pause");
	return EXIT_SUCCESS;
}



评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Digital2Slave

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值