-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChessBoard.py
45 lines (40 loc) · 1.41 KB
/
ChessBoard.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
import cv2 as cv
import numpy as np
class CalibBoard():
def __init__(self):
self.partternSize=None
self.squareSize=None
class ChessBoard():
def __init__(self):
self.partternSize=(11,8)
self.squareSize=2.5
self.printSize=(29.7,21)
self.dpi=96
def create(self,parternSize,squareSize,dpi,imageSize):
self.partternSize = parternSize
self.squareSize = squareSize
self.printSize = imageSize
self.dpi = dpi
return self.print()
def print(self):
dpi=self.dpi/2.54
suqrelen=int(dpi*self.squareSize)
imageSize=(int(self.printSize[0]*dpi),int(self.printSize[1]*dpi))
board=(imageSize[0]-suqrelen*self.partternSize[0],imageSize[1]-suqrelen*self.partternSize[1])
board=(board[0]//2,board[1]//2)
chessBoard=np.array(np.zeros((imageSize[1],imageSize[0]),'uint8'))
chessBoard[:]=255
flag=1
for i in range(0,self.partternSize[0]):
flag=0 if flag else 1
for j in range(flag,self.partternSize[1],2):
x=(i*suqrelen+board[0],(i+1)*suqrelen+board[0])
y=(j*suqrelen+board[1],(j+1)*suqrelen+board[1])
chessBoard[y[0]:y[1],x[0]:x[1]]=0
return chessBoard
if __name__ == '__main__':
a=ChessBoard()
b=a.create()
cv.imshow('a',b)
cv.imwrite('C:\\Users\\w\\Desktop\\chssboard.png',b)
cv.waitKey()