Last active
December 28, 2016 07:22
-
-
Save udaya1223/fa4212f07f6aa80188d309d601084953 to your computer and use it in GitHub Desktop.
Make a chessboard pattern using OpenCV for camera calibration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make a chessboard pattern given the num. of rows & cols, square size in pixels, and square colors | |
void crvlMakeChessboardPattern(Mat &outChessboard, int inRows, int inCols, int inSquareSize = 100, Scalar color1 = CV_RGB(0, 0, 0), Scalar color2 = CV_RGB(255, 255, 255)){ | |
CV_Assert(inRows > 1 && inCols > 1); | |
CV_Assert(inSquareSize > 0); | |
int chessboardImgCols = inCols*inSquareSize; | |
int chessboardImgRows = inRows*inSquareSize; | |
outChessboard = Mat(chessboardImgRows, chessboardImgCols, CV_8UC3, Scalar(0, 0, 0)); | |
for (size_t rows = 0, rowNum = 0; rows < chessboardImgRows; rows += inSquareSize, rowNum++) | |
{ | |
for (size_t cols = 0, colNum = 0; cols < chessboardImgCols; cols += inSquareSize, colNum++) | |
{ | |
Rect rec(cols, rows, inSquareSize, inSquareSize); | |
if ((rowNum + colNum) % 2 == 0) | |
rectangle(outChessboard, rec, color1, -1, 8); | |
else | |
rectangle(outChessboard, rec, color2, -1, 8); | |
} | |
} | |
} | |
int main(){ | |
Mat chessboardImg; | |
crvlMakeChessboardPattern(chessboardImg, 6, 8); | |
imshow("Chessboard1", chessboardImg); | |
imwrite("Chessboard1.bmp", chessboardImg); | |
crvlMakeChessboardPattern(chessboardImg, 5, 7, 200, CV_RGB(255,0,0), CV_RGB(0,0,255)); | |
imshow("Chessboard2", chessboardImg); | |
imwrite("Chessboard2.bmp", chessboardImg); | |
waitKey(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment