我只是试图在棋盘上裁剪任何正方形,为此我使用了在python中不起作用的dewarp。
import scipy
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
import cv2
img = cv2.imread('/home/tejas/Pictures/webcam_chess.png')
approx = find_board_contour(img)
fig = plt.figure(1, (8,8))
grid = ImageGrid(fig, 111, nrows_ncols=(8,8), axes_pad=0.1)
board = dewarp(img,approx)
board = cv2.resize(board, (400,400))
for i in range(8*8):
col = i % 8
row = i // 8
square = get_square(board, row, col)
grid[i].imshow(cv2.cvtColor(square, cv2.COLOR_BGR2RGB))
#fig[i].show()
plt.show()