先上原图:
附上调试代码:
# _*_ coding:utf-8 _*_
__author__ = 'admin'
from PIL import Image, ImageDraw, ImageFont
im = Image.open(r'C:\Users\admin\Desktop\1515415644.png')
im.show()
im_pixel = im.load()
width, height = im.size
draw = ImageDraw.Draw(im)
# 变量初始化
# 棋盘重心的横纵坐标
target_x = 0
target_y = 0
# 棋子的匹配域内像素点个数、横纵坐标的和统计
sum_piece_x = 0
count_piece_x = 0
sum_piece_y = 0
count_piece_y = 0
# 棋盘的上顶点/上边缘的像素点个数、横纵坐标的和统计
sum_target_x = 0
count_target_x = 0
sum_target_y = 0
count_target_y = 0
# 棋盘上顶点、下顶点初始化
oberer_pol_x = 0
oberer_pol_y = 0
lower_vertex_x = 0
lower_vertex_y = 0
# 已知棋子重