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


C++ mat::max方法代码示例

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


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

示例1: depth_penalty

double costfunc::depth_penalty(mat &cam_mat, mat &depthmp, mat &spheres,
							   mat &disttrans, double scale) {
	/*
	 * second term of the cost function; this forces the sphere model to lie
	 * inside the ptncloud; it is given by:
	 *
	 * B(c, D) =
	 * .........(a) max(0, D(j(c))-cz)
	 * .........(b) dis(j(c), D)
	 *
	 * ==> if the projection of spheresM (u,v) has non-zero depth, apply (a) -->
	 * with D(j(c)) == depth at (u,v) and cz = depth at sphere center
	 *
	 * ==> if the projection of spheresM (u,v) has zero depth, apply (b) -->
	 * i.e. distance between (u,v) to the non-zero depth calculated using
	 * distance transform of the inverted depth map
	 *
	 * */


	vec radii = *(this->hand->get_radii());

	spheres.cols(1,2) *= -1; // reset depth

	mat projection = cam_mat * spheres.t(); // (3x3) * (3xnspheres)
	projection = projection / repmat(projection.row(2), 3, 1); // to homogeneous
	projection.shed_row(2); // remove the last row, which are all 1's;
	projection = projection.t(); // shape = (nspheres, 2)
	projection = floor(projection); // val --> int for indexing


	double depth_penalty = 0.0;
	int count = projection.n_rows;
	for (int i = 0; i < count; ++i) {
		double dx = projection(i,0);
		double dy = projection(i,1);

		/*
		 * firstly check if the projection of the sphere centers lie inside
		 * the depthmap
		 * (i.e. inside 320x240 as described by xbounded and ybounded)
		 *
		 * if so, calculate the cost accordingly
		 *
		 * else, add the maximum distance from dist-transform
		 *
		 * */
		bool xbounded = dx >= 0 && dx < depthmp.n_cols; // end = depthmp.n_rows-1
		bool ybounded = dy >= 0 && dy < depthmp.n_rows;

		if (xbounded && ybounded) {

			double d_jc = depthmp(dy, dx);
			if (d_jc != 0.0) {

				double diff = max(0.0, d_jc-spheres(i, 2)); // depth at u,v

				depth_penalty += diff*diff;
			}
			else {

				double ddis = disttrans(dy, dx) * scale + radii(i);
				depth_penalty += ddis*ddis;
			}

		}
		else {
			/*
			 * if the projection is out side the image (i.e. 320 x 240)
			 * */

			double maxdis = disttrans.max() * scale + radii(i);
			depth_penalty += maxdis*maxdis;
		}
	}

	return (depth_penalty);
}
开发者ID:hjurong,项目名称:hand-pose-estimation,代码行数:78,代码来源:costfunc.cpp


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