1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #ifdef NICE_USELIB_OPENMP
- #include <omp.h>
- #endif
- #include "vislearning/features/regionfeatures/RFBoVCodebook.h"
- #include <iostream>
- #include "core/basics/Timer.h"
- using namespace OBJREC;
- using namespace std;
- using namespace NICE;
- RFBoVCodebook::RFBoVCodebook( const Config *_conf, LocalFeature *_lf ):RFBoV(_conf, _lf)
- {
- cb = NULL;
- }
- void RFBoVCodebook::setCodebook(Codebook *_cb){
- cb = _cb;
- }
- void RFBoVCodebook::convert(const Matrix &mask, const RegionGraph &rg, VVector &infeats, VVector &outfeats, VVector &positions)
- {
- int fsize = conf->gI("BoVMoosmann", "codebooksize", 1024);
- for(int i = 0; i < (int)rg.size(); i++)
- {
- Vector v(fsize);
- v.set(0.0);
- outfeats.push_back(v);
- }
- vector<double> counter(rg.size(), 0.0);
- #pragma omp parallel for
- for(int i = 0; i < (int)infeats.size(); i++)
- {
- SparseVector probs;
- cb->vote(infeats[i], probs);
- int r = mask(positions[i][0], positions[i][1]);
- #pragma omp critical
- {
- for(int j = 0; j < fsize; j++)
- {
- double val = probs.get(j);
- outfeats[r][j] += val;
- counter[r] += val;
- }
- }
- }
- for(int i = 0; i < (int)rg.size(); i++)
- {
- outfeats[i] /= counter[i];
- }
- }
- RFBoVCodebook::~RFBoVCodebook()
- {
- }
|