一,OpenCV 相机标定中棋盘格图像要点
1,棋盘格的内部交点个数boardSize:水平方向(board_width, -w=4)和垂直方向(board_height, -h=5)
个人建议:棋盘格的内部交点个数boardSize的w和h的值不要一样以区分旋转。
2,棋盘格格子(正方形)的边长squareSize:(squareSize, -s=0.025):
二,制作棋盘格图像程序
1,程序语言:Python
2,程序依赖项:numpy, opencv-python, screeninfo
3,代码
# pip install screeninfo
#
import numpy as np
import cv2
import screeninfo
def gen_board(board_size, squre_size):
'''
@board_size: board grid num (horz, vert)
@squre_size: board squre length, unit:mm
'''
# ppmm: pixels per mm
ppmm_x = 1920 / 476 # Monitor.width / Monitor.width_mm
ppmm_y = 1080 / 268 # Monitor.height / Monitor.height_mm
# rect_pixels
rect_width = int( ppmm_x * squre_size )
rect_height = int( ppmm_y * squre_size )
img_width = board_size[0] * rect_width
img_height = board_size[1] * rect_height
print("board: grid={0}, img={1}".format((rect_width, rect_height), (img_width, img_height)))
img = np.ones((img_height, img_width, 3), dtype=np.uint8)
pixel = 255
for y in range(0, img_height, rect_height):
colr_grid = [pixel, pixel, pixel]
for x in range(0, img_width, rect_width):
cv2.rectangle(img, (x, y, rect_width, rect_height), colr_grid, -1)
# next col
colr_grid[0] = 255 - colr_grid[0]
colr_grid[1] = 255 - colr_grid[1]
colr_grid[2] = 255 - colr_grid[2]
# next row
pixel = 255 - pixel
cv2.imwrite("board.png", img)
def main():
for m in screeninfo.get_monitors():
print(str(m))
# board size: 9,7
# board squre length=25mm
gen_board((9, 7), 25)
if __name__ == '__main__':
main()
三,示例