sanmaozhao
2020-01-02 14:56:45 +08:00
简单粗暴,从左上角开始穷举就行了。用 python 简单写了一个,最后找到的是 75*67:
import numpy as np
import cv2
import math
def is_same(a,b):
difference = cv2.subtract(a, b)
return not np.any(difference)
img = cv2.imread("nuSEXUkVgtTa6Md.png")
# 先找纵向
for i in range(1, img.shape[0]//2):
img_pattern = img[0:i, :]
# 按现有的高度平铺成与原始图像等大
img_tile = np.tile(img_pattern, (math.ceil(img.shape[0]/i),1,1))
img_tile = img_tile[0:img.shape[0],:]
if is_same(img_tile,img):
break
# 再找横向
for j in range(1, img.shape[1]//2):
img_pattern = img[:, 0:j]
img_tile = np.tile(img_pattern, (1,math.ceil(img.shape[1]/j),1))
img_tile = img_tile[:,0:img.shape[1]]
if is_same(img_tile,img):
break
print(i,j)
cv2.imshow("img_pattern", img[0:i, 0:j])
cv2.waitKey(0)
cv2.destroyAllWindows()