1、图片上均匀画黑色矩形
2、给每个矩形写上序号
#include <iostream>
#include <stdio.h>
#include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/ocl.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/calib3d.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/xfeatures2d.hpp"
#include<list>
#include<windows.h>
#include <opencv2/highgui/highgui_c.h>
#include<string>
using namespace cv;
using namespace cv::xfeatures2d;
using namespace std;
void func2()
{
int t_width = 3500;
int t_height = 2474;
int t_width_all = 9;
int t_height_all = 9;
Mat displayMat = cv::Mat(t_height , t_width, CV_8UC3, Scalar(255, 255, 255));
int t_per_width = t_width / t_width_all;
int t_per_height = t_height / t_height_all;
int t_index = 1;
for (int i = 0; i < t_width_all; )
{
for (int j = 0; j < t_height_all;)
{
vector<Point> m1;
m1.push_back(Point(t_per_width * i, t_per_height * j));
m1.push_back(Point(t_per_width * (i + 1), t_per_height * j));
m1.push_back(Point(t_per_width * (i + 1), t_per_height * (j + 1)));
m1.push_back(Point(t_per_width * i, t_per_height * (j + 1)));
fillPoly(displayMat, m1, Scalar(0, 0, 0), 8);
String t_tep_index = to_string(t_index);
while (t_tep_index.length() != 3)
{
t_tep_index = "0" + t_tep_index;
}
putText(displayMat, t_tep_index.c_str(), Point(t_per_width * i+ t_per_width/5, t_per_height * j+ t_per_height/3*2), FONT_HERSHEY_SIMPLEX, 4, Scalar(255, 255, 255), 8, 8);
t_index++;
j += 2;
}
i += 2;
}
cv::imshow("displayMat", displayMat);
imwrite("D:\\11.jpg", displayMat);
cv::waitKey(0);
}
int main()
{
func2();
return 0;
}
效果如下: