python cv2 opencv手写一个棋盘格
推荐开源项目:简单的SLAM与机器人教程与编程实践-github
有时候我们需要用棋盘格测试我们写的代码或者用于校准相机。虽然opencv里面有自带的代码。但是了解下如何写一个棋盘格也是有必要的。下图是一个简单的实现。
import cv2
import numpy as np
checker_img = np.zeros((320,320))
block_width = 320//8
black_block = np.full((block_width,block_width),255)
for row in range(8):
for col in range(8):
if (row+col)%2==0:
row_begin = row*block_width
row_end = row_begin+block_width
col_begin = col*block_width
col_end = col_begin+block_width
checker_img[row_begin:row_end,col_begin:col_end] = black_block
cv2.imwrite("checker_board.jpg",checker_img)
cv2.imshow("checker_board",checker_img)
cv2.waitKey(0)
知乎 https://www.zhihu.com/people/yuanmuou/activities