up e2e cpp
parent
e004f4e4e5
commit
99bf200138
@ -1,37 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.6)
|
|
||||||
project(SwiftPR)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
||||||
add_library( lib_opencv SHARED IMPORTED )
|
|
||||||
|
|
||||||
|
|
||||||
find_library( # Sets the name of the path variable.
|
|
||||||
log-lib
|
|
||||||
|
|
||||||
# Specifies the name of the NDK library that
|
|
||||||
# you want CMake to locate.
|
|
||||||
log )
|
|
||||||
|
|
||||||
|
|
||||||
include_directories(/Users/yujinke/Downloads/OpenCV-android-sdk-3.3/sdk/native/jni/include)
|
|
||||||
include_directories(include)
|
|
||||||
|
|
||||||
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libopencv_java3.so)
|
|
||||||
|
|
||||||
set(SRC_DETECTION src/PlateDetection.cpp src/util.h include/PlateDetection.h)
|
|
||||||
|
|
||||||
set(SRC_FINEMAPPING src/FineMapping.cpp )
|
|
||||||
|
|
||||||
set(SRC_FASTDESKEW src/FastDeskew.cpp )
|
|
||||||
|
|
||||||
set(SRC_SEGMENTATION src/PlateSegmentation.cpp )
|
|
||||||
|
|
||||||
set(SRC_RECOGNIZE src/Recognizer.cpp src/CNNRecognizer.cpp)
|
|
||||||
|
|
||||||
set(SRC_PIPLINE src/Pipeline.cpp)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
add_library(hyperlpr SHARED ${SRC_DETECTION} ${SRC_FINEMAPPING} ${SRC_FASTDESKEW} ${SRC_SEGMENTATION} ${SRC_RECOGNIZE} ${SRC_PIPLINE} javaWarpper.cpp)
|
|
||||||
|
|
||||||
target_link_libraries(hyperlpr lib_opencv ${log-lib})
|
|
@ -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
|
@ -0,0 +1,118 @@
|
|||||||
|
//
|
||||||
|
// Created by 庾金科 on 28/11/2017.
|
||||||
|
//
|
||||||
|
#include "../include/SegmentationFreeRecognizer.h"
|
||||||
|
|
||||||
|
namespace pr {
|
||||||
|
SegmentationFreeRecognizer::SegmentationFreeRecognizer(std::string prototxt, std::string caffemodel) {
|
||||||
|
net = cv::dnn::readNetFromCaffe(prototxt, caffemodel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline int judgeCharRange(int id)
|
||||||
|
{return id<31 || id>63;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::pair<std::string,float> decodeResults(cv::Mat code_table,std::vector<std::string> mapping_table,float thres)
|
||||||
|
{
|
||||||
|
// cv::imshow("imagea",code_table);
|
||||||
|
// cv::waitKey(0);
|
||||||
|
|
||||||
|
cv::MatSize mtsize = code_table.size;
|
||||||
|
int sequencelength = mtsize[2];
|
||||||
|
int labellength = mtsize[1];
|
||||||
|
cv::transpose(code_table.reshape(1,1).reshape(1,labellength),code_table);
|
||||||
|
std::string name = "";
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<int> seq(sequencelength);
|
||||||
|
std::vector<std::pair<int,float>> seq_decode_res;
|
||||||
|
|
||||||
|
for(int i = 0 ; i < sequencelength; i++) {
|
||||||
|
float *fstart = ((float *) (code_table.data) + i * labellength );
|
||||||
|
int id = std::max_element(fstart,fstart+labellength) - fstart;
|
||||||
|
seq[i] =id;
|
||||||
|
}
|
||||||
|
|
||||||
|
float sum_confidence = 0;
|
||||||
|
|
||||||
|
int plate_lenghth = 0 ;
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0 ; i< sequencelength ; i++)
|
||||||
|
{
|
||||||
|
if(seq[i]!=labellength-1 && (i==0 || seq[i]!=seq[i-1]))
|
||||||
|
{
|
||||||
|
float *fstart = ((float *) (code_table.data) + i * labellength );
|
||||||
|
float confidence = *(fstart+seq[i]);
|
||||||
|
std::pair<int,float> pair_(seq[i],confidence);
|
||||||
|
seq_decode_res.push_back(pair_);
|
||||||
|
//
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
if(judgeCharRange(seq_decode_res[0].first) && judgeCharRange(seq_decode_res[1].first))
|
||||||
|
{
|
||||||
|
i=2;
|
||||||
|
int c = seq_decode_res[0].second<seq_decode_res[1].second;
|
||||||
|
name+=mapping_table[seq_decode_res[c].first];
|
||||||
|
sum_confidence+=seq_decode_res[c].second;
|
||||||
|
plate_lenghth++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(; i < seq_decode_res.size();i++)
|
||||||
|
{
|
||||||
|
name+=mapping_table[seq_decode_res[i].first];
|
||||||
|
sum_confidence +=seq_decode_res[i].second;
|
||||||
|
plate_lenghth++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::pair<std::string,float> res;
|
||||||
|
|
||||||
|
res.second = sum_confidence/plate_lenghth;
|
||||||
|
res.first = name;
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string decodeResults(cv::Mat code_table,std::vector<std::string> mapping_table)
|
||||||
|
{
|
||||||
|
cv::MatSize mtsize = code_table.size;
|
||||||
|
int sequencelength = mtsize[2];
|
||||||
|
int labellength = mtsize[1];
|
||||||
|
cv::transpose(code_table.reshape(1,1).reshape(1,labellength),code_table);
|
||||||
|
std::string name = "";
|
||||||
|
std::vector<int> seq(sequencelength);
|
||||||
|
for(int i = 0 ; i < sequencelength; i++) {
|
||||||
|
float *fstart = ((float *) (code_table.data) + i * labellength );
|
||||||
|
int id = std::max_element(fstart,fstart+labellength) - fstart;
|
||||||
|
seq[i] =id;
|
||||||
|
}
|
||||||
|
for(int i = 0 ; i< sequencelength ; i++)
|
||||||
|
{
|
||||||
|
if(seq[i]!=labellength-1 && (i==0 || seq[i]!=seq[i-1]))
|
||||||
|
name+=mapping_table[seq[i]];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<<name;
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::pair<std::string,float> SegmentationFreeRecognizer::SegmentationFreeForSinglePlate(cv::Mat Image,std::vector<std::string> mapping_table) {
|
||||||
|
cv::transpose(Image,Image);
|
||||||
|
cv::Mat inputBlob = cv::dnn::blobFromImage(Image, 1 / 255.0, cv::Size(40,160));
|
||||||
|
net.setInput(inputBlob, "data");
|
||||||
|
cv::Mat char_prob_mat = net.forward();
|
||||||
|
return decodeResults(char_prob_mat,mapping_table,0.00);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue