add generate strong seed and mergeCharToGroup, draw lines

v1.6alpha
liuruoze 10 years ago
parent 480df262b6
commit e1df2fff3a

@ -1722,3 +1722,8 @@ Recall:31.1421%, Precise:35.8134%, Fscore:33.3148%.
Recall:83.2984%, Precise:86.2716%, Fscore:84.7589%.
平均字符差距:0.845361, 完全匹配数:127, 完全匹配率:65.4639%
总时间:216秒, 平均执行时间:1.08秒
2016-06-21 15:39:31
总图片数:25, 未识出图片:25, 定位率:0%
Recall:0%, Precise:0%, Fscore:0%.
平均字符差距:0, 完全匹配数:0, 完全匹配率:0%
总时间:231秒, 平均执行时间:9.24秒

@ -9,7 +9,8 @@
//////////////////////////////////////////////////////////////////////////
#ifndef EASYPR_CORE_CHARACTER_H_
#define EASYPR_CORE_CHARACTER_H_
#include "core_func.h"
#include "easypr/core/core_func.h"
/*! \namespace easypr
Namespace where all the C++ EasyPR functionality resides
@ -20,6 +21,11 @@ namespace easypr {
public:
CCharacter()
{
m_characterMat = Mat();
m_characterPos = Rect();
m_characterStr = "";
m_score = 0;
m_isChinese = false;
}
CCharacter(const CCharacter& other)
@ -28,6 +34,7 @@ namespace easypr {
m_characterPos = other.m_characterPos;
m_characterStr = other.m_characterStr;
m_score = other.m_score;
m_isChinese = other.m_isChinese;
}
inline void setCharacterMat(Mat param) { m_characterMat = param; }
@ -42,6 +49,18 @@ namespace easypr {
inline void setCharacterScore(double param) { m_score = param; }
inline double getCharacterScore() const { return m_score; }
inline void setIsChinese(bool param) { m_isChinese = param; }
inline bool getIsChinese() const { return m_isChinese; }
//inline void setIsStrong(bool param) { isStrong = param; }
inline bool getIsStrong() const { return m_score >= 0.9; }
//inline void setIsWeak(bool param) { isWeak = param; }
inline bool getIsWeak() const { return m_score < 0.9 && m_score >= 0.5; }
//inline void setIsLittle(bool param) { isLittle = param; }
inline bool getIsLittle() const { return m_score < 0.5; }
bool operator < (const CCharacter& other) const
{
return (m_score > other.m_score);
@ -66,8 +85,16 @@ namespace easypr {
double m_score;
//! weather is chinese
bool isChinese;
bool m_isChinese;
////! m_score >= 0.9
//bool isStrong;
////! m_score < 0.9 && m_score >= 0.5
//bool isWeak;
////! m_score < 0.5
//bool isLittle;
};
} /*! \namespace easypr*/

