#include <iostream>
#include <opencv4/opencv2/opencv.hpp>
#include <string.h>
using namespace cv;
using namespace std;
int main() {
string template_path = "./template.jpg";
string save_path = "./";
Mat template_bg = imread(template_path,IMREAD_REDUCED_COLOR_2);
if(template_bg.empty()){
return -1;
}
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
Mat new_img = template_bg.clone();
stringstream ii;
stringstream jj;
ii << i;
jj << j;
putText(new_img,ii.str(),Point(95,350),cv::FONT_HERSHEY_DUPLEX,2.8,Scalar(15,0,175),8);
putText(new_img,jj.str(),Point(208,350),cv::FONT_HERSHEY_DUPLEX,2.8,Scalar(15,0,175),8);
stringstream file_name_stream;
file_name_stream << save_path << i << j << ".jpg";
string file_name = file_name_stream.str();
imwrite(file_name,new_img);
new_img.release();
cout << file_name << endl;
}
}
return 0;
}
注意文字的样式,目前只支持默认的样式,还未测试中文,还有文字大小和线条粗细参数的调试。