opencv 画黑色矩形,并写上序号

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;
}

效果如下:
请添加图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值