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


C++ ModelPtr::SetSize方法代码示例

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


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

示例1: FitFirstPrincipalComponents

void Optimizer::FitFirstPrincipalComponents(mat& alpha,
	mat& beta,
	mat& rho,
	mat& lamda,
	InputPtr input,
	ModelPtr model,
	MeshPtr mesh,
	ShapePtr shape,
	TexturePtr texture,
	const cv::Mat& ready)
{


	mat alpha_gradient = mat(PrincipalNum, 1, fill::zeros);
	mat alpha_hessian_inv = mat(PrincipalNum, PrincipalNum, fill::zeros);

	mat beta_gradient = mat(PrincipalNum, 1, fill::zeros);
	mat rho_gradient = mat(RhoNum, 1, fill::zeros);
	mat lamda_gradient = mat(LamdaNum, 1, fill::zeros);

	vec step(RhoNum, 1);
	step.rows(0, 2).fill(0.00000006);
	step.rows(3, 5).fill(0.0002);
	step.rows(6, 6).fill(2.0);
	mat step_mat = diagmat(step);



	// down sampled version
	cv::Mat down_sampled;
	pyrDown(ready, down_sampled, Size(IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2));
	input = make_shared<InputImage>(down_sampled);
	model->SetSize(IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2);
	rho[FOCAL] /= 2;


	//SetStartingValue(rho, lamda);
	double para_num = 10;
	double weight = 1.0 / 900;

	int counter = 0;
	while (counter < 1000)
	{

		Alpha alpha_para(alpha, input, model, mesh, shape, texture);
		Beta beta_para(beta, model, mesh, shape, texture);
		Rho rho_para(rho, input, model, mesh, shape, texture);
		Lamda lamda_para(lamda, model, mesh, shape, texture);


		if (counter == 0 || counter % 1000 == 0)
		{
			Face3dModel face3d_model(shape, texture);
			mesh = face3d_model.Construction(alpha, beta);
			TwoPassZbuffer(rho, lamda, mesh, model);
			model->EnableIterator();
			model->InitialRandomGenerator();

			//GenerateRandomPoints(model, HessianRandomNum);
			//for (int i = 0; i < para_num; ++i)
			//{
			//	double variance = shape->GetVariance(i);

			//	mat alpha1 = alpha;
			//	alpha1[i] -= H;
			//	Alpha alpha_para1(alpha1, input, model, mesh, shape, texture);
			//	double first_derivative1 = weight * ComputeIntensityGradient(input, &alpha_para1, i) + 2 * alpha1[i] / variance;

			//	mat alpha2 = alpha;
			//	alpha2[i] += H;
			//	Alpha alpha_para2(alpha2, input, model, mesh, shape, texture);
			//	double first_derivative2 = weight * ComputeIntensityGradient(input, &alpha_para2, i) + 2 * alpha2[i] / variance;

			//	double second_derivative = (first_derivative2 - first_derivative1) / (2 * H);
			//	alpha_hessian_inv(i, i) = 1 / (second_derivative + 2 / variance);
			//}
		}



		// Generate random points  
		GenerateRandomPoints(model, GradientRandomNum);
		double function_value = 0;
		function_value = ComputeCost(input, model, alpha_para);
		ofstream cost;
		cost.open("first_cost", ios::app);
		cost << function_value << "\n";
		cost.close();



		for (int i = 0; i < para_num; ++i)
		{
			double variance = shape->GetVariance(i);
			alpha_gradient[i] = weight * ComputeIntensityGradient(input, &alpha_para, i) + 2 * alpha[i] / variance;
		}


		//for (int i = 0; i < 10; ++i)
		//{
//.........这里部分代码省略.........
开发者ID:tpys,项目名称:face-reconstruction-from-one-frontal-image,代码行数:101,代码来源:optimizer.cpp

示例2: FitIllumination

void Optimizer::FitIllumination(mat& alpha, 
	mat& beta, 
	mat& rho, 
	mat& lamda, 
	InputPtr input, 
	ModelPtr model,
	MeshPtr mesh,
	ShapePtr shape, 
	TexturePtr texture, 
	const cv::Mat& ready)
{


	mat lamda_gradient=mat(LamdaNum, 1,fill::zeros);
	mat lamda_hessian_inv = mat(LamdaNum, LamdaNum, fill::zeros);


	Face3dModel face3d_model(shape, texture);
	mesh = face3d_model.Construction(alpha, beta);
	//VisualizeResult(rho, lamda, input, mesh, 0);
	TwoPassZbuffer(rho, lamda, mesh, model);
	model->EnableIterator();
	model->InitialRandomGenerator();

	// down sampled version
	cv::Mat down_sampled;
	pyrDown(ready, down_sampled, Size(IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2));
	input = make_shared<InputImage>(down_sampled);
	model->SetSize(IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2);
	rho[FOCAL] /= 2;

	double weight = 1.0 / 1000;
	int counter = 0;

	while (counter < 500)
	{

		Alpha alpha_para(alpha, input, model, mesh, shape, texture);
		Beta beta_para(beta, model, mesh, shape, texture);
		Rho rho_para(rho, input, model, mesh, shape, texture);
		Lamda lamda_para(lamda, model, mesh, shape, texture);

		// Generate random points  
		//if (counter == 0 || counter % 1000 == 0)
		//{
		//	GenerateRandomPoints(model, HessianRandomNum);

		//	for (int i = 0; i < LamdaNum - 7; ++i)
		//	{
		//		mat lamda1 = lamda;
		//		lamda1[i] -= H;
		//		Lamda lamda_para1(lamda1, model, mesh, shape, texture);
		//		double first_derivative1 = weight*ComputeIntensityGradient(input, &lamda_para1, i);


		//		mat lamda2 = lamda;
		//		lamda2[i] += H;
		//		Lamda lamda_para2(lamda2, model, mesh, shape, texture);
		//		double first_derivative2 = weight* ComputeIntensityGradient(input, &lamda_para2, i);
		//		double second_derivative = (first_derivative2 - first_derivative1) / (2 * H);

		//		lamda_hessian_inv(i, i) = 1 / second_derivative;

		//	}


		//}
	
		GenerateRandomPoints(model, GradientRandomNum);

		//double function_value = 0;
		//function_value = ComputeCost(input, model, alpha_para);
		//ofstream cost;
		//cost.open("illumination_cost", ios::app);
		//cost << function_value << "\n";
		//cost.close();


		for (int i = 0; i < LamdaNum; ++i)
		{		 
			lamda_gradient[i] = weight*ComputeIntensityGradient(input, &lamda_para, i);
		}

		lamda -= lamda_para.Step*lamda_gradient;
		//lamda -= 0.5*lamda_hessian_inv*lamda_gradient;
		++counter;
	}

	// restore original version
	input= make_shared<InputImage>(ready);
	model->SetSize(IMAGE_WIDTH, IMAGE_HEIGHT);
	rho[FOCAL] *= 2;

	VisualizeResult(rho, lamda, input, mesh, "illumination");

}
开发者ID:tpys,项目名称:face-reconstruction-from-one-frontal-image,代码行数:96,代码来源:optimizer.cpp


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