def moveToTopLeft(img): ret = [] height, width = img.shape moveY = 0 moveX = 0 xp = Util.get_X_Projection(img) yp = Util.get_Y_Projection(img) for i in range(len(xp) - 1): if(xp[i] > 0 and xp[i + 1] > 0): moveY = i break for i in range(len(yp) - 1): if(yp[i] > 0 and yp[i + 1] > 0): moveX = i break #print(moveX) #print(moveY) target = np.zeros((height, width), dtype=np.int8) for y in range(moveY, height): for x in range(moveX, width): target[y - moveY, x - moveX] = img.item(y, x) #Util.printCV2Image(target) ''' 在这里进行wrap变换应该是最佳的 ''' target = Util.copyOneImg(target, (height, width)) return Util.wrap(target)