Go to the documentation of this file.00001 #include <iostream>
00002 #include <fstream>
00003 #include <vector>
00004 #include "head_pose_estimation/CRTree.h"
00005
00006 using namespace std;
00007
00008 bool CRTree::loadTree(const char* filename) {
00009
00010 cout << "Load Tree (BIN) " << filename << " " << flush;
00011 int dummy;
00012 bool success = true;
00013
00014 FILE* fp = fopen(filename,"rb");
00015
00016 if(!fp){
00017 cout << "failed" << endl;
00018 return false;
00019 }
00020
00021 success &= ( fread( &max_depth, sizeof(int), 1, fp) == 1);
00022 success &= ( fread( &num_leaf, sizeof(int), 1, fp) == 1);
00023 success &= ( fread( &m_pwidth, sizeof(int), 1, fp) == 1);
00024 success &= ( fread( &m_pheight, sizeof(int), 1, fp) == 1);
00025 success &= ( fread( &m_no_chans,sizeof(int), 1, fp) == 1);
00026
00027 num_nodes = (int)pow(2.0,int(max_depth+1))-1;
00028
00029 treetable = new int[num_nodes * TEST_DIM];
00030 int* ptT = &treetable[0];
00031
00032
00033 leaf = new LeafNode[num_leaf];
00034
00035
00036 for(unsigned int n=0; n<num_nodes; ++n) {
00037
00038 success &= ( fread( &dummy, sizeof(int), 1, fp) == 1);
00039 success &= ( fread( &dummy, sizeof(int), 1, fp) == 1);
00040
00041
00042 for(unsigned int i=0; i<TEST_DIM; ++i, ++ptT){
00043 success &= ( fread( ptT, sizeof(int), 1, fp) == 1);
00044 }
00045
00046 }
00047
00048
00049 LeafNode* ptLN = &leaf[0];
00050 for(unsigned int l=0; l<num_leaf; ++l, ++ptLN) {
00051
00052 ptLN->mean.create(POSE_SIZE, 1, CV_32FC1); ptLN->mean.setTo(0);
00053
00054 success &= ( fread( &dummy, sizeof(int), 1, fp) == 1);
00055 success &= ( fread( &(ptLN->pfg), sizeof(float), 1, fp) == 1);
00056 success &= ( fread( ptLN->mean.data, sizeof(float), POSE_SIZE, fp) == POSE_SIZE );
00057 success &= ( fread( &(ptLN->trace), sizeof(float), 1, fp) == 1);
00058
00059 }
00060
00061 fclose(fp);
00062 std::cout << " done " << endl;
00063
00064 return success;
00065
00066 }
00067