mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 11:40:54 +08:00
Added scorekeeper class to manage scores/weights for platecorners
This commit is contained in:
75
src/openalpr/edges/scorekeeper.cpp
Normal file
75
src/openalpr/edges/scorekeeper.cpp
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014 New Designs Unlimited, LLC
|
||||||
|
* Opensource Automated License Plate Recognition [http://www.openalpr.com]
|
||||||
|
*
|
||||||
|
* This file is part of OpenAlpr.
|
||||||
|
*
|
||||||
|
* OpenAlpr is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License
|
||||||
|
* version 3 as published by the Free Software Foundation
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "scorekeeper.h"
|
||||||
|
|
||||||
|
ScoreKeeper::ScoreKeeper() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ScoreKeeper::~ScoreKeeper() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScoreKeeper::setScore(std::string weight_id, float score, float weight) {
|
||||||
|
|
||||||
|
// Assume that we never set this value twice
|
||||||
|
weight_ids.push_back(weight_id);
|
||||||
|
scores.push_back(score);
|
||||||
|
weights.push_back(weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float ScoreKeeper::getTotal() {
|
||||||
|
|
||||||
|
float score = 0;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < weights.size(); i++)
|
||||||
|
{
|
||||||
|
score += scores[i] * weights[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScoreKeeper::printDebugScores() {
|
||||||
|
|
||||||
|
int longest_weight_id = 0;
|
||||||
|
for (unsigned int i = 0; i < weight_ids.size(); i++)
|
||||||
|
{
|
||||||
|
if (weight_ids[i].length() > longest_weight_id)
|
||||||
|
longest_weight_id = weight_ids[i].length();
|
||||||
|
}
|
||||||
|
|
||||||
|
float total = getTotal();
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < weight_ids.size(); i++)
|
||||||
|
{
|
||||||
|
float percent_of_total = (scores[i] * weights[i]) / total * 100;
|
||||||
|
|
||||||
|
std::cout << " - " << std::setw(longest_weight_id + 1) << std::left << weight_ids[i] <<
|
||||||
|
" Weighted Score: " << std::setw(10) << std::left << (scores[i] * weights[i]) <<
|
||||||
|
" Orig Score: " << std::setw(10) << std::left << scores[i] <<
|
||||||
|
" (" << percent_of_total << "% of total)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "Total: " << total << std::endl;
|
||||||
|
}
|
48
src/openalpr/edges/scorekeeper.h
Normal file
48
src/openalpr/edges/scorekeeper.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014 New Designs Unlimited, LLC
|
||||||
|
* Opensource Automated License Plate Recognition [http://www.openalpr.com]
|
||||||
|
*
|
||||||
|
* This file is part of OpenAlpr.
|
||||||
|
*
|
||||||
|
* OpenAlpr is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License
|
||||||
|
* version 3 as published by the Free Software Foundation
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OPENALPR_SCOREKEEPER_H
|
||||||
|
#define OPENALPR_SCOREKEEPER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
class ScoreKeeper {
|
||||||
|
public:
|
||||||
|
ScoreKeeper();
|
||||||
|
virtual ~ScoreKeeper();
|
||||||
|
|
||||||
|
void setScore(std::string weight_id, float score, float weight);
|
||||||
|
|
||||||
|
float getTotal();
|
||||||
|
|
||||||
|
void printDebugScores();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::vector<std::string> weight_ids;
|
||||||
|
std::vector<float> weights;
|
||||||
|
|
||||||
|
std::vector<float> scores;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* OPENALPR_SCOREKEEPER_H */
|
||||||
|
|
Reference in New Issue
Block a user