• 大小: 16.07MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-31
  • 语言: C/C++
  • 标签:

资源简介

此资源用C++和opencv编写的人脸性别、帽子、眼镜和口罩识别及其颜色识别

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace cv;
using namespace std;

//全部变量
int returnHat returnEye returnMask;
Mat dst_Img1 dst_Img2 dst_Img3;
Mat img_HSV;
Mat img_RGB;
Mat dst_img_HSV1 dst_img_HSV2 dst_img_HSV3;
int lowOrange lowBlock lowYellow lowGreen lowCyan lowBlue lowViolet lowRed LowS LowV lowGray lowWrite;//H值low
int HighOrange HighBlock HighYellow HighGreen HighCyan HighBlue HighViolet HighRed HighS HighV HighGray HighWrite;//H值high
int block_s_low block_s_high gray_s_low gray_s_high write_s_low write_s_high orange_s_low orange_s_high;//部分S值
int block_v_low block_v_high gray_v_low gray_v_high write_v_low write_v_high;
string train_sex_csv train_hat_csv train_glass_csv train_mask_csv;
string test_sex_csv test_hat_csv test_glass_csv test_mask_csv;
int returnSexValue returnHatValue returnGlassValue returnMaskValue;

//使用CSV文件去读图像和标签,主要使用stringstream和getline方法
static void read_csv(const string& filename vector& images vector& labels char separator = ‘;‘) {
std::ifstream file(filename.c_str() ifstream::in);
if (!file) {
string error_message = “No valid input file was given please check the given filename.“;
CV_Error(CV_StsBadArg error_message);
}
string line path classlabel;
while (getline(file line)) {
stringstream liness(line);
getline(liness path separator);
getline(liness classlabel);
if (!path.empty() && !classlabel.empty()) {
images.push_back(imread(path 0));
labels.push_back(atoi(classlabel.c_str()));
}
}
}

//性别的识别
int sex_Rec(string fn_csv string tn_csv)
{
int returnSex;
vector allImages train_images;
vector allLabels train_labels;

vector testImages test_images;
vector testLabels test_labels;


//-------------------------训练集---------------------//
try {
read_csv(fn_csv allImages allLabels);
}
catch (cv::Exception& e) {
cerr << “Error opening file “ << fn_csv << “. Reason: “ << e.msg << endl;
exit(1);
}

for (int i = 0; i < allImages.size(); i++)
equalizeHist(allImages[i] allImages[i]);

int photoTrainNumber = allImages.size();
for (int i = 0; i < photoTrainNumber; i++)
{
train_images.push_back(allImages[i]);
train_labels.push_back(allLabels[i]);
}

//------------------------训练结束---------------------//

//-------------------------测试---------------------------//
try {
read_csv(tn_csv testImages testLabels);
}
catch (cv::Exception& e) {
cerr << “Error opening file “ << fn_csv << “. Reason: “ << e.msg << endl;
exit(1);
}

for (int i = 0; i < testImages.size(); i++)
equalizeHist(testImages[i] testImages[i]);

int photoTestNum = testImages.size();
for (int i = 0; i < photoTestNum; i++)
{
test_images.push_back(testImages[i]);
test_lab

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-05-13 15:50  faceRecognize\
     目录           0  2017-05-13 15:49  faceRecognize\Debug\
     文件     1187840  2017-05-11 22:21  faceRecognize\Debug\three_test.exe
     文件     2848816  2017-05-11 22:21  faceRecognize\Debug\three_test.ilk
     文件     5902336  2017-05-11 22:21  faceRecognize\Debug\three_test.pdb
     目录           0  2017-05-13 15:50  faceRecognize\three_test\
     文件    14614528  2017-05-13 15:47  faceRecognize\three_test.sdf
     文件         976  2017-05-11 14:24  faceRecognize\three_test.sln
     目录           0  2017-05-13 15:49  faceRecognize\three_test\Debug\
     文件      860532  2017-05-11 22:20  faceRecognize\three_test\Debug\main.obj
     文件        3247  2017-05-11 22:21  faceRecognize\three_test\Debug\three_test.log
     目录           0  2017-05-13 15:49  faceRecognize\three_test\Debug\three_test.tlog\
     文件         752  2017-05-11 22:20  faceRecognize\three_test\Debug\three_test.tlog\cl.command.1.tlog
     文件        9122  2017-05-11 22:20  faceRecognize\three_test\Debug\three_test.tlog\CL.read.1.tlog
     文件         596  2017-05-11 22:20  faceRecognize\three_test\Debug\three_test.tlog\CL.write.1.tlog
     文件        2754  2017-05-11 22:21  faceRecognize\three_test\Debug\three_test.tlog\link.command.1.tlog
     文件        6124  2017-05-11 22:21  faceRecognize\three_test\Debug\three_test.tlog\link.read.1.tlog
     文件         574  2017-05-11 22:21  faceRecognize\three_test\Debug\three_test.tlog\link.write.1.tlog
     文件         184  2017-05-11 22:21  faceRecognize\three_test\Debug\three_test.tlog\three_test.lastbuildstate
     文件      560128  2017-05-11 22:20  faceRecognize\three_test\Debug\vc120.idb
     文件     1339392  2017-05-11 22:20  faceRecognize\three_test\Debug\vc120.pdb
     文件       22532  2017-05-11 18:52  faceRecognize\three_test\main.cpp
     文件          90  2017-05-11 22:25  faceRecognize\three_test\result.txt
     目录           0  2017-05-13 15:49  faceRecognize\three_test\testPicture\
     文件        2807  2017-05-10 14:52  faceRecognize\three_test\testPicture\test.jpg
     文件          24  2017-05-11 08:39  faceRecognize\three_test\test_glass.txt
     文件          24  2017-05-11 08:39  faceRecognize\three_test\test_hat.txt
     文件          24  2017-05-11 08:33  faceRecognize\three_test\test_mask.txt
     文件          24  2017-05-11 22:11  faceRecognize\three_test\test_sex.txt
     文件        4277  2017-05-11 22:23  faceRecognize\three_test\three_test.vcxproj
     文件         945  2017-05-11 14:25  faceRecognize\three_test\three_test.vcxproj.filters
............此处省略1519个文件信息

评论

共有 条评论

相关资源