@chenbiaolong
2015-08-25T06:03:42.000000Z
字数 1560
阅读 1675
未分类
收集了3700多个常用汉字的样本,每一个字有20种字体。
TrainData目录下有两个文件夹:ChineseData 和 mnisten。
ChineseData主要存放中文样本的图片数据,其中text2image.py
是生成训练样本的python程序,fonts是字体文件,包含了windows的20种汉字字体。ChineseData/data目录存放具体的汉字图片,一共有3754个汉字,每一个汉字对应一个整形的序号,汉字与序号之间的对应关系存放在该目录下的map.txt中。
ChineseData目录下的train_images.idx3
,train_labels.idx1
文件根据idx的数据格式将所有的汉字图像文件转换成二进制格式存放,train_images.idx3
存放图片数据,train_labels.idx1
存放标识数据。
mnisten目录存放将图片文件转换成idx格式文件的程序。mnist的数据介绍点击这里了解。由于汉字的种类比较多,因此汉字的idx文件格式和mnist不大一样,进行的相应修改。
TRAINING SET LABEL FILE (train-labels-idx1):
offset | type | value | description |
---|---|---|---|
0000 | 32 bit integer | 0x00000801(2049) | magic number (MSB first) |
0004 | 32 bit integer | 75080 | number of items |
0008 | uint16_t | ?? | label |
0009 | uint16_t | ?? | label |
..... | |||
xxxx | uint16_t | ?? | label |
The labels values are 0 to 3753.
TRAINING SET IMAGE FILE (train-images-idx3):
offset | type | value | description |
---|---|---|---|
0000 | 32 bit integer | 0x00000803(2051) | magic number (MSB first) |
0004 | 32 bit integer | 75080 | number of images |
0008 | 32 bit integer | 64 | number of rows |
00012 | 32 bit integer | 64 | number of columns |
0016 | unsigned byte | ?? | pixel |
..... | ... | ... | ... |
xxxx | unsigned byte | ?? | pixel |
http://source.jd.com/app/CharacterRecognition/tree/master/include
中的mnist_parser.h
包含了解析函数
可用下面函数进行测试
void main{
string labelFile = "E:\\JDSource\\TrainData\\ChineseData\\train_labels.idx1";
string imageFile = "E:\\JDSource\\TrainData\\ChineseData\\train_images.idx3";
std::vector<label_t> train_labels;
std::vector<vec_t> train_images;
parse_mnist_labels(labelFile, &train_labels);
parse_mnist_images(imageFile, &train_images);
Mat testMat;
std::cout << train_labels[0] << std::endl;
VecToMat(train_images[0], 64,64,testMat);
cv::imshow("test", testMat);
while(cv::waitKey()!='q') {
}
}