当前位置: 首页>>代码示例>>C++>>正文


C++ PCA::computeVar方法代码示例

本文整理汇总了C++中PCA::computeVar方法的典型用法代码示例。如果您正苦于以下问题:C++ PCA::computeVar方法的具体用法?C++ PCA::computeVar怎么用?C++ PCA::computeVar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PCA的用法示例。


在下文中一共展示了PCA::computeVar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
			add(meanXs, instance, meanXs);
		}
		
		for (int i = 0; i < Xp.cols; i++) {
			instance = Xp.col(i);
			add(meanXp, instance, meanXp);
		}
		
		// calculate total mean
		meanX.convertTo(meanX, CV_32F, 1.0/static_cast<double>(X.cols));
		meanXs.convertTo(meanXs, CV_32F, 1.0/static_cast<double>(Xs.cols));
		meanXp.convertTo(meanXp, CV_32F, 1.0/static_cast<double>(Xp.cols));
		
		
		// subtract the mean of matrix
		for(int i=0; i<X.cols; i++) {
			Mat c_i = X.col(i);
			subtract(c_i, meanX.reshape(1,dim), c_i);
		}
		
		for(int i=0; i<Xs.cols; i++) {
			Mat c_i = Xs.col(i);
			subtract(c_i, meanXs.reshape(1,dim), c_i);
		}
		
		for(int i=0; i<Xp.cols; i++) {
			Mat c_i = Xp.col(i);
			subtract(c_i, meanXp.reshape(1,dim), c_i);
		}
		
		if(meanX.total() >= nTraining)
			pca(X, Mat(), CV_PCA_DATA_AS_COL, nTraining-1);
		else
			pca.computeVar(X, Mat(), CV_PCA_DATA_AS_COL, .99);
		
		Mat W1 = pca.eigenvectors.t();
		Mat ldaData = (W1.t()*X).t();
		lda.compute(ldaData, labels);
		Mat W2 = lda.eigenvectors();
		W2.convertTo(W2, CV_32F);
		Mat projectionMatrix = (W2.t()*W1.t()).t();
		
		//testing
		#pragma omp parallel for private(temp)
		for(uint i=0; i<nTestingSketches; i++){
			temp = *(testingSketchesDescriptors[i]);
			temp = bag(temp, bag_indexes, 154);
			temp = projectionMatrix.t()*(temp-meanX);
			if(b==0){
				testingSketchesDescriptorsBag[i] = new Mat();
				*(testingSketchesDescriptorsBag[i]) = temp.clone();
			}
			else{
				vconcat(*(testingSketchesDescriptorsBag[i]), temp, *(testingSketchesDescriptorsBag[i]));
			}
		}
		
		#pragma omp parallel for private(temp)
		for(uint i=0; i<nTestingPhotos; i++){
			temp = *(testingPhotosDescriptors[i]);
			temp = bag(temp, bag_indexes, 154);
			temp = projectionMatrix.t()*(temp-meanX);
			if(b==0){
				testingPhotosDescriptorsBag[i] = new Mat();
				*(testingPhotosDescriptorsBag[i]) = temp.clone();
			}
开发者ID:HVisionSensing,项目名称:facialSketchRecognition,代码行数:67,代码来源:demoKernelProtoDRS.cpp

示例2: main


//.........这里部分代码省略.........
		Kernel k(trainingPhotosDescriptors1Temp, trainingSketchesDescriptors1Temp);
		k.compute();
		
		uint dim = (k.projectGallery(bag(*(trainingPhotosDescriptors1[0]), bag_indexes, 154))).total();
		
		Mat X(dim, 2*nTraining2, CV_32F);
		
		#pragma omp parallel for private(temp)
		for(uint i=0; i<nTraining2; i++){
			temp = *(trainingSketchesDescriptors2[i]);
			temp = bag(temp, bag_indexes, 154);
			temp = k.projectProbe(temp);
			temp.copyTo(X.col(i));
		}
		
		#pragma omp parallel for private(temp)
		for(uint i=0; i<nTraining2; i++){
			temp = *(trainingPhotosDescriptors2[i]);
			temp = bag(temp, bag_indexes, 154);
			temp = k.projectGallery(temp);
			temp.copyTo(X.col(i+nTraining2));
		}
		
		Mat meanX = Mat::zeros(dim, 1, CV_32F), instance;
		
		// calculate sums
		for (int i = 0; i < X.cols; i++) {
			instance = X.col(i);
			add(meanX, instance, meanX);
		}
		
		// calculate total mean
		meanX.convertTo(meanX, CV_32F, 1.0/static_cast<double>(X.cols));
		
		// subtract the mean of matrix
		for(int i=0; i<X.cols; i++) {
			Mat c_i = X.col(i);
			subtract(c_i, meanX.reshape(1,dim), c_i);
		}
		
		pca.computeVar(X, Mat(), CV_PCA_DATA_AS_COL, .99);
		
		Mat W1 = pca.eigenvectors.t();
		Mat ldaData = (W1.t()*X).t();
		lda.compute(ldaData, labels);
		Mat W2 = lda.eigenvectors();
		W2.convertTo(W2, CV_32F);
		Mat projectionMatrix = (W2.t()*W1.t()).t();
		
		//testing
		#pragma omp parallel for private(temp)
		for(uint i=0; i<nTestingSketches; i++){
			temp = *(testingSketchesDescriptors[i]);
			temp = bag(temp, bag_indexes, 154);
			temp = k.projectProbe(temp);
			temp = projectionMatrix.t()*(temp-meanX);
			if(b==0){
				testingSketchesDescriptorsBag[i] = new Mat();
				*(testingSketchesDescriptorsBag[i]) = temp.clone();
			}
			else{
				vconcat(*(testingSketchesDescriptorsBag[i]), temp, *(testingSketchesDescriptorsBag[i]));
			}
		}
		
		#pragma omp parallel for private(temp)
		for(uint i=0; i<nTestingPhotos; i++){
			temp = *(testingPhotosDescriptors[i]);
			temp = bag(temp, bag_indexes, 154);
			temp = k.projectGallery(temp);
			temp = projectionMatrix.t()*(temp-meanX);
			if(b==0){
				testingPhotosDescriptorsBag[i] = new Mat();
				*(testingPhotosDescriptorsBag[i]) = temp.clone();
			}
			else{
				vconcat(*(testingPhotosDescriptorsBag[i]), temp, *(testingPhotosDescriptorsBag[i]));
			}
		}
	}
	
	Mat distancesCosine = Mat::zeros(nTestingSketches,nTestingPhotos,CV_64F);
	
	#pragma omp parallel for
	for(uint i=0; i<nTestingSketches; i++){
		for(uint j=0; j<nTestingPhotos; j++){
			distancesCosine.at<double>(i,j) = abs(1-cosineDistance(*(testingSketchesDescriptorsBag[i]),*(testingPhotosDescriptorsBag[j])));
		}
	}
	
	string file1name = "kernel-prs-" + filter + descriptor + database + to_string(nTraining) + string("cosine") + to_string(count) + string(".xml");
	
	FileStorage file1(file1name, FileStorage::WRITE);
	
	file1 << "distanceMatrix" << distancesCosine;
	
	file1.release();
	
	return 0;
}
开发者ID:albertofernandezvillan,项目名称:facialSketchRecognition,代码行数:101,代码来源:demoKernelProtoPRS.cpp


注:本文中的PCA::computeVar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。