forked from higerra/HoughForest
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CRForest.h
74 lines (61 loc) · 2.09 KB
/
CRForest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
// Author: Juergen Gall, BIWI, ETH Zurich
// Email: [email protected]
*/
#pragma once
#include "CRTree.h"
#include <vector>
class CRForest {
public:
// Constructors
CRForest(int trees = 0) {
vTrees.resize(trees);
}
~CRForest() {
for(std::vector<CRTree*>::iterator it = vTrees.begin(); it != vTrees.end(); ++it) delete *it;
vTrees.clear();
}
// Set/Get functions
void SetTrees(int n) {vTrees.resize(n);}
int GetSize() const {return vTrees.size();}
unsigned int GetDepth() const {return vTrees[0]->GetDepth();}
unsigned int GetNumCenter() const {return vTrees[0]->GetNumCenter();}
// Regression
void regression(std::vector<const LeafNode*>& result, uchar** ptFCh, int stepImg) const;
// Training
void trainForest(int min_s, int max_d, cv::RNG* pRNG, const CRPatch& TrData, int samples);
// IO functions
void saveForest(const char* filename, unsigned int offset = 0);
void loadForest(const char* filename, int type = 0);
void show(int w, int h) const {vTrees[0]->showLeaves(w,h);}
// Trees
std::vector<CRTree*> vTrees;
};
inline void CRForest::regression(std::vector<const LeafNode*>& result, uchar** ptFCh, int stepImg) const {
result.resize( vTrees.size() );
for(int i=0; i<(int)vTrees.size(); ++i) {
result[i] = vTrees[i]->regression(ptFCh, stepImg);
}
}
//Training
inline void CRForest::trainForest(int min_s, int max_d, cv::RNG* pRNG, const CRPatch& TrData, int samples) {
for(int i=0; i < (int)vTrees.size(); ++i) {
vTrees[i] = new CRTree(min_s, max_d, TrData.vLPatches[1][0].center.size(), pRNG);
vTrees[i]->growTree(TrData, samples);
}
}
// IO Functions
inline void CRForest::saveForest(const char* filename, unsigned int offset) {
char buffer[200];
for(unsigned int i=0; i<vTrees.size(); ++i) {
sprintf_s(buffer,"%s%03d.txt",filename,i+offset);
vTrees[i]->saveTree(buffer);
}
}
inline void CRForest::loadForest(const char* filename, int type) {
char buffer[200];
for(unsigned int i=0; i<vTrees.size(); ++i) {
sprintf_s(buffer,"%s%03d.txt",filename,i);
vTrees[i] = new CRTree(buffer);
}
}