opencv画棋盘格

  • Post author:
  • Post category:其他


#include <iostream>
#include <opencv2\highgui\highgui.hpp>

using namespace std;
using namespace cv;

Size bord_w_h = { 9, 6 };
int longth = 126;

int kong = 10;

int main()
{
	//int highth_back = 1050, wideth_back = 1050;

	int highth_back = (bord_w_h.height + 1)*longth + 2 * kong;
	int wideth_back = (bord_w_h.width + 1)*longth + 2 * kong;

	Mat matImage = Mat::Mat(highth_back, wideth_back, CV_8UC3, Scalar(255, 255, 255));

	int _w = bord_w_h.width / 2 + 1;

	int _kong = kong + 1;
	for (int j = 0; j < bord_w_h.height + 1; j++)
	{
		for (int i = 0; i < _w; i++)
		{
			if (j % 2 == 0)
			{
				cv::rectangle(matImage, cvPoint(_kong + 2 * i*longth, _kong + j*longth), cvPoint(kong + (2 * i + 1)*longth, kong + (j + 1)*longth), Scalar(0, 0, 0), -1, 1, 0);
			}
			else
			{
				cv::rectangle(matImage, cvPoint(_kong + (2 * i + 1)*longth, _kong + j*longth), cvPoint(kong + (2 * i + 2)*longth, kong + (j + 1)*longth), Scalar(0, 0, 0), -1, 1, 0);
			}
		}
	}

	imshow("matImage", matImage);

	imwrite("1.png", matImage);
	waitKey();
	return 0;
}



版权声明:本文为W_AYF0726原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。