本文整理汇总了C++中Forest::Apply方法的典型用法代码示例。如果您正苦于以下问题:C++ Forest::Apply方法的具体用法?C++ Forest::Apply怎么用?C++ Forest::Apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Forest
的用法示例。
在下文中一共展示了Forest::Apply方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getForestPrediction2Forests
DBfileindex getForestPrediction2Forests(DepthDBWithVotesSImpl<VoteType,VoteDim> &db,
Forest<DepthFeature, Stats> &forest1,
Forest<DepthFeature, Stats> &forest2,
AggregatedLeafs<DepthFeature,Stats,VoteType,VoteDim> &aggLeafs1,
AggregatedLeafs<DepthFeature,Stats,VoteType,VoteDim> &aggLeafs2,
LocalCache &cache,
const Configuration &config,
VoteType w1, VoteType w2,
std::vector<cv::Vec<VoteType,VoteDim> > &prediction, //OUT
std::vector<double> &weights, //OUT
DBindex &idx) //OUT
{
//strong assumption: the pixels of one image are following one another
std::ostream &log = cache.log();
DBfileindex img = db.getImageIdx(idx);
std::vector<DBindex> oneimage;
while(idx < db.Count() && db.getImageIdx(idx) == img){
oneimage.push_back(idx++);
}
//we dont need GT, so simple filebased index will do
SubindexFileBasedImageDB dboneimage(db,oneimage);
std::vector<std::vector<int> > leafIndicesPerTree1;
ProgressStream progress(cache.log(),Verbose);
forest1.Apply(dboneimage,leafIndicesPerTree1,&progress);
VotesAggregator<VoteType,VoteDim> imageVotes(db.voteClassCount());
for(int t=0; t< forest1.TreeCount(); t++){
for(int i=0; i< dboneimage.Count(); i++){
if(leafIndicesPerTree1[t][i]>0){
imageVotes.AddVotes(aggLeafs1.get(t,leafIndicesPerTree1[t][i]),w1);
}
}
}
std::vector<std::vector<int> > leafIndicesPerTree2;
forest2.Apply(dboneimage,leafIndicesPerTree2,&progress);
for(int t=0; t< forest2.TreeCount(); t++){
for(int i=0; i< dboneimage.Count(); i++){
if(leafIndicesPerTree2[t][i]>0){
imageVotes.AddVotes(aggLeafs2.get(t,leafIndicesPerTree2[t][i]),w1);
}
}
}
mean_shift::MeanShift finalshift;
finalshift.setRadius(config.meanShiftR());
finalshift.setMaxIter(config.meanShiftMaxIter());
finalshift.setMaxNeigboursCount(config.maxNN());
std::vector<float> imean;
std::vector<float> istd;
imean.resize(db.voteClassCount()*VoteDim);
istd.resize(db.voteClassCount()*VoteDim);
//imageVotes.Normalize(imean,istd);
std::cerr << "istd: " << istd[0] << std::endl;
imageVotes.Prediction(prediction,weights,finalshift);
imageVotes.Serialize(cache.openBinStream("imageVotes"));
/*for(int i=0; i<prediction.size();i++){
for(int j=0; j<VoteDim; j++){
prediction[i][j] = prediction[i][j]*istd[i*VoteDim+j] + imean[i*VoteDim+j];
}
}*/
log << "prediction computed" << std::endl;
return img;
}
示例2: getForestPrediction
DBfileindex getForestPrediction(DepthDBWithVotesSImpl<VoteType,VoteDim> &db,
Forest<DepthFeature, Stats> &forest,
AggregatedLeafs<DepthFeature,Stats,VoteType,VoteDim> &aggLeafs,
LocalCache &cache,
const Configuration &config,
std::vector<cv::Vec<VoteType,VoteDim> > &prediction, //OUT
std::vector<double> &weights, //OUT
DBindex &idx) //OUT
{
//strong assumption: the pixels of one image are following one another
std::ostream &log = cache.log();
DBfileindex img = db.getImageIdx(idx);
std::vector<DBindex> oneimage;
while(idx< db.Count() && db.getImageIdx(idx) == img){
oneimage.push_back(idx++);
}
//we dont need GT, so simple filebased index will do
SubindexFileBasedImageDB dboneimage(db,oneimage);
std::vector<std::vector<int> > leafIndicesPerTree;
ProgressStream progress(cache.log(),Verbose);
forest.Apply(dboneimage,leafIndicesPerTree,&progress);
log << "forest applied" << std::endl;
VotesAggregator<VoteType,VoteDim> imageVotes(db.voteClassCount());
for(int t=0; t< forest.TreeCount(); t++){
for(int i=0; i< dboneimage.Count(); i++){
imageVotes.AddVotes(aggLeafs.get(t,leafIndicesPerTree[t][i]));
}
}
log << "votes aggregated" << std::endl;
mean_shift::MeanShift finalshift;
std::vector<float> imean;
std::vector<float> istd;
imean.resize(db.voteClassCount()*VoteDim);
istd.resize(db.voteClassCount()*VoteDim);
finalshift.setRadius(config.meanShiftR());
finalshift.setMaxIter(config.meanShiftMaxIter());
finalshift.setMaxNeigboursCount(config.maxNN());
imageVotes.Normalize(imean,istd);
bool valid = imageVotes.Prediction(prediction,weights,finalshift);
for(int i=0; i<prediction.size();i++){
for(int j=0; j<VoteDim; j++){
prediction[i][j] = prediction[i][j]*istd[i*VoteDim+j] + imean[i*VoteDim+j];
}
}
if(valid)
log << "prediction for image " << db.imageIdx2Filename(img) << " computed" << std::endl;
else
log << "prediction for image " << db.imageIdx2Filename(img) << " failed" << std::endl;
return img;
}