免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 发帖

[新创意] 一个然并卵的图片拼接脚本

rt.使用了python3.5+numpy+cv2(opencv)
考虑以下应用场景:首先,我们有一个盟军关卡,想要截一张关卡的全景图.常规的做法自然是分别截图然后使用ps等软件拼接.但是,由于楼主闲得蛋疼,所以决定用脚本来做这件事.
为了方便起见,我把游戏内分辨率调到了3840*2160,这样对于绝大多数关卡,只需要截左上左下右上右下四张图,就可以拼出完整的地图.
接下来的问题就很容易解决了,我们有四张相同尺寸的图片,并且知道目标图片的尺寸(通常情况下,目标图片的尺寸就等于关卡y64图片的尺寸,可以解包y64文件查看),只需要计算一下截取图片的哪些部分就可以了.(小学级别的加减法....)

下面的例子中,我选择了X22的地图,DO3.y64.(地图尺寸5004*2930 单位:像素)
(ul ur bl br 分别对应左上右上左下右下的图片)
  1. import numpy as np
  2. import cv2


  3. tg=[2930,5004]


  4. ul = cv2.imread('ul.BMP')
  5. ur = cv2.imread('ur.BMP')
  6. bl = cv2.imread('bl.BMP')
  7. br = cv2.imread('br.BMP')

  8. h1_matrix = np.zeros((ul.shape[0], tg[1], 3), np.uint8)
  9. h1_matrix[0:ul.shape[0],0:ul.shape[1]]=ul
  10. 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]]

  11. h2_matrix = np.zeros((ul.shape[0], tg[1], 3), np.uint8)
  12. h2_matrix[0:bl.shape[0],0:bl.shape[1]]=bl
  13. 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]]


  14. f_matrix = np.zeros((tg[0], tg[1], 3), np.uint8)
  15. f_matrix[0:h1_matrix.shape[0],0:h1_matrix.shape[1]]=h1_matrix
  16. 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]]

  17. cv2.imwrite("tg0.bmp",f_matrix)
复制代码


Do you know what your fate is?
And are you trying to shake it?

原始图片尺寸太大,不上传了,只发一下最终效果图片.
(微博图床还是不能用...郁闷)


Do you know what your fate is?
And are you trying to shake it?

TOP

返回列表 回复 发帖