Exemplo n.º 1
0
/* http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/lookat.html
   http://msdn.microsoft.com/en-us/library/bb205343.aspx
*/
void
RMtx4LookAtRH( RMtx4* out, const RVec3* eye, const RVec3* at, const RVec3* up )
{
#define AX(i) RVec3GetElement( &axis_x, i )
#define AY(i) RVec3GetElement( &axis_y, i )
#define AZ(i) RVec3GetElement( &axis_z, i )

    RVec3 axis_x, axis_y, axis_z;

    RMtx4Identity( out );

    RVec3Sub( &axis_z, eye, at );
    RVec3Normalize( &axis_z, &axis_z );

    RVec3Cross( &axis_x, up, &axis_z );
    RVec3Normalize( &axis_x, &axis_x );

    RVec3Cross( &axis_y, &axis_z, &axis_x );

    SET_ELEMENT( out, 0, 0,  AX(0) );
    SET_ELEMENT( out, 0, 1,  AX(1) );
    SET_ELEMENT( out, 0, 2,  AX(2) );
    SET_ELEMENT( out, 0, 3,  -RVec3Dot(&axis_x, eye) );

    SET_ELEMENT( out, 1, 0,  AY(0) );
    SET_ELEMENT( out, 1, 1,  AY(1) );
    SET_ELEMENT( out, 1, 2,  AY(2) );
    SET_ELEMENT( out, 1, 3,  -RVec3Dot(&axis_y, eye) );

    SET_ELEMENT( out, 2, 0,  AZ(0) );
    SET_ELEMENT( out, 2, 1,  AZ(1) );
    SET_ELEMENT( out, 2, 2,  AZ(2) );
    SET_ELEMENT( out, 2, 3,  -RVec3Dot(&axis_z, eye) );

#undef AX
#undef AY
#undef AZ
}
Exemplo n.º 2
0
cv::Mat_<int> cModel::__lbf_fast(const cv::Mat_<uchar>&img, const cv::Rect& bbox, const cv::Mat_<float>& shape,int markID, int stage)
{
	int max_stage = m_Model.__head.__num_stage;
	int num_node = m_Model.__head.__num_leaf + m_Model.__head.__num_node;
	int num_point = m_Model.__head.__num_point;
	int num_tree_per_point = m_Model.__head.__num_tree_per_point;
	int num_leaf = m_Model.__head.__num_leaf;
	
	m_AX[stage].row(markID) *= bbox.width;
	m_AY[stage].row(markID) *= bbox.height;
	m_BX[stage].row(markID) *= bbox.width;
	m_BY[stage].row(markID) *= bbox.height;	

	m_AX[stage].row(markID) += shape(markID, 0);
	m_AY[stage].row(markID) += shape(markID, 1);
	m_BX[stage].row(markID) += shape(markID, 0);
	m_BY[stage].row(markID) += shape(markID, 1);

	cv::Mat_<int> cind = cv::Mat::ones(m_AX[stage].cols, 1, CV_32SC1);
	cv::Mat_<float> AX = m_AX[stage].row(markID);
	cv::Mat_<float> AY = m_AY[stage].row(markID);
	cv::Mat_<float> BX = m_BX[stage].row(markID);
	cv::Mat_<float> BY = m_BY[stage].row(markID);
	cv::Mat_<float> Thresh = m_Thresh[stage].row(markID);	
	

	int width =  img.cols;
	int height = img.rows;	
	
	for (int j = 0; j < AX.cols; j += num_node){
		for (int index = 0; index < m_Model.__head.__num_node; index++){
			int pos = j + index;
			int a_x = (int)(AX(0, pos) + 0.5);
			int a_y = (int)(AY(0, pos) + 0.5);
			int b_x = (int)(BX(0, pos) + 0.5);
			int b_y = (int)(BY(0, pos) + 0.5);

			a_x = MAX(0, MIN(a_x, width - 1));
			a_y = MAX(0, MIN(a_y, height - 1));
			b_x = MAX(0, MIN(b_x, width - 1));
			b_y = MAX(0, MIN(b_y, height - 1));

			float pixel_v_a = (float)img(cv::Point(a_x, a_y));
			float pixel_v_b = (float)img(cv::Point(b_x, b_y));
			float val = pixel_v_a - pixel_v_b;
			
			if (val < (float)Thresh(0, pos)){
				cind(pos, 0) = 0;
			}
		}		
	}

	cv::Mat_<int> binfeature = cv::Mat::zeros(1, (int)cv::sum(m_Isleaf).val[0], CV_32SC1);

	int cumnum_nodes = 0;
	int cumnum_leafnodes = 0;

	for (int t = 0; t < num_tree_per_point; t++){		
		int id_cnode = 0;
		while (1){
			if (m_Isleaf(id_cnode + cumnum_nodes)){
				binfeature(0, cumnum_leafnodes + __getindex(m_Idleafnodes, id_cnode)) = 1;
				cumnum_nodes = cumnum_nodes + num_node;
				cumnum_leafnodes = cumnum_leafnodes + num_leaf;
				break;
			}
			id_cnode = m_Cnodes(cumnum_nodes + id_cnode, cind(cumnum_nodes + id_cnode, 0));
		}
	}
	return binfeature;	
}