forked from ZYM-PKU/6Don-pen-track
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawchessboard.py
58 lines (48 loc) · 1.89 KB
/
drawchessboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding:utf-8 -*-
import cv2,os
import numpy as np
#指定工作目录
PATH = os.path.dirname(__file__)
os.chdir(PATH)
def generatePattern(CheckerboardSize, Nx_cor, Ny_cor):
'''
自定义生成棋盘
:param CheckerboardSize: 棋盘格大小,此处100即可
:param Nx_cor: 棋盘格横向内角数
:param Ny_cor: 棋盘格纵向内角数
:return:
'''
black = np.zeros((CheckerboardSize, CheckerboardSize, 3), np.uint8)
white = np.zeros((CheckerboardSize, CheckerboardSize, 3), np.uint8)
black[:] = [0, 0, 0] # 纯黑色
white[:] = [255, 255, 255] # 纯白色
black_white = np.concatenate([black, white], axis=1)
black_white2 = black_white
white_black = np.concatenate([white, black], axis=1)
white_black2 = white_black
# 横向连接
if Nx_cor % 2 == 1:
for i in range(1, (Nx_cor+1) // 2):
black_white2 = np.concatenate([black_white2, black_white], axis=1)
white_black2 = np.concatenate([white_black2, white_black], axis=1)
else:
for i in range(1, Nx_cor // 2):
black_white2 = np.concatenate([black_white2, black_white], axis=1)
white_black2 = np.concatenate([white_black2, white_black], axis=1)
black_white2 = np.concatenate([black_white2, black], axis=1)
white_black2 = np.concatenate([white_black2, white], axis=1)
jj = 0
black_white3 = black_white2
for i in range(0, Ny_cor):
jj += 1
# 纵向连接
if jj % 2 == 1:
black_white3 = np.concatenate((black_white3, white_black2)) # =np.vstack((img1, img2))
else:
black_white3 = np.concatenate((black_white3, black_white2)) # =np.vstack((img1, img2))
cv2.imshow('', black_white3)
cv2.imwrite('pattern.jpg', black_white3)
cv2.waitKey(5000)
cv2.destroyAllWindows()
if __name__ == '__main__':
generatePattern(150, 9, 6)