CRTree.h
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include "opencv2/core/core.hpp"
00004 #include "opencv2/highgui/highgui.hpp"
00005 
00006 #define TEST_DIM 11
00007 #define POSE_SIZE 6
00008 #define AVG_FACE_DIAMETER 236.4f
00009 #define AVG_FACE_DIAMETER2 55884.96f
00010 
00011 // Structure for the leafs
00012 class LeafNode {
00013 
00014 public:
00015 
00016         LeafNode() { }
00017         ~LeafNode(){ }
00018 
00019         // Probability of belonging to a head
00020         float pfg;
00021         // mean vector
00022         cv::Mat mean;
00023         // trace of the covariance matrix
00024         float trace;
00025 
00026 };
00027 
00028 class CRTree {
00029 
00030 public:
00031 
00032         CRTree() {};
00033 
00034         ~CRTree() { delete [] leaf; delete[] treetable; }
00035 
00036         bool loadTree(const char* filename);
00037 
00038         int getDepth() const {return max_depth;}
00039         int getPatchWidth() const {return m_pwidth;}
00040         int getPatchHeight() const {return m_pheight;}
00041         int getNoChannels() const {return m_no_chans;}
00042 
00043         const LeafNode* regressionIntegral(const std::vector< cv::Mat >&, const cv::Mat& nonZeros, const cv::Rect& roi);
00044 
00045 
00046 private:
00047 
00048         int m_pwidth, m_pheight, m_no_chans;
00049 
00050     // Data structure
00051     // tree table
00052     int* treetable;
00053 
00054         // number of nodes: 2^(max_depth+1)-1
00055         int num_nodes;
00056 
00057         // number of leafs
00058         int num_leaf;
00059 
00060         int max_depth;
00061 
00062         //leafs as vector
00063         LeafNode* leaf;
00064 
00065 };
00066 
00067 inline const LeafNode* CRTree::regressionIntegral(const std::vector< cv::Mat >& patch, const cv::Mat& nonZeros, const cv::Rect& roi) {
00068 
00069         // pointer to current node
00070         const int* pnode = &treetable[0];
00071         int node = 0;
00072 
00073         // Go through tree until one arrives at a leaf, i.e. pnode[0]>=0)
00074         while(pnode[0]==-1) {
00075 
00076                 const cv::Mat ptC = patch[ pnode[9] ];
00077 
00078                 int xa1 = roi.x + pnode[1];             int xa2 = xa1 + pnode[5];
00079                 int ya1 = roi.y + pnode[2];             int ya2 = ya1 + pnode[6];
00080                 int xb1 = roi.x + pnode[3];             int xb2 = xb1 + pnode[7];
00081                 int yb1 = roi.y + pnode[4];             int yb2 = yb1 + pnode[8];
00082 
00083                 double mz1 = ( ptC.at<double>(ya1,xa1) +
00084                                            ptC.at<double>(ya2,xa2) -
00085                                            ptC.at<double>(ya2,xa1) -
00086                                            ptC.at<double>(ya1,xa2) )/
00087                                            (double)MAX(1, nonZeros.at<double>(ya1,xa1) +
00088                                                                           nonZeros.at<double>(ya2,xa2) -
00089                                                                           nonZeros.at<double>(ya2,xa1) -
00090                                                                           nonZeros.at<double>(ya1,xa2));
00091 
00092                 double mz2 = ( ptC.at<double>(yb1,xb1) +
00093                                            ptC.at<double>(yb2,xb2) -
00094                                            ptC.at<double>(yb2,xb1) -
00095                                            ptC.at<double>(yb1,xb2) )/
00096                                            (double)MAX(1, nonZeros.at<double>(yb1,xb1) +
00097                                                                           nonZeros.at<double>(yb2,xb2) -
00098                                                                           nonZeros.at<double>(yb2,xb1) -
00099                                                                           nonZeros.at<double>(yb1,xb2));
00100 
00101                 //check test
00102                 int test = ( (mz1 - mz2) >= (double)pnode[10] );
00103 
00104                 //the test result sends the patch to one of the children nodes
00105                 int incr = node+1+test;
00106                 node += incr;
00107                 pnode += incr*TEST_DIM;
00108 
00109         }
00110 
00111         return &leaf[pnode[0]];
00112 
00113 }
00114 
00115 


head_pose_estimation
Author(s): Dan Lazewatsky
autogenerated on Thu Feb 11 2016 23:06:59