批处理人脸检测区域的保存和下采样
来源:互联网 发布:阿里云主机干什么的 编辑:程序博客网 时间:2024/06/03 17:01
花了一晚上时间,终于解决了检测到的人脸区域的保存和下采样,成果如下:
1.可以批处理一个文件夹下的所有图像;
2.利用opencv进行人脸的检测;
3.对检测到的人脸区域进行保存;
4.对人脸图像32*32的下采样保存。
源代码:
#include "cv.h"#include "highgui.h"#include <stdio.h>using namespace cv;#include<iostream> #include<opencv2\opencv.hpp> #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include <math.h> #include <stdio.h> #include <cv.h> #include <highgui.h> #include<io.h> using std::cout;using std::endl;using namespace std;#include <cmath> #include<string.h> #include <iostream> #include <fstream> using namespace std;int main(int argc, char** argv){CvHaarClassifierCascade * pCascade = 0; // the face detectorCvMemStorage * pStorage = 0; // expandable memory bufferCvSeq * pFaceRectSeq; // list of detected facesint ii;// initializationsFILE *fp;char str0[200][100];char str2[200][100];char str3[200][100];int i, n = 0;system("dir /a-d /b E:\\pic\\安以轩\\ >d:\\cam5.txt");fp = fopen("d:\\cam5.txt", "r");while (1){if (fgets(str0[n], 50, fp) == NULL) break;str0[n][strlen(str0[n]) - 1] = '\0'; // 加一个字符串结束符 n++;}n--;fclose(fp);double value_psnr01 = 0;double value_ssim01 = 0;double value_psnr21 = 0;double value_ssim21 = 0;double value_psnr11 = 0;double value_ssim11 = 0;for (i = 0; i < 100; i++){char refColor[200] = "E:\\pic\\安以轩\\";strcat(refColor, str0[i]);IplImage * pInpImg = cvLoadImage(refColor, CV_LOAD_IMAGE_COLOR);pStorage = cvCreateMemStorage(0);pCascade = (CvHaarClassifierCascade *)cvLoad("D:\\opencv\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt.xml", 0, 0, 0);// validate that everything initialized properlyif (!pInpImg || !pStorage || !pCascade){printf("Initialization failed: %s \n",(!pInpImg) ? "didn't load image file" :(!pCascade) ? "didn't load Haar cascade -- ""make sure path is correct" :"failed to allocate memory for data storage");exit(-1);}// detect faces in imagepFaceRectSeq = cvHaarDetectObjects(pInpImg, pCascade, pStorage,1.1, // increase search scale by 10% each pass 3, // drop groups of fewer than three detections CV_HAAR_DO_CANNY_PRUNING, // skip regions unlikely to contain a face cvSize(0, 0)); // use XML default for smallest search scale// create a window to display detected faces//cvNamedWindow("Haar Window", CV_WINDOW_AUTOSIZE);//cv::Mat xMat;// draw a rectangular outline around each detectionfor (ii = 0; ii<(pFaceRectSeq ? pFaceRectSeq->total : 0); ii++){CvRect * r = (CvRect*)cvGetSeqElem(pFaceRectSeq, ii);CvPoint pt1 = { r->x, r->y };CvPoint pt2 = { r->x + r->width, r->y + r->height };CvSize size = cvSize(r->width, r->height);cvSetImageROI(pInpImg, cvRect(r->x, r->y, size.width, size.height));IplImage* pDest = cvCreateImage(size, pInpImg->depth, pInpImg->nChannels);cvCopy(pInpImg, pDest);//cvNamedWindow("ShowImage...", 1); //cvNamedWindow会创建一个显示窗口//cvShowImage("ShowImage...", pDest); //cvShowImage在窗口中显示创建的图像cvResetImageROI(pDest);cvSaveImage(refColor, pDest);cv::Mat pDest1 = imread(refColor);resize(pDest1, pDest1, Size(32, 32), 0, 0, CV_INTER_LINEAR);//imshow("wangjian",pDest1);imwrite(refColor, pDest1);cvRectangle(pInpImg, pt1, pt2, CV_RGB(0, 255, 0), 3, 4, 0);}// display face detections//cvShowImage("Haar Window", pInpImg);//cvWaitKey(0);//cvDestroyWindow("Haar Window");// clean up and release resourcescvReleaseImage(&pInpImg); }if (pCascade) cvReleaseHaarClassifierCascade(&pCascade);if (pStorage) cvReleaseMemStorage(&pStorage);return 0;}
0 0
- 批处理人脸检测区域的保存和下采样
- mfc下的人脸检测并保存截图
- 上采样和下采样
- vs下opencv的人脸检测以及qt下dll的封装调用(一、opencv下的人脸检测以及图片的保存)
- 利用OpenCV的级联分类器类CascadeClassifier和Haar特征实现人脸区域的检测
- 视频序列中扣图,在扣下的区域进行人眼检测
- 常用profile工具使用--采样和检测
- 图像的上采样(up-sampling)和下采样(down-sampling)
- 基于Jetsontk1和OpenCV下的人脸检测
- MTCNN批量读取图片进行人脸和关键点检测,并保存检测结果
- 对图像进行上采样和下采样
- 图像金字塔——上采样和下采样
- 图像处理学习笔记1 下采样和上采样
- opencv检测人脸并将检测到的人脸图像保存
- 多边形检测区域的缩放
- 特定区域的动作检测
- 上采样 下采样
- 信号的采样和量化
- PL/SQL美化规则文件详解
- Android开发:shape和selector和layer-list的(详细说明) .
- jar包中读取文件及其内容
- wps如何打开文档的目录
- Android优化学习篇一:NDK的那些事儿
- 批处理人脸检测区域的保存和下采样
- JDBC连接数据库操作含连接前后台
- 虚拟视点图像的生成009
- [leetcode][tree][dfs] Balanced Binary Tree
- context和getApplicationContext()介绍
- 新的开始
- Rails4 使用postgreSQL做数据库
- 第九周 项目四 我的向量类
- 字符串相似度算法