C++批量处理图片并保存

#include 
#include 
#include

using namespace std;
using namespace cv;

int main()
{
   string path = "D:/workspace/PycharmProjects/scripts/mnist/demo/";
   String dest = "D:/workspace/PycharmProjects/scripts/mnist/demo1/";
 
   String savedfilename;
   int len = path.length();
   vector<cv::String> filenames;
   cv::glob(path, filenames);
   for (int i = 0; i < filenames.size(); i++) {
       Mat frame;
       frame = imread(filenames[i],0);
       frame = 255 - frame;   //对每一张图片取反
       savedfilename = dest + filenames[i].substr(len);
       cout << savedfilename << endl;
       imwrite(savedfilename, frame);
      }
   return 0;
}

你可能感兴趣的:(c++)