import os
import numpy as np
import struct
from PIL import Image
# data文件夹存放转换后的.png文件
data_dir = './data'
# 路径为存放数据集解压后的.gnt文件
train_data_dir = os.path.join(data_dir, 'E:/code/tfrecord_png/HWDB1.1trn_gnt')
test_data_dir = os.path.join(data_dir, 'E:/code/tfrecord_png/HWDB1.1tst_gnt')
def read_from_gnt_dir(gnt_dir=train_data_dir):
def one_file(f):
header_size = 10
while True:
header = np.fromfile(f, dtype='uint8', count=header_size)
if not header.size: break
sample_size = header[0] + (header[1] << 8) + (header[2] << 16) + (header[3] << 24)
tagcode = header[5] + (header[4] << 8)
width = header[6] + (header[7] << 8)
height = header[8] + (header[9] << 8)
if header_size + width * height != sample_size:
break
HWDB1.1数据集.gnt转换成.png
最新推荐文章于 2023-05-10 13:48:04 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)