简介
将文件夹下的图片批量灰度化:
// Demon.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <opencv2\opencv.hpp>
#include <windows.h>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
string dir_path = "F:\\objectmarker\\todo\\";
char outDirName[50];
Directory dir;
string extenttype = "*.bmp";
vector<string> fileNames = dir.GetListFiles(dir_path, extenttype, false);
for (int item = 0; item < fileNames.size(); item++)
{
//get image name
string fileName = fileNames[item];
string fileFullName = dir_path + fileName;
//cout << "File name:" << fileName << endl;
cout << "Full path:" << fileFullName << endl;
cv::Mat img = cv::imread(fileFullName);
Mat grayImg;
cvtColor(img, grayImg, CV_BGR2GRAY);
/*cv::imshow("gray", grayImg);
cv::waitKey();*/
sprintf_s(outDirName, "F:\\objectmarker\\todo\\gray\\%08d.bmp", item+3002);
imwrite(outDirName, grayImg);
}
return 0;
}