@ -2,6 +2,7 @@
#define EASYPR_CORE_CHARSIDENTIFY_H_
#include "easypr/util/kv.h"
#include "easypr/core/character.hpp"
#include <memory>
#include "opencv2/opencv.hpp"
@ -14,6 +15,8 @@ class CharsIdentify {
int classify(cv::Mat f, float& maxVal, bool isChinses = false);
void classify(cv::Mat featureRows, std::vector<int>& out_maxIndexs,
std::vector<float>& out_maxVals, std::vector<bool> isChineseVec);
void classify(std::vector<CCharacter>& charVec);
std::pair<std::string, std::string> identify(cv::Mat input, bool isChinese = false);
int identify(std::vector<cv::Mat> inputs, std::vector<std::pair<std::string, std::string>>& outputs,

@ -9,7 +9,8 @@
//////////////////////////////////////////////////////////////////////////
#ifndef EASYPR_CORE_PLATE_H_
#define EASYPR_CORE_PLATE_H_
#include "core_func.h"
#include "easypr/core/core_func.h"
/*! \namespace easypr
Namespace where all the C++ EasyPR functionality resides

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 KiB

After

Width:  |  Height:  |  Size: 84 KiB

File diff suppressed because it is too large Load Diff

@ -33,13 +33,14 @@ namespace easypr {
ann_->predict(featureRows, output);
for (int output_index = 0; output_index < rowNum; output_index++) {
Mat output_row = output.row(output_index);
int result = -1;
float maxVal = -2.f;
bool isChinses = isChineseVec[output_index];
if (!isChinses) {
result = 0;
for (int j = 0; j < kCharactersNumber; j++) {
float val = output.at<float>(j);
float val = output_row.at<float>(j);
// std::cout << "j:" << j << "val:" << val << std::endl;
if (val > maxVal) {
maxVal = val;
@ -50,7 +51,7 @@ namespace easypr {
else {
result = kCharactersNumber;
for (int j = kCharactersNumber; j < kCharsTotalNumber; j++) {
float val = output.at<float>(j);
float val = output_row.at<float>(j);
//std::cout << "j:" << j << "val:" << val << std::endl;
if (val > maxVal) {
maxVal = val;
@ -63,6 +64,63 @@ namespace easypr {
}
}
void CharsIdentify::classify(std::vector<CCharacter>& charVec){
size_t charVecSize = charVec.size();
Mat featureRows;
for (size_t index = 0; index < charVecSize; index++) {
Mat charInput = charVec[index].getCharacterMat();
Mat feature = charFeatures(charInput, kPredictSize);
featureRows.push_back(feature);
}
cv::Mat output(charVecSize, kCharsTotalNumber, CV_32FC1);
ann_->predict(featureRows, output);
for (size_t output_index = 0; output_index < charVecSize; output_index++) {
CCharacter& character = charVec[output_index];
Mat output_row = output.row(output_index);
int result = -1;
float maxVal = -2.f;
std::string label = "";
bool isChinses = character.getIsChinese();
if (!isChinses) {
result = 0;
for (int j = 0; j < kCharactersNumber; j++) {
float val = output_row.at<float>(j);
//std::cout << "j:" << j << "val:" << val << std::endl;
if (val > maxVal) {
maxVal = val;
result = j;
}
}
label = std::make_pair(kChars[result], kChars[result]).second;
}
else {
result = kCharactersNumber;
for (int j = kCharactersNumber; j < kCharsTotalNumber; j++) {
float val = output_row.at<float>(j);
//std::cout << "j:" << j << "val:" << val << std::endl;
if (val > maxVal) {
maxVal = val;
result = j;
}
}
const char* key = kChars[result];
std::string s = key;
std::string province = kv_->get(s);
label = std::make_pair(s, province).second;
}
/*std::cout << "result:" << result << std::endl;
std::cout << "maxVal:" << maxVal << std::endl;*/
character.setCharacterScore(maxVal);
character.setCharacterStr(label);
}
}
int CharsIdentify::classify(cv::Mat f, float& maxVal, bool isChinses){
int result = -1;

File diff suppressed because it is too large Load Diff

@ -985,8 +985,7 @@ int CPlateLocate::plateMserLocate(Mat src, vector<CPlate> &candPlates, int index
vector<CPlate> plates;
Mat src_b;
for (size_t i = 0; i < channelImages.size(); ++i)
{
for (size_t i = 0; i < channelImages.size(); ++i) {
Mat channelImage = channelImages[i];
Mat image = scaleImage(channelImage, Size(scale_size, scale_size), scale_ratio);
@ -999,13 +998,11 @@ int CPlateLocate::plateMserLocate(Mat src, vector<CPlate> &candPlates, int index
}
}
for (size_t i = 0; i < rects_mser.size(); ++i)
{
for (size_t i = 0; i < rects_mser.size(); ++i) {
Rect_<float> outputRect;
calcSafeRect(rects_mser[i], src, outputRect);
if (0)
{
if (0) {
std::stringstream ss(std::stringstream::in | std::stringstream::out);
ss << "resources/image/tmp/plate_" << i << ".jpg";
imwrite(ss.str(), src(outputRect));
@ -1015,8 +1012,7 @@ int CPlateLocate::plateMserLocate(Mat src, vector<CPlate> &candPlates, int index
plate.setPlateLocateType(CMSER);
plate.setPlateMat(src(outputRect));
plate.setPlatePos(rects_mser[i]);
candPlates.push_back(plate);
//candPlates.push_back(plate);
}
//deskew(src, src_b, rects_mser_blue, plates);

File diff suppressed because it is too large Load Diff

@ -0,0 +1,237 @@
#include "easypr/core/chars_identify.h"
#include "easypr/core/character.hpp"
#include "easypr/config.h"
#include "easypr/core/core_func.h"
namespace easypr {
CharsIdentify* CharsIdentify::instance_ = nullptr;
CharsIdentify* CharsIdentify::instance() {
if (!instance_) {
instance_ = new CharsIdentify;
}
return instance_;
}
CharsIdentify::CharsIdentify() {
ann_ = ml::ANN_MLP::load<ml::ANN_MLP>(kDefaultAnnPath);
kv_ = std::shared_ptr<Kv>(new Kv);
kv_->load("etc/province_mapping");
}
void CharsIdentify::LoadModel(std::string path) {
ann_->clear();
ann_->ml::ANN_MLP::load<ml::ANN_MLP>(path);
}
void CharsIdentify::classify(cv::Mat featureRows, std::vector<int>& out_maxIndexs,
std::vector<float>& out_maxVals, std::vector<bool> isChineseVec){
int rowNum = featureRows.rows;
cv::Mat output(rowNum, kCharsTotalNumber, CV_32FC1);
ann_->predict(featureRows, output);
for (int output_index = 0; output_index < rowNum; output_index++) {
int result = -1;
float maxVal = -2.f;
bool isChinses = isChineseVec[output_index];
if (!isChinses) {
result = 0;
for (int j = 0; j < kCharactersNumber; j++) {
float val = output.at<float>(j);
// std::cout << "j:" << j << "val:" << val << std::endl;
if (val > maxVal) {
maxVal = val;
result = j;
}
}
}
else {
result = kCharactersNumber;
for (int j = kCharactersNumber; j < kCharsTotalNumber; j++) {
float val = output.at<float>(j);
//std::cout << "j:" << j << "val:" << val << std::endl;
if (val > maxVal) {
maxVal = val;
result = j;
}
}
}
out_maxIndexs[output_index] = result;
out_maxVals[output_index] = maxVal;
}
}
void CharsIdentify::classify(std::vector<CCharacter>& charVec){
size_t charVec_size = charVec.size();
Mat featureRows;
for (size_t index = 0; index < charVec_size; index++) {
Mat charInput = charVec[index].getCharacterMat();
Mat feature = charFeatures(charInput, kPredictSize);
featureRows.push_back(feature);
}
int rowNum = featureRows.rows;
cv::Mat output(rowNum, kCharsTotalNumber, CV_32FC1);
ann_->predict(featureRows, output);
for (int output_index = 0; output_index < rowNum; output_index++) {
CCharacter& character = charVec[output_index];
int result = -1;
float maxVal = -2.f;
string label = "";
bool isChinses = character.getIsChinese();
if (!isChinses) {
result = 0;
for (int j = 0; j < kCharactersNumber; j++) {
float val = output.at<float>(j);
// std::cout << "j:" << j << "val:" << val << std::endl;
if (val > maxVal) {
maxVal = val;
result = j;
}
}
}
else {
result = kCharactersNumber;
for (int j = kCharactersNumber; j < kCharsTotalNumber; j++) {
float val = output.at<float>(j);
//std::cout << "j:" << j << "val:" << val << std::endl;
if (val > maxVal) {
maxVal = val;
result = j;
}
}
}
character.setCharacterScore(maxVal);
character.setCharacterStr(result);
}
}
int CharsIdentify::classify(cv::Mat f, float& maxVal, bool isChinses){
int result = -1;
cv::Mat output(1, kCharsTotalNumber, CV_32FC1);
ann_->predict(f, output);
maxVal = -2.f;
if (!isChinses) {
result = 0;
for (int j = 0; j < kCharactersNumber; j++) {
float val = output.at<float>(j);
// std::cout << "j:" << j << "val:" << val << std::endl;
if (val > maxVal) {
maxVal = val;
result = j;
}
}
}
else {
result = kCharactersNumber;
for (int j = kCharactersNumber; j < kCharsTotalNumber; j++) {
float val = output.at<float>(j);
//std::cout << "j:" << j << "val:" << val << std::endl;
if (val > maxVal) {
maxVal = val;
result = j;
}
}
}
//std::cout << "maxVal:" << maxVal << std::endl;
return result;
}
bool CharsIdentify::isCharacter(cv::Mat input, std::string& label, float& maxVal, bool isChinese) {
cv::Mat feature = charFeatures(input, kPredictSize);
auto index = static_cast<int>(classify(feature, maxVal, isChinese));
if (isChinese)
std::cout << "maxVal:" << maxVal << std::endl;
if (maxVal >= 0.9) {
if (index < kCharactersNumber) {
label = std::make_pair(kChars[index], kChars[index]).second;
}
else {
const char* key = kChars[index];
std::string s = key;
std::string province = kv_->get(s);
label = std::make_pair(s, province).second;
}
return true;
}
else
return false;
}
/*bool CharsIdentify::charsJudge(std::vector<CCharacter>& charVec) {
cv::Mat feature = charFeatures(input, kPredictSize);
auto index = static_cast<int>(classify(feature, maxVal, isChinese));
if (isChinese)
std::cout << "maxVal:" << maxVal << std::endl;
if (maxVal >= 0.9) {
if (index < kCharactersNumber) {
label = std::make_pair(kChars[index], kChars[index]).second;
}
else {
const char* key = kChars[index];
std::string s = key;
std::string province = kv_->get(s);
label = std::make_pair(s, province).second;
}
return true;
}
else
return false;
}*/
std::pair<std::string, std::string> CharsIdentify::identify(cv::Mat input, bool isChinese) {
cv::Mat feature = charFeatures(input, kPredictSize);
float maxVal = -2;
auto index = static_cast<int>(classify(feature, maxVal, isChinese));
if (index < kCharactersNumber) {
return std::make_pair(kChars[index], kChars[index]);
}
else {
const char* key = kChars[index];
std::string s = key;
std::string province = kv_->get(s);
return std::make_pair(s, province);
}
}
int CharsIdentify::identify(std::vector<cv::Mat> inputs, std::vector<std::pair<std::string, std::string>>& outputs,
std::vector<bool> isChineseVec) {
Mat featureRows;
size_t input_size = inputs.size();
for (size_t i = 0; i < input_size; i++) {
Mat input = inputs[i];
cv::Mat feature = charFeatures(input, kPredictSize);
featureRows.push_back(feature);
}
std::vector<int> maxIndexs;
std::vector<float> maxVals;
classify(featureRows, maxIndexs, maxVals, isChineseVec);
for (size_t row_index = 0; row_index < input_size; row_index++) {
int index = maxIndexs[row_index];
if (index < kCharactersNumber) {
outputs[row_index] = std::make_pair(kChars[index], kChars[index]);
}
else {
const char* key = kChars[index];
std::string s = key;
std::string province = kv_->get(s);
outputs[row_index] = std::make_pair(s, province);
}
}
return 0;
}
}

@ -95,8 +95,8 @@ namespace easypr {
// 设置要处理的一张图片中最多有多少车牌
pr.setMaxPlates(4);
pr.setDetectType(PR_DETECT_COLOR | PR_DETECT_SOBEL);
//pr.setDetectType(PR_DETECT_CMSER);
//pr.setDetectType(PR_DETECT_COLOR | PR_DETECT_SOBEL);
pr.setDetectType(PR_DETECT_CMSER);
//CPlateDetect pd;
//pd.setDetectType(PR_DETECT_CMSER);

Loading…
Cancel
Save