????????中科院好像把這個(gè)數(shù)據(jù)集從官網(wǎng)上撤掉了?我真的找遍全網(wǎng)豺旬,總算是找到了這個(gè)數(shù)據(jù)集,現(xiàn)在分享給大家柒凉。共六個(gè)文件族阅,分別是CASIA-HWDB1.0訓(xùn)練集和測試集、CASIA-HWDB1.1訓(xùn)練集和測試集膝捞、CASIA-Competition數(shù)據(jù)集還有一張申請表坦刀。不過我看大多數(shù)人都是把前四個(gè)文件合并起來當(dāng)做訓(xùn)練集,用Competition那個(gè)做測試集的绑警∏筇【注:2019年春節(jié)期間數(shù)據(jù)集的官網(wǎng)打不開,現(xiàn)在已經(jīng)可以正常訪問了】
下載鏈接:https://pan.baidu.com/s/1jyeo97h_PhWsFS4ngakwbw
????????還缺一個(gè)CASIA-HWDB1.2的數(shù)據(jù)集计盒,是與之前的數(shù)據(jù)集類別不重合的渴频,我沒找到,要是誰有這個(gè)數(shù)據(jù)就在下邊評論吧北启,謝謝卜朗!
????????順便一提,CASIA-HWDB的官網(wǎng)可以用網(wǎng)頁快照打開咕村,猜一下原始的下載鏈接场钉,掛在迅雷會員里是可以下載的,不過我發(fā)現(xiàn)下載界面是真的只有1.0和1.1懈涛,并沒有提供1.2的下載逛万,好奇怪呀......可能只能申請吧。
地址:http://web.archive.org/web/20180621154922/http://www.nlpr.ia.ac.cn/databases/handwriting/Download.html
????????我還寫了個(gè)Reader類批钠,可以方便地讀取gnt文件宇植,并轉(zhuǎn)換為image-label對得封,歡迎使用。
import struct
from codecs import decode
from scipy.misc import toimage
import numpy as np
import PIL.ImageOps
class Reader:
def load_gnt_file(self, filename):
"""
Load characters and images from a given GNT file.
:param filename: The file path to load.
:return: (image: Pillow.Image.Image, character) tuples
"""
with open(filename, "rb") as f:
while True:
packed_length = f.read(4)
if packed_length == b'':
break
length = struct.unpack("<I", packed_length)[0]
raw_label = struct.unpack(">cc", f.read(2))
width = struct.unpack("<H", f.read(2))[0]
height = struct.unpack("<H", f.read(2))[0]
photo_bytes = struct.unpack("{}B".format(height * width), f.read(height * width))
label = decode(raw_label[0] + raw_label[1], encoding="gb2312")
image = toimage(np.array(photo_bytes).reshape(height, width))
yield image, label
def read_gnt_image(self, path):
data = self.load_gnt_file(path)
data_list = []
while True:
try:
image, label = next(data)
image = image.resize((32, 32)) # 圖像縮放指郁,根據(jù)自己的需求修改
image = PIL.ImageOps.invert(image) # 圖像反色忙上,根據(jù)自己的需求修改
data_list.append((image, label))
except StopIteration:
break
return data_list
????????大概這樣使用
import os
reader = Reader()
dirs = ['database/HWDB1.1/', 'database/HWDB1.0/'] # 改成你的目錄
data_list = []
for dir_path in dirs:
files = os.listdir(dir_path)
length = len(files)
for index, file in enumerate(files):
file_path = dir_path + file
data_list.extend(reader.read_gnt_image(file_path))
sys.stdout.write('\r>> Dealing gnt file %d/%d' % (index, length))
sys.stdout.flush()
sys.stdout.write('\n')
print(len(data_list))