from cv2 import cv2 as cv
import numpy as np
chess_size = 512
unit = int(chess_size / 8)
chess_shape = (chess_size,chess_size)
chess = np.ones((chess_shape),dtype=np.uint8)
print(chess.shape)
for i in range(8):
for j in range(8):
#判斷第幾行第一格為黑或白
if i % 2 == 0:
#判斷是否為第一格
if j % 2 == 0:
chess[i*unit:(i+1)*unit,j*unit:(j+1)*unit] = 0
elif j % 2 == 1:
chess[i*unit:(i+1)*unit,j*unit:(j+1)*unit] = 255
elif i % 2 == 1:
#判斷是否為第一格
if j % 2 == 0:
chess[i*unit:(i+1)*unit,j*unit:(j+1)*unit] = 255
elif j % 2 == 1:
chess[i*unit:(i+1)*unit,j*unit:(j+1)*unit] = 0
#cv.imshow('chess',chess)
#cv.waitKey()
#cv.destroyAllWindows()
cv.imwrite('chess.png',chess)