更新vs工程到端到端模型

This commit is contained in:
iss
2019-07-02 19:47:23 +08:00
parent 33b6f6e346
commit 846d4c7a29
27 changed files with 628 additions and 300 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
//
// Created by 庾金科 on 21/10/2017.
// Created by Jack Yu on 21/10/2017.
//
#ifndef SWIFTPR_CNNRECOGNIZER_H
+60 -85
View File
@@ -1,85 +1,60 @@
//
// Created by ׽ on 22/10/2017.
//
#ifndef SWIFTPR_PIPLINE_H
#define SWIFTPR_PIPLINE_H
#include "PlateDetection.h"
#include "PlateSegmentation.h"
#include "CNNRecognizer.h"
#include "PlateInfo.h"
#include "FastDeskew.h"
#include "FineMapping.h"
#include "Recognizer.h"
namespace pr{
class PipelinePR{
public:
GeneralRecognizer *generalRecognizer;
PlateDetection *plateDetection;
PlateSegmentation *plateSegmentation;
FineMapping *fineMapping;
PipelinePR(std::string detector_filename,
std::string finemapping_prototxt, std::string finemapping_caffemodel,
std::string segmentation_prototxt, std::string segmentation_caffemodel,
std::string charRecognization_proto, std::string charRecognization_caffemodel
) {
plateDetection = new PlateDetection(detector_filename);
fineMapping = new FineMapping(finemapping_prototxt, finemapping_caffemodel);
plateSegmentation = new PlateSegmentation(segmentation_prototxt, segmentation_caffemodel);
generalRecognizer = new CNNRecognizer(charRecognization_proto, charRecognization_caffemodel);
}
~PipelinePR() {
delete plateDetection;
delete fineMapping;
delete plateSegmentation;
delete generalRecognizer;
}
std::vector<std::string> chars_code{ "","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z" };
std::vector<std::string> plateRes;
std::vector<PlateInfo> RunPiplineAsImage(cv::Mat plateImage) {
std::vector<PlateInfo> results;
std::vector<pr::PlateInfo> plates;
plateDetection->plateDetectionRough(plateImage, plates);
for (pr::PlateInfo plateinfo : plates) {
cv::Mat image_finemapping = plateinfo.getPlateImage();
image_finemapping = fineMapping->FineMappingVertical(image_finemapping);
image_finemapping = pr::fastdeskew(image_finemapping, 5);
image_finemapping = fineMapping->FineMappingHorizon(image_finemapping, 2, 5);
cv::resize(image_finemapping, image_finemapping, cv::Size(136, 36));
plateinfo.setPlateImage(image_finemapping);
std::vector<cv::Rect> rects;
plateSegmentation->segmentPlatePipline(plateinfo, 1, rects);
plateSegmentation->ExtractRegions(plateinfo, rects);
cv::copyMakeBorder(image_finemapping, image_finemapping, 0, 0, 0, 20, cv::BORDER_REPLICATE);
plateinfo.setPlateImage(image_finemapping);
generalRecognizer->SegmentBasedSequenceRecognition(plateinfo);
plateinfo.decodePlateNormal(chars_code);
results.push_back(plateinfo);
std::cout << plateinfo.getPlateName() << std::endl;
}
// for (auto str:results) {
// std::cout << str << std::endl;
// }
return results;
}
};
}
#endif //SWIFTPR_PIPLINE_H
//
// Created by 庾金科 on 22/10/2017.
//
#ifndef SWIFTPR_PIPLINE_H
#define SWIFTPR_PIPLINE_H
#include "PlateDetection.h"
#include "PlateSegmentation.h"
#include "CNNRecognizer.h"
#include "PlateInfo.h"
#include "FastDeskew.h"
#include "FineMapping.h"
#include "Recognizer.h"
#include "SegmentationFreeRecognizer.h"
namespace pr{
const std::vector<std::string> CH_PLATE_CODE{"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
"B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
"Y", "Z","","","使","","","","","","","广","","","","","","","",""};
const int SEGMENTATION_FREE_METHOD = 0;
const int SEGMENTATION_BASED_METHOD = 1;
class PipelinePR{
public:
GeneralRecognizer *generalRecognizer;
PlateDetection *plateDetection;
PlateSegmentation *plateSegmentation;
FineMapping *fineMapping;
SegmentationFreeRecognizer *segmentationFreeRecognizer;
PipelinePR(std::string detector_filename,
std::string finemapping_prototxt,std::string finemapping_caffemodel,
std::string segmentation_prototxt,std::string segmentation_caffemodel,
std::string charRecognization_proto,std::string charRecognization_caffemodel,
std::string segmentationfree_proto,std::string segmentationfree_caffemodel
);
~PipelinePR();
std::vector<std::string> plateRes;
std::vector<PlateInfo> RunPiplineAsImage(cv::Mat plateImage,int method);
};
}
#endif //SWIFTPR_PIPLINE_H
+1 -1
View File
@@ -6,7 +6,7 @@
#define SWIFTPR_PLATEDETECTION_H
#include <opencv2/opencv.hpp>
#include "PlateInfo.h"
#include <PlateInfo.h>
#include <vector>
namespace pr{
class PlateDetection{
+9 -10
View File
@@ -10,17 +10,14 @@ namespace pr {
typedef std::vector<cv::Mat> Character;
enum PlateColor { BLUE, YELLOW, WHITE, GREEN, BLACK,UNKNOWN};
enum CharType {CHINESE,LETTER,LETTER_NUMS};
enum CharType {CHINESE,LETTER,LETTER_NUMS,INVALID};
class PlateInfo {
public:
std::vector<std::pair<CharType,cv::Mat>> plateChars;
std::vector<std::pair<CharType,cv::Mat>> plateChars;
std::vector<std::pair<CharType,cv::Mat>> plateCoding;
float confidence = 0;
PlateInfo(const cv::Mat &plateData, std::string plateName, cv::Rect plateRect, PlateColor plateType) {
licensePlate = plateData;
name = plateName;
@@ -93,17 +90,21 @@ namespace pr {
}
if(plate.first == LETTER) {
else if(plate.first == LETTER) {
decode += mappingTable[std::max_element(prob+41,prob+65)- prob];
confidence+=*std::max_element(prob+41,prob+65);
}
if(plate.first == LETTER_NUMS) {
else if(plate.first == LETTER_NUMS) {
decode += mappingTable[std::max_element(prob+31,prob+65)- prob];
confidence+=*std::max_element(prob+31,prob+65);
// std::cout<<*std::max_element(prob+31,prob+65)<<std::endl;
}
else if(plate.first == INVALID)
{
decode+='*';
}
}
name = decode;
@@ -113,12 +114,10 @@ namespace pr {
return decode;
}
private:
cv::Mat licensePlate;
cv::Rect ROI;
std::string name;
std::string name ;
PlateColor Type;
};
}
-4
View File
@@ -1,7 +1,3 @@
//
// Created by 庾金科 on 16/10/2017.
//
#ifndef SWIFTPR_PLATESEGMENTATION_H
#define SWIFTPR_PLATESEGMENTATION_H
+2
View File
@@ -13,7 +13,9 @@ namespace pr{
class GeneralRecognizer{
public:
virtual label recognizeCharacter(cv::Mat character) = 0;
// virtual cv::Mat SegmentationFreeForSinglePlate(cv::Mat plate) = 0;
void SegmentBasedSequenceRecognition(PlateInfo &plateinfo);
void SegmentationFreeSequenceRecognition(PlateInfo &plateInfo);
};
@@ -0,0 +1,28 @@
//
// Created by 庾金科 on 28/11/2017.
//
#ifndef SWIFTPR_SEGMENTATIONFREERECOGNIZER_H
#define SWIFTPR_SEGMENTATIONFREERECOGNIZER_H
#include "Recognizer.h"
namespace pr{
class SegmentationFreeRecognizer{
public:
const int CHAR_INPUT_W = 14;
const int CHAR_INPUT_H = 30;
const int CHAR_LEN = 84;
SegmentationFreeRecognizer(std::string prototxt,std::string caffemodel);
std::pair<std::string,float> SegmentationFreeForSinglePlate(cv::Mat plate,std::vector<std::string> mapping_table);
private:
cv::dnn::Net net;
};
}
#endif //SWIFTPR_SEGMENTATIONFREERECOGNIZER_H
+5 -3
View File
@@ -62,8 +62,9 @@ void niBlackThreshold( InputArray _src, OutputArray _dst, double maxValue,
thresh = mean + static_cast<float>(k) * sqrtVarianceMeanSum;
break;
default:
CV_Error( CV_StsBadArg, "Unknown binarization method" );
break;
// CV_Error( CV_StsBadArg, "Unknown binarization method" );
CV_Error(-5, "Unknown binarization method");
break;
}
thresh.convertTo(thresh, src.depth());
@@ -99,7 +100,8 @@ void niBlackThreshold( InputArray _src, OutputArray _dst, double maxValue,
src.copyTo(dst, mask);
break;
default:
CV_Error( CV_StsBadArg, "Unknown threshold type" );
// CV_Error( CV_StsBadArg, "Unknown threshold type" );
CV_Error(-5, "Unknown threshold type");
break;
}
}