C++之opencv将图片批量改成灰度图

来源:互联网 发布:测试工具 python 编辑:程序博客网 时间:2024/06/12 18:34
#include <opencv2\opencv.hpp>#include <iostream>#include <string>using namespace std;using namespace cv;int main(){try{for (int i = 1408; i <= 1408; i++){char str[10];char c[100] = "1\\";string source = strcat(c, strcat(itoa(i, str, 10), ".jpg"));Mat src_mat = imread(source);Mat gray_mat;cvtColor(src_mat, gray_mat, CV_BGR2GRAY);char str2[10];char c2[100] = "fq\\";cvSaveImage(strcat(c2, strcat(itoa(i, str2, 10), ".jpg")), &(IplImage(gray_mat)));imshow("原图", src_mat);imshow("灰度图", gray_mat);//waitKey();cout << "Hit enter to process the next image..." << endl;cin.get();}}catch (exception& e){cout << "\nexception thrown!" << endl;cout << e.what() << endl;}return 0;}

0 0