#include "stdafx.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
#include <iostream>
#include <string>
#include <fstream>
#ifdef _DEBUG
#pragma comment(lib,"lib/opencv_core2411d.lib")
#pragma comment(lib,"lib/opencv_highgui2411d.lib")
#pragma comment(lib,"lib/opencv_imgproc2411d.lib")
#else
#pragma comment(lib,"lib/opencv_core2411.lib")
#pragma comment(lib,"lib/opencv_highgui2411.lib")
#pragma comment(lib,"lib/opencv_imgproc2411.lib")
#endif
using namespace cv;
using namespace std;
int main(int argc, char*argv[])
{
//法一,棋盘格子角点没有强化
int width = 140;//棋盘格宽度
int height = 140;//棋盘格高度
IplImage *src = cvCreateImage(cvSize(980, 1260), IPL_DEPTH_8U, 1);
cvZero(src);
for (int i = 0; i < src->height; i++)
{
for (int j = 0; j < src->width; j++)
{
if ((i / width + j / height) % 2 != 0)
{
src->imageData[i*src->widthStep + j*src->nChannels] = 255;
}
}
}
cvSaveImage("ChessBoard.png", src, 0);
//法2,棋盘格子角点强化
//(1330,1830) lsize=167;上、左边17,打印出来格子25mm
Mat img(1330, 1830, CV_8UC1, Scalar(255));
int toprow = 17;//留出上边
int leftcol =17;//留出左边
int lsize = 167;//棋盘黑格边长
int w= lsize-1;
int step = 2 * w;
for (int i = toprow; i <img.rows - w; i += step)
{
for (int t = 0; t <=w; t++)
{
for (int j = leftcol; j < img.cols - w; j += step)
{
for (int k = 0; k <= w; k++)
{
img.at<uchar>(i + t, j + k) = 0;
}
}
}
if ((i + step) >= img.rows)
break;
for (int t = w; t<=step;t++)
{
for (int j = leftcol; j < img.cols - step; j += step)
{
for (int k = w; k<=step; k++)
{
img.at<uchar>(i + t, j + k) = 0;
}
}
}
}
imwrite("zizhi.png",img);
cvWaitKey(0);
return 0;
}
zhouyelihua**http://blog.youkuaiyun.com/zhouyelihua/article/details/46674191**
http://blog.youkuaiyun.com/loser__wang/article/details/51811347