OpenCV 读取 Cifar 数据集
来源:互联网 发布:windows下svn钩子 编辑:程序博客网 时间:2024/05/22 22:31
欢迎访问人工智能研究网 www.studyai.cn
OpenCV 读取 Cifar 数据集(来自studyai.cn)
Cifar数据集的下载地址[http://www.cs.toronto.edu/~kriz/cifar.html]
下载C语言版本的数据集
CIFAR-10 binary version (suitable for C programs) 162 MB c32a1d4ab5d03f1284b67883e8d87530
程序代码
#include <string>#include <iostream>#include <fstream>#include <vector>#include <opencv2\opencv.hpp>using namespace std;using namespace cv;bool ReadCifar10DataBatch(const string& dir, const string& batchName, size_t imgCount, vector<Mat>& images, vector<int>& labels){ const int PATCH_SIZE = 32; //图像块的尺寸: 32*32 const int N_CHANEL = 3; //通道数 const int LINE_LENGTH = PATCH_SIZE * PATCH_SIZE * N_CHANEL + 1;//以字节为单位 bool isSuccess = false; fstream fs(dir + batchName, ios::in | ios::binary);//以二进制方式读取 if (fs.is_open()) { cout << "成功打开文件: " << batchName << endl; char buffer[LINE_LENGTH]; for (size_t imgIdx = 0; imgIdx < imgCount; imgIdx++) { fs.read(buffer, LINE_LENGTH); int class_label = (int)buffer[0];//类别标签:buffer[0] Mat red_img(32, 32, CV_8UC1, &buffer[1]);//红色通道:buffer[1->1024] Mat green_img(32, 32, CV_8UC1, &buffer[1025]);//绿色通道:buffer[1025->2048] Mat blue_img(32, 32, CV_8UC1, &buffer[2049]);//蓝色通道:buffer[2049->3072] vector<Mat> bgrMats = { blue_img, green_img, red_img };//OpenCV的通道顺序是BGR Mat rgb_img; cv::merge(bgrMats, rgb_img);//RGB通道融合 //将样本和对应的标签加入集合 images.push_back(rgb_img); labels.push_back(class_label); } isSuccess = true; } else { cout << "无法打开文件: " << batchName << endl; isSuccess = false; } fs.close(); return isSuccess;}int main(int argc, char* argv[]){ const string dir = "F:\\cifar-10-binary\\cifar-10-batches-bin\\"; const string class_names[10] = { "airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck" }; const string batch_names[6] = { "data_batch_1.bin", "data_batch_2.bin", "data_batch_3.bin", "data_batch_4.bin", "data_batch_5.bin", "test_batch.bin" }; size_t ImgCountPerBatch = 10000; vector<Mat> images; vector<int> labels; bool success = ReadCifar10DataBatch(dir, batch_names[2], ImgCountPerBatch, images, labels); if (success) { for (size_t imgIdx = 0; imgIdx < images.size(); imgIdx++) { Mat BigImg; cv::resize(images[imgIdx], BigImg, Size(128, 128)); imshow("cifar image", BigImg); cout << "image index: "<<imgIdx<<"---->class label,name :" << labels[imgIdx] << "<->" << class_names[labels[imgIdx]] << endl; cv::waitKey(5); } } system("pause"); return 0;}
1 0
- OpenCV 读取 Cifar 数据集
- CIFAR-10和CIFAR-100数据集读取显示
- CIFAR数据读取
- PyTorch读取Cifar数据集并显示图片
- 第四篇:对cifar-10数据集的读取
- PyTorch读取Cifar数据集并显示图片(转载)
- 用python读取cifar-10与cifar-100图像数据
- 用python读取cifar-10与cifar-100图像数据
- TensorFlow CIFAR-10数据集
- Python3读取深度学习CIFAR-10数据集出现的若干问题解决
- TensorFlow CNN 测试CIFAR-10数据集
- The CIFAR-10 dataset 数据集
- python实现CIFAR-10数据集可视化
- simpleCNN 训练 cifar-10 数据集
- CIFAR-10数据集可视化Python版本
- CIFAR-10数据集可视化二进制版本
- Ubuntu+caffe训练cifar-10数据集
- TensorFlow-CNN CIFAR-10数据集 学习
- 数据库查询 接收
- 【Linux】系统运行级别
- C++ Primer 第五版 部分课后题答案
- HDU_How far away ?
- (找数组中唯一出现两次的数)
- OpenCV 读取 Cifar 数据集
- 三、C++ 复制构造函数
- 使用Colseable接口封装流关闭工具类IOClose
- HDU2068
- C++实验7-最大公约和和最小公倍数
- Hibernate 双向 1 对 1 对象关系映射 —外键关联 下 ,测试 crud
- 视频加载
- laravel5.1框架下的权限控制
- 进程与线程的一个简单解释