ORL Faces Database介绍

ORL人脸数据集共包含40个不同人的400张图像,是在1992年4月至1994年4月期间由英国剑桥的Olivetti研究实验室创建。

此数据集下包含40个目录,每个目录下有10张图像,每个目录表示一个不同的人。所有的图像是以PGM格式存储,灰度图,图像大小宽度为92,高度为112。对每一个目录下的图像,这些图像是在不同的时间、不同的光照、不同的面部表情(睁眼/闭眼,微笑/不微笑)和面部细节(戴眼镜/不戴眼镜)环境下采集的。所有的图像是在较暗的均匀背景下拍摄的,拍摄的是正脸(有些带有略微的侧偏)。

可以从http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html下载此人脸数据集。

测试代码如下:

#include "funset.hpp"
#include <iostream>
#include <fstream>
#include <vector>
#include <opencv2/opencv.hpp>

int ORLFacestoImage()
{
	const std::string path{ "E:/GitCode/NN_Test/data/database/ORL_Faces/" };
	cv::Mat dst;
	int height, width;

	for (int i = 1; i <= 40; ++i) {
		std::string directory = path + "s" + std::to_string(i) + "/";

		for (int j = 1; j <= 10; ++j) {
			std::string image_name = directory + std::to_string(j) + ".pgm";
			cv::Mat mat = cv::imread(image_name, 0);
			if (!mat.data) {
				fprintf(stderr, "read image fail: %s\n", image_name.c_str());
			}

			//std::string save_image_name = directory + std::to_string(j) + ".png";
			//cv::imwrite(save_image_name, mat);

			if (i == 1 && j == 1) {
				height = mat.rows;
				width = mat.cols;
				dst = cv::Mat(height * 20, width * 20, CV_8UC1);
			}

			int y_start = (i - 1) / 2 * height;
			int y_end = y_start + height;
			int x_start = (i - 1) % 2 * 10 * width + (j - 1) * width;
			int x_end = x_start + width;
			cv::Mat copy = dst(cv::Range(y_start, y_end), cv::Range(x_start, x_end));
			mat.copyTo(copy);
		}
	}

	int new_width = 750;
	float factor = dst.cols * 1.f / new_width;
	int new_height = dst.rows / factor;
	cv::resize(dst, dst, cv::Size(new_width, new_height));
	cv::imwrite("E:/GitCode/NN_Test/data/orl_faces_dataset.png", dst);

	return 0;
}
执行结果如下:



  • 16
    点赞
  • 62
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值