def centerDigit(img):
xMean,yMean,count = 0,0,0
(x,y) = np.shape(img)
for i in range(x):
for j in range(y):
if img[i][j] == 255:
xMean,yMean,count = (xMean+i),(yMean+j),(count+1)
if count == 0:
return img
xMean,yMean = (xMean / count),(yMean / count)
xDisp,yDisp = (xMean - (x/2)),(yMean - (y/2))
newImg = np.zeros((x,y),np.uint8)
for i in range(x):
for j in range(y):
if img[i][j] == 255:
newImg[i-xDisp][j-yDisp] = 255
return newImg
# Given the cropped out digit, places it on a black background for matching with templates
评论列表
文章目录