基于OpenCV的MNIST手写体分类
简介
MNIST 数据集来自美国国家标准与技术研究所, National Institute of Standards and Technology (NIST).
训练集 (training set) 由来自 250 个不同人手写的数字构成, 其中 50% 是高中学生, 50% 来自人口普查局 (the Census Bureau) 的工作人员. 测试集(test set) 也是同样比例的手写数字数据.
它的训练集有6万项数据,而测试集有1万项数据(其中前5000个来自最初NIST项目的训练集,后5000个来自最初NIST项目的测试集)。在官方网站上,这些数据以4个gz压缩包的方式提供下载:
实验要求
采用SVM实现实现MNIST手写体分类,数据下载链接在官方网站上;上传源码和实现结果,语言不限
实验环境
- Pycharm 2019.3 BETA
- Win10 1909
- Python 3.7.0
- OpenCV 4.1.1
- VS 2019
OpenCV的配置
本次实验我选择使用C++的OpenCV实现。所以需要先配置OpenCV环境。
在windows下配置OpenCV是一个技术活,这里引用一下本专业最强的达哥博客,他的博客把windows下配置OpenCV讲解的很详细。
OpenCV的全称是Open Source Computer Vision Library,是一个跨平台的计算机视觉库。
总体概览
-
train-images-idx3-ubyte.gz: training set images (9912422 bytes)
-
train-labels-idx1-ubyte.gz: training set labels (28881 bytes)
-
t10k-images-idx3-ubyte.gz: test set images (1648877 bytes)
-
t10k-labels-idx1-ubyte.gz: test set labels (4542 bytes)
The data is stored in a very simple file format designed for storing vectors and multidimensional matrices. General info on this format is given at the end of this page, but you don’t need to read that to use the data files.
All the integers in the files are stored in the MSB first (high endian) format used by most non-Intel processors. Users of Intel processors and other low-endian machines must flip the bytes of the header.
如上图,这些数据的格式还是比较简单的,上面文件中的所有的数字都是按照MSB(大端)的方式存储的。值得注意的的是,intel处理器是little-endian的。所以在intel处理器上或者其它的little-endian处理器上,必须要进行相应的翻转处理。也就是大端转小端。
那么什么是大小端?
最标准的解释可以是Wiki百科自己学习一下。点击这里去Wiki。可能需要科学访问,或者你可以自行百度&谷歌。
但是我还是“断章取义”一下:
例如,一个多位的整数,按照存储地址从低到高排序的字节中,如果该整数的最低有效字节