制作眼睛样本
来源:互联网 发布:龙霸网络电视 编辑:程序博客网 时间:2024/04/30 06:00
#include <windows.h>#include <stdio.h>#include <string>#include <vector>#include <iostream>#include <fstream>#include "cv.h"#include "highgui.h"#include "cxcore.h"using namespace std; bool Drawing=false;//标记鼠标响应IplImage *temp;//存放在鼠标响应后的图IplImage *src;//存放原图vector<CvRect> boxVector;//存放在图上框出的框CvRect box;//每一个框,也可以不用全局变量// 深度优先递归遍历目录中所有的文件BOOL DirectoryList(const string &Path,vector<string> &file_lists,vector<string> &file_names){WIN32_FIND_DATA FindData;HANDLE hError;int FileCount = 0;string FilePathName;// 构造路径FilePathName=Path;FilePathName=FilePathName+ "\\*.*";//取文件下所有文件hError = FindFirstFile(FilePathName.c_str(), &FindData);if (hError == INVALID_HANDLE_VALUE){printf("搜索失败!");return 0;}while(::FindNextFile(hError, &FindData)){string FullPathName;// 过虑.和..if (strcmp(FindData.cFileName, ".") == 0 || strcmp(FindData.cFileName, "..") == 0 ){continue;}// 构造完整路径FullPathName=Path+FindData.cFileName;FileCount++;file_lists.push_back(FullPathName);file_names.push_back(FindData.cFileName);if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){printf("<Dir>");DirectoryList(FullPathName,file_lists,file_names);}}return 0;}void Mouse_Call_Back(int event,int x,int y,int flags,void *param) { if(event==CV_EVENT_LBUTTONDOWN) { box.x=x;box.y=y;box.width=0;box.height=0;Drawing=true;//按下左键画图标志记为真}else if(event==CV_EVENT_MOUSEMOVE) {if(Drawing==true){cvCopy(src,temp);box.width=abs(x-box.x); box.height=abs(y-box.y); CvPoint pt1,pt2;pt1.x=box.x;pt1.y=box.y;pt2.x=x;pt2.y=y;cvDrawRect(temp,pt1,pt2,cvScalar(0,255,0));cvShowImage("pic",temp);}} else if(event==CV_EVENT_LBUTTONUP){if((box.width>0)&&(box.height>0)){boxVector.push_back(box);}Drawing=false;}} int main(){IplImage *dst;//抠的图vector<string> file_lists;vector<string> file_names;ifstream OrigImgPath;ifstream EyePosPath;ifstream NewImgPath;ofstream eyePos;//存放眼睛坐标的txt文件string OIPath;//存放原图的文件夹string NIPath;string EPPath;OrigImgPath.open("OrigImgPath.txt");//原图文件夹OrigImgPath>>OIPath;OrigImgPath.close();EyePosPath.open("EyePositionPath.txt");EyePosPath>>EPPath;EyePosPath.close();NewImgPath.open("NewImgPath.txt");NewImgPath>>NIPath;NewImgPath.close();DirectoryList(OIPath,file_lists,file_names);int len=file_lists.size();cout<<"共有"<<len<<"张图片!"<<endl;for(size_t i=0;i<file_lists.size();i++){string picName(file_names[i],0,file_names[i].size()-4);string EyePos;EyePos=EPPath+picName+".txt";eyePos.open(EyePos.c_str());src = cvLoadImage(file_lists[i].c_str(),1); temp=cvCloneImage(src);cvNamedWindow("pic");cvShowImage("pic",src);cout<<"处理第"<<i<<"张图..."<<endl;cvSetMouseCallback("pic",Mouse_Call_Back,0);int key;while(1){key=cvWaitKey(0);if(key==27) {cvDestroyWindow("pic");cvReleaseImage(&src);cvReleaseImage(&temp);eyePos.close();return 0;}break;}for(int j=0;j<boxVector.size();j++){eyePos << boxVector[j].x<< " " << boxVector[j].y << " "<< boxVector[j].width << " "<< boxVector[j].height << endl;cvSetImageROI(src,boxVector[j]);dst=cvCreateImage(cvSize(boxVector[j].width,boxVector[j].height),src->depth,src->nChannels);dst=cvCloneImage(src);char IndexN[5];itoa(j,IndexN,10);string smallImage=picName+"_"+IndexN+".jpg";string savePath;savePath=NIPath+smallImage;//新图像的绝对路径加文件名cvSaveImage(savePath.c_str(),dst);cvResetImageROI(src);cvReleaseImage(&dst);}while(!boxVector.empty()){boxVector.pop_back();}eyePos.close();}cvDestroyWindow("pic");cvReleaseImage(&src);cvReleaseImage(&temp);cout<<"图片处理结束!"<<endl;return 0;}
0 0
- 制作眼睛样本
- Face++ 制作样本
- 训练样本集的制作
- HOG提取训练检测+样本制作
- 开篇-HOG提取训练检测+样本制作
- 开篇-HOG提取训练检测+样本制作
- 制作theano可用的训练样本
- 开篇-HOG提取训练检测+样本制作
- theano 训练样本制作(二)
- 制作theano可用的训练样本
- 【opencv】训练样本的批量制作
- 样本册的制作思路设计
- 3D MAX眼睛贴图制作过程
- Flex制作的swf加载时的设置样本
- HOG 行人检测 学习体会(如何制作训练样本)
- HOG 行人检测 学习体会(如何制作训练样本)
- HOG+SVM 自己制作训练样本+训练分类器
- HOG 行人检测 学习体会(如何制作训练样本)
- 素数算法
- java.lang.NumberFormatException: null
- 如何让软文推广效果最大化
- TCP连接、Http连接与Socket连接
- 南阳理工OJ_题目50 爱摘苹果的小明
- 制作眼睛样本
- Cracking The Coding Interview 1.4
- 【NOI2002】贪吃的九头龙
- Codeforces 52B Right Triangles
- 关于tomcat启动后,直接访问本地地址默认的页面
- Ext.require的作用
- JQuery中$.ajax()方法参数详解
- WebView注入Java对象注意事项,4.2之前版本,4.2之后的区别
- 在配置oem时遇到“DBSNMP 用户名或密码无效”时