[OpenCV-Python案例] 游戏图集分割

你说的曾经没有我的故事 提交于 2019-11-25 17:02:43

游戏图集分割程序

本程序只对游戏图集做简单的处理,需要有json配置文件图集文件

运行环境

  • python 3.6 +

  • opencv-python pip install opencv-python

案例

  • 目录
|--split
|--|--imgs //用于存储分割后的散图
|--|--index.py
|--|--res.json //图集配置文件(以LayaBox的图集为例)
|--|--res.png //图集(以LayaBox的图集为例)
  • index.py
# -*- coding: utf-8 -*-
import json
import cv2
# 读取图集
imgMax = cv2.imread('res.png', cv2.IMREAD_UNCHANGED)
# 读取图集配置文件
with open('res.json', 'r') as load_f:
    load_dict = json.load(load_f)
imgs = load_dict.get('frames')
# 遍历配置并保存散图
for imgName in imgs:
    d = imgs[imgName]
    img = imgMax[d['y']:d['y']+d['h'], d['x']:d['x']+d['w']]
    cv2.imwrite('imgs/' + imgName + '.png', img)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!