这里将告诉您[OpenCV-Python案例] 游戏图集分割,具体实现方法:
游戏图集分割程序
本程序只对游戏图集做简单的处理,需要有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)
[OpenCV-Python案例] 游戏图集分割就为您介绍到这里,感谢您关注懒咪学编程c.lanmit.com.
本文地址:https://c.lanmit.com/redianjishu/xunihua/8128.html