예제 #1
0
void Mixture::convolve(const HOGPyramid & pyramid, vector<HOGPyramid::Matrix> & scores,
                       vector<Indices> & argmaxes,
                       vector<vector<vector<Model::Positions> > > * positions) const
{
    if(empty() || pyramid.empty()) {
        scores.clear();
        argmaxes.clear();

        if(positions)
            positions->clear();

        return;
    }

    const int nbModels = models_.size();
    const int nbLevels = pyramid.levels().size();
    // Convolve with all the models
    vector<vector<HOGPyramid::Matrix> > tmp(nbModels);
    convolve(pyramid, tmp, positions);

    // In case of error
    if(tmp.empty()) {
        scores.clear();
        argmaxes.clear();

        if(positions)
            positions->clear();

        return;
    }

    // Resize the scores and argmaxes
    scores.resize(nbLevels);
    argmaxes.resize(nbLevels);
    int i;
    #pragma omp parallel for private(i)

    for(i = 0; i < nbLevels; ++i) {
        scores[i].resize(pyramid.levels()[i].rows() - maxSize().first + 1,
                         pyramid.levels()[i].cols() - maxSize().second + 1);
        argmaxes[i].resize(scores[i].rows(), scores[i].cols());

        for(int y = 0; y < scores[i].rows(); ++y) {
            for(int x = 0; x < scores[i].cols(); ++x) {
                int argmax = 0;

                for(int j = 1; j < nbModels; ++j)
                    if(tmp[j][i](y, x) > tmp[argmax][i](y, x))
                        argmax = j;

                scores[i](y, x) = tmp[argmax][i](y, x);
                argmaxes[i](y, x) = argmax;
            }
        }
    }
}
예제 #2
0
void Mixture::convolve(const HOGPyramid & pyramid,
                       vector<vector<HOGPyramid::Matrix> > & scores,
                       vector<vector<vector<Model::Positions> > > * positions) const
{
    if(empty() || pyramid.empty()) {
        scores.clear();

        if(positions)
            positions->clear();
    }

    const int nbModels = models_.size();
    scores.resize(nbModels);

    if(positions)
        positions->resize(nbModels);

    // Transform the filters if needed
    #pragma omp critical

    if(filterCache_.empty())
        cacheFilters();

    while(!cached_);

    // Create a patchwork
    const Patchwork patchwork(pyramid);
    // Convolve the patchwork with the filters
    vector<vector<HOGPyramid::Matrix> > convolutions(filterCache_.size());
    patchwork.convolve(filterCache_, convolutions);

    // In case of error
    if(convolutions.empty()) {
        scores.clear();

        if(positions)
            positions->clear();

        return;
    }

    // Save the offsets of each model in the filter list
    vector<int> offsets(nbModels);

    for(int i = 0, j = 0; i < nbModels; ++i) {
        offsets[i] = j;
        j += models_[i].parts_.size();
    }

    // For each model
    int i;
    #pragma omp parallel for private(i)

    for(i = 0; i < nbModels; ++i) {
        vector<vector<HOGPyramid::Matrix> > tmp(models_[i].parts_.size());

        for(size_t j = 0; j < tmp.size(); ++j)
            tmp[j].swap(convolutions[offsets[i] + j]);

        models_[i].convolve(pyramid, tmp, scores[i], positions ? & (*positions)[i] : 0);
    }
}