#include"opencv2\opencv.hpp"
#include"cv.h"
#include
#include
#include"iostream"
#include"fstream"
#include
#include"highgui.h"
#include"cxcore.h"
#include"time.h"
#include"math.h"
//==============
#include"opencv2/imgproc.hpp"
#include"opencv2/highgui.hpp"
#include"opencv2/ml.hpp"
#include"opencv2/objdetect.hpp"
#include"string"
#include"stdlib.h"
//=========2 14 添加
#include"io.h"
#include
using namespace cv;
using namespace std;
vector
vector
void GetAllFormatFiles(string path, vector
//======add==
int main()
{
string gallery_path = "F:\\image_save\\advance_2";
string probe_path = "F:\\image_save\\new_test";
vector
for (int g = 0; g < gallery_folders.size(); g++) {
vector
for (int f = 0; f < image_list.size(); f++) {
cout << gallery_path + "\\" + gallery_folders.at(g) + "\\" + image_list.at(f) << endl;
string ga = gallery_folders.at(g);
cout << "gallery_folders.at(g): " << ga << endl;
string ss = image_list.at(f);//this is picture number
cout << "image_list.at(f)" << ss << endl;
string filename = gallery_path + "\\" + gallery_folders.at(g) + "\\" + image_list.at(f);
//=========================批次处理图片
Mat srcImage, grayImage;
srcImage = imread(filename);
Mat sizeImage;
double bili = 0.125;
Size dsize = Size(srcImage.cols*bili, srcImage.rows*bili);
resize(srcImage, sizeImage, dsize);
cvtColor(sizeImage, grayImage, CV_BGR2GRAY);
Mat img1 = Mat::zeros(grayImage.size(), CV_8UC1);
Mat dstImage;
int height = grayImage.rows;
int width = grayImage.cols;
dstImage.create(grayImage.size(), grayImage.type());
GaussianBlur(grayImage, dstImage, Size(5, 5), 1);
cout << "高度:" << height << endl;
cout << "宽度:" << width << endl;
//Mat dst;
int blockSize = 5;
int constValue = 10;
const int maxVal = 255;
//0 ADPTIVE_THRESH_MEAN_C 1: ADAPTIVE_THRESH_GAUSSIAN_C
//thresold type 0 THRESH_BINARY 1:THRESH_BINARY_INV
int adaptiveMethod = 0;
int thresholdType = 0;
// cv::adaptiveThreshold(dstImage,img1,maxVal,adaptiveMethod,thresholdType,blockSize,constValue);
////==============lunkuo xianshi
////threshold(image,img1,45,255,THRESH_BINARY);
threshold(dstImage, img1, 45, 255, THRESH_OTSU);//change sharpen_after dstImage
vector
vector
string mu_lu_2_2 = "\\back_binary";
string filename_end = "F:\\image_save\\back_2\\" + gallery_folders.at(g) + "\\" + image_list.at(f);
imwrite(filename_end, img1);//grayImage dst img1
cout << "3333" << endl;
//waitKey();
}
}
waitKey();
cin.get();
return 0;
}
vector
vector
//文件句柄
intptr_t hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("/*").c_str(), &fileinfo)) != -1) {
do {
if ((fileinfo.attrib & _A_SUBDIR)) {
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) {
dirpath.push_back(p.assign(fileinfo.name));
}
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
return dirpath;
}
vector
vector
//文件句柄
intptr_t hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("/*." + format).c_str(), &fileinfo)) != -1)
{
do
{
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
{
//files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
GetAllFormatFiles(p.assign(fileinfo.name), files, format);
}
}
else
{
files.push_back(p.assign(fileinfo.name)); //将文件路径保存,也可以只保存文件名: p.assign(path).append("\\").append(fileinfo.name)
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
return files;
}
//获取特定格式的文件名
void GetAllFormatFiles(string path, vector
files.clear();
//文件句柄
intptr_t hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("/*." + format).c_str(), &fileinfo)) != -1)
{
do
{
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
{
//files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
GetAllFormatFiles(p.assign(path).append("/").append(fileinfo.name), files, format);
}
}
else
{
files.push_back(p.assign(fileinfo.name)); //将文件路径保存,也可以只保存文件名: p.assign(path).append("\\").append(fileinfo.name)
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}