rt.使用了python3.5+numpy+cv2(opencv)
考虑以下应用场景:首先,我们有一个盟军关卡,想要截一张关卡的全景图.常规的做法自然是分别截图然后使用ps等软件拼接.但是,由于楼主闲得蛋疼,所以决定用脚本来做这件事.
为了方便起见,我把游戏内分辨率调到了3840*2160,这样对于绝大多数关卡,只需要截左上左下右上右下四张图,就可以拼出完整的地图.
接下来的问题就很容易解决了,我们有四张相同尺寸的图片,并且知道目标图片的尺寸(通常情况下,目标图片的尺寸就等于关卡y64图片的尺寸,可以解包y64文件查看),只需要计算一下截取图片的哪些部分就可以了.(小学级别的加减法....)
下面的例子中,我选择了X22的地图,DO3.y64.(地图尺寸5004*2930 单位:像素)
(ul ur bl br 分别对应左上右上左下右下的图片)- import numpy as np
- import cv2
- tg=[2930,5004]
- ul = cv2.imread('ul.BMP')
- ur = cv2.imread('ur.BMP')
- bl = cv2.imread('bl.BMP')
- br = cv2.imread('br.BMP')
- h1_matrix = np.zeros((ul.shape[0], tg[1], 3), np.uint8)
- h1_matrix[0:ul.shape[0],0:ul.shape[1]]=ul
- h1_matrix[0:ul.shape[0],ul.shape[1]:tg[1]]=ur[0:ur.shape[0],2*ur.shape[1]-tg[1]:ur.shape[1]]
- h2_matrix = np.zeros((ul.shape[0], tg[1], 3), np.uint8)
- h2_matrix[0:bl.shape[0],0:bl.shape[1]]=bl
- h2_matrix[0:bl.shape[0],bl.shape[1]:tg[1]]=br[0:br.shape[0],2*br.shape[1]-tg[1]:br.shape[1]]
- f_matrix = np.zeros((tg[0], tg[1], 3), np.uint8)
- f_matrix[0:h1_matrix.shape[0],0:h1_matrix.shape[1]]=h1_matrix
- f_matrix[h1_matrix.shape[0]:tg[0],0:h1_matrix.shape[1]]=h2_matrix[2*h2_matrix.shape[0]-tg[0]:h2_matrix.shape[0],0:h2_matrix.shape[1]]
- cv2.imwrite("tg0.bmp",f_matrix)
复制代码 |