#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv2\core\core.hpp>
#include <opencv\cvaux.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace cv;
using namespace std;
#define NCLUSTERS 35
// Build a BMB comprising of nclusters number of background models from training images
// in pathfolder. BMB[0] = centroids estimated by Kmeans and BMB[1] = standard deviations
void BuildBMB(const String pathfolder, const int nclusters, vector<Mat> &BMB){
Mat ycrcb, rgb, vect, Data, labels;
vector<String> files;
// filenames of training images
glob(pathfolder, files);
// Compute Data = rgb & ycrcb of training images
for (unsigned int i=0; i< files.size(); i++){
// Read RGB the image files[i]
fprintf(stdout, "Read image %d/%d\n", i, (int)files.size());
rgb = imread(files[i]);
imshow("RGB image", rgb);
waitKey(10);
// Convert from uchar -> float and scale between [0,1]
rgb.convertTo(rgb, CV_32FC3, 1.0/255.0);
// Convert for color space RGB to color space YcrCb
cvtColor(rgb, ycrcb, CV_BGR2YCrCb);
// Reshape to LIGNE vectors
rgb = rgb.reshape(1, 1);
ycrcb = ycrcb.reshape(1, 1);
// Concatenation of rgb & ycrcb
hconcat(rgb, ycrcb, vect);
// Insert vect to Data
Data.push_back(vect);
}
fprintf(stdout, "Data [%d,%d] is computed.\n", Data.rows, Data.cols);
// clustering Data by kmeans
fprintf(stdout, "Compute Kmeans...\n");
kmeans(Data, nclusters, labels, TermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 350, 1e-3), 3, KMEANS_PP_CENTERS, BMB[0]);
fprintf(stdout, "centroids [%d,%d] and labels [%d,%d] are computed.\n", BMB[0].rows, BMB[0].cols, labels.rows, labels.cols);
double minl,maxl;
minMaxLoc(labels, &minl, &maxl);
fprintf(stdout,"labels : min=%f, max=%f\n", minl, maxl);
// Compute BMB[1] of standatd devaiations. BMB[1] has the same size of BMB[0]
}
int main(int argc, char** argv){
// Train the Background models BMB based on kmeans
fprintf(stdout, "Start training ....\n");
vector<Mat> BMB(2, Mat());
String pathfolder = "C:\\Users\\lenovo\\Documents\\Visual Studio 2010\\Projects\\image\\trainning\\*.jpg";
BuildBMB(pathfolder, NCLUSTERS, BMB);
fprintf(stdout, "End of training.\n");
return(1);
}
这里的问题是我使用的是windows和fuction glob不存在。(linux函数)
我如何在Windows上使用glob?
或者我是否需要其他功能将图像名称加载到&#34;文件&#34;
我想我可以使用&#34; cl typeit.c / link setargv.obj&#34;但是coudn没有把它搞定。