[C++]读取文件夹中图片,并灰度化

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include "cv.h"
#include "highgui.h"
#include 

using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
	ifstream Test("negatives/infofile.txt");
	string ImgName;//图片名(绝对路径)
	for (int num = 0; getline(Test, ImgName); num++)
	{
		cout << "Processing:" << ImgName << endl;
		Mat src = imread(ImgName);//读取图片
		Mat src_gray;
		//Mat src = imread("lena.jpg");
		if (!src.data)
		{
			return -1;
		}
		cvtColor(src, src_gray, CV_RGB2GRAY);
		stringstream ss;
		string Img1;
		ss << num;
		ss >> Img1;
		Img1 = Img1 + "ImgProcessed.bmp";
		imwrite(Img1, src_gray);
	}
}

 

你可能感兴趣的:(OpenCV)