更新vs工程到端到端模型
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Created by 庾金科 on 02/10/2017.
|
||||
// Created by Jack Yu on 02/10/2017.
|
||||
//
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Created by 庾金科 on 24/09/2017.
|
||||
// Created by Jack Yu on 24/09/2017.
|
||||
//
|
||||
|
||||
#include "FineMapping.h"
|
||||
@@ -22,4 +22,4 @@ int main()
|
||||
|
||||
return 0 ;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +1,229 @@
|
||||
//
|
||||
// Created by 庾金科 on 23/10/2017.
|
||||
//
|
||||
// Created by Jack Yu on 23/10/2017.
|
||||
//
|
||||
|
||||
#include "../include/Pipeline.h"
|
||||
using namespace pr;
|
||||
#include<fstream>
|
||||
#include<vector>
|
||||
|
||||
void TEST_PIPELINE(){
|
||||
|
||||
pr::PipelinePR prc("../lpr/model/cascade.xml",
|
||||
"../lpr/model/HorizonalFinemapping.prototxt","../lpr/model/HorizonalFinemapping.caffemodel",
|
||||
"../lpr/model/Segmentation.prototxt","../lpr/model/Segmentation.caffemodel",
|
||||
"../lpr/model/CharacterRecognization.prototxt","../lpr/model/CharacterRecognization.caffemodel"
|
||||
);
|
||||
|
||||
cv::Mat image = cv::imread("../6.jpg");
|
||||
cv::imshow("image",image);
|
||||
cv::waitKey(0);
|
||||
using namespace std;
|
||||
|
||||
std::vector<pr::PlateInfo> res = prc.RunPiplineAsImage(image);
|
||||
float conf = 0 ;
|
||||
for(auto st:res) {
|
||||
if(st.confidence>0.1) {
|
||||
std::cout << st.getPlateName() << " " << st.confidence << std::endl;
|
||||
conf += st.confidence;
|
||||
}
|
||||
}
|
||||
std::cout<<conf<<std::endl;
|
||||
system("pause");
|
||||
|
||||
template<class T>
|
||||
static unsigned int levenshtein_distance(const T &s1, const T &s2) {
|
||||
const size_t len1 = s1.size(), len2 = s2.size();
|
||||
std::vector<unsigned int> col(len2 + 1), prevCol(len2 + 1);
|
||||
|
||||
for (unsigned int i = 0; i < prevCol.size(); i++) prevCol[i] = i;
|
||||
for (unsigned int i = 0; i < len1; i++) {
|
||||
col[0] = i + 1;
|
||||
for (unsigned int j = 0; j < len2; j++)
|
||||
col[j + 1] = min(
|
||||
min(prevCol[1 + j] + 1, col[j] + 1),
|
||||
prevCol[j] + (s1[i] == s2[j] ? 0 : 1));
|
||||
col.swap(prevCol);
|
||||
}
|
||||
return prevCol[len2];
|
||||
}
|
||||
|
||||
|
||||
void TEST_CAM()
|
||||
{
|
||||
cv::VideoCapture capture("test1.mp4");
|
||||
cv::Mat frame;
|
||||
pr::PipelinePR prc("../lpr/model/cascade.xml",
|
||||
"../lpr/model/HorizonalFinemapping.prototxt", "../lpr/model/HorizonalFinemapping.caffemodel",
|
||||
"../lpr/model/Segmentation.prototxt", "../lpr/model/Segmentation.caffemodel",
|
||||
"../lpr/model/CharacterRecognization.prototxt", "../lpr/model/CharacterRecognization.caffemodel",
|
||||
"../lpr/model/SegmentationFree.prototxt", "../lpr/model/SegmentationFree.caffemodel"
|
||||
);
|
||||
while (1) {
|
||||
//读取下一帧
|
||||
if (!capture.read(frame)) {
|
||||
std::cout << "读取视频失败" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
//
|
||||
// cv::transpose(frame,frame);
|
||||
// cv::flip(frame,frame,2);
|
||||
|
||||
// cv::resize(frame,frame,cv::Size(frame.cols/2,frame.rows/2));
|
||||
|
||||
|
||||
std::vector<pr::PlateInfo> res = prc.RunPiplineAsImage(frame, pr::SEGMENTATION_FREE_METHOD);
|
||||
|
||||
for (auto st : res) {
|
||||
if (st.confidence > 0.75) {
|
||||
std::cout << st.getPlateName() << " " << st.confidence << std::endl;
|
||||
cv::Rect region = st.getPlateRect();
|
||||
|
||||
cv::rectangle(frame, cv::Point(region.x, region.y), cv::Point(region.x + region.width, region.y + region.height), cv::Scalar(255, 255, 0), 2);
|
||||
}
|
||||
}
|
||||
|
||||
cv::imshow("image", frame);
|
||||
cv::waitKey(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TEST_ACC() {
|
||||
|
||||
pr::PipelinePR prc("../lpr/model/cascade.xml",
|
||||
"../lpr/model/HorizonalFinemapping.prototxt", "../lpr/model/HorizonalFinemapping.caffemodel",
|
||||
"../lpr/model/Segmentation.prototxt", "../lpr/model/Segmentation.caffemodel",
|
||||
"../lpr/model/CharacterRecognization.prototxt", "../lpr/model/CharacterRecognization.caffemodel",
|
||||
"../lpr/model/SegmentationFree.prototxt", "../lpr/model/SegmentationFree.caffemodel"
|
||||
);
|
||||
|
||||
ifstream file;
|
||||
string imagename;
|
||||
int n = 0, correct = 0, j = 0, sum = 0;
|
||||
char filename[] = "/Users/yujinke/Downloads/general_test/1.txt";
|
||||
string pathh = "/Users/yujinke/Downloads/general_test/";
|
||||
file.open(filename, ios::in);
|
||||
while (!file.eof())
|
||||
{
|
||||
file >> imagename;
|
||||
string imgpath = pathh + imagename;
|
||||
std::cout << "------------------------------------------------" << endl;
|
||||
cout << "图片名:" << imagename << endl;
|
||||
cv::Mat image = cv::imread(imgpath);
|
||||
// cv::imshow("image", image);
|
||||
// cv::waitKey(0);
|
||||
|
||||
std::vector<pr::PlateInfo> res = prc.RunPiplineAsImage(image, pr::SEGMENTATION_FREE_METHOD);
|
||||
|
||||
float conf = 0;
|
||||
vector<float> con;
|
||||
vector<string> name;
|
||||
for (auto st : res) {
|
||||
if (st.confidence > 0.1) {
|
||||
//std::cout << st.getPlateName() << " " << st.confidence << std::endl;
|
||||
con.push_back(st.confidence);
|
||||
name.push_back(st.getPlateName());
|
||||
//conf += st.confidence;
|
||||
}
|
||||
else
|
||||
cout << "no string" << endl;
|
||||
}
|
||||
// std::cout << conf << std::endl;
|
||||
int num = con.size();
|
||||
float max = 0;
|
||||
string platestr, chpr, ch;
|
||||
int diff = 0, dif = 0;
|
||||
for (int i = 0; i < num; i++) {
|
||||
|
||||
if (con.at(i) > max)
|
||||
{
|
||||
max = con.at(i);
|
||||
platestr = name.at(i);
|
||||
}
|
||||
|
||||
}
|
||||
// cout << "max:"<<max << endl;
|
||||
cout << "string:" << platestr << endl;
|
||||
chpr = platestr.substr(0, 2);
|
||||
ch = imagename.substr(0, 2);
|
||||
diff = levenshtein_distance(imagename, platestr);
|
||||
dif = diff - 4;
|
||||
cout << "差距:" << dif << endl;
|
||||
sum += dif;
|
||||
if (ch != chpr) n++;
|
||||
if (diff == 0) correct++;
|
||||
j++;
|
||||
}
|
||||
float cha = 1 - float(n) / float(j);
|
||||
std::cout << "------------------------------------------------" << endl;
|
||||
cout << "车牌总数:" << j << endl;
|
||||
cout << "汉字识别准确率:" << cha << endl;
|
||||
float chaccuracy = 1 - float(sum - n * 2) / float(j * 8);
|
||||
cout << "字符识别准确率:" << chaccuracy << endl;
|
||||
|
||||
}
|
||||
int main()
|
||||
|
||||
|
||||
void TEST_PIPELINE() {
|
||||
|
||||
pr::PipelinePR prc("../lpr/model/cascade.xml",
|
||||
"../lpr/model/HorizonalFinemapping.prototxt", "../lpr/model/HorizonalFinemapping.caffemodel",
|
||||
"../lpr/model/Segmentation.prototxt", "../lpr/model/Segmentation.caffemodel",
|
||||
"../lpr/model/CharacterRecognization.prototxt", "../lpr/model/CharacterRecognization.caffemodel",
|
||||
"../lpr/model/SegmentationFree.prototxt", "../lpr/model/SegmentationFree.caffemodel"
|
||||
);
|
||||
|
||||
cv::Mat image = cv::imread("../lpr/res/test.jpg");
|
||||
|
||||
|
||||
std::vector<pr::PlateInfo> res = prc.RunPiplineAsImage(image, pr::SEGMENTATION_FREE_METHOD);
|
||||
|
||||
for (auto st : res) {
|
||||
if (st.confidence > 0.75) {
|
||||
std::cout << st.getPlateName() << " " << st.confidence << std::endl;
|
||||
cv::Rect region = st.getPlateRect();
|
||||
|
||||
cv::rectangle(image, cv::Point(region.x, region.y), cv::Point(region.x + region.width, region.y + region.height), cv::Scalar(255, 255, 0), 2);
|
||||
}
|
||||
}
|
||||
|
||||
cv::imshow("image", image);
|
||||
cv::waitKey(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*void TEST_CAM()
|
||||
{
|
||||
|
||||
TEST_PIPELINE();
|
||||
cv::VideoCapture capture("test1.mp4");
|
||||
cv::Mat frame;
|
||||
|
||||
pr::PipelinePR prc("../lpr/model/cascade.xml",
|
||||
"../lpr/model/HorizonalFinemapping.prototxt", "../lpr/model/HorizonalFinemapping.caffemodel",
|
||||
"../lpr/model/Segmentation.prototxt", "../lpr/model/Segmentation.caffemodel",
|
||||
"../lpr/model/CharacterRecognization.prototxt", "../lpr/model/CharacterRecognization.caffemodel",
|
||||
"../lpr/model/SegmentationFree.prototxt", "../lpr/model/SegmentationFree.caffemodel"
|
||||
);
|
||||
while (1) {
|
||||
//读取下一帧
|
||||
if (!capture.read(frame)) {
|
||||
std::cout << "读取视频失败" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
//
|
||||
// cv::transpose(frame,frame);
|
||||
// cv::flip(frame,frame,2);
|
||||
|
||||
// cv::resize(frame,frame,cv::Size(frame.cols/2,frame.rows/2));
|
||||
|
||||
|
||||
return 0 ;
|
||||
|
||||
std::vector<pr::PlateInfo> res = prc.RunPiplineAsImage(frame, pr::SEGMENTATION_FREE_METHOD);
|
||||
|
||||
for (auto st : res) {
|
||||
if (st.confidence > 0.75) {
|
||||
std::cout << st.getPlateName() << " " << st.confidence << std::endl;
|
||||
cv::Rect region = st.getPlateRect();
|
||||
|
||||
cv::rectangle(frame, cv::Point(region.x, region.y), cv::Point(region.x + region.width, region.y + region.height), cv::Scalar(255, 255, 0), 2);
|
||||
}
|
||||
}
|
||||
|
||||
cv::imshow("image", frame);
|
||||
cv::waitKey(1);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
int main()
|
||||
{
|
||||
// TEST_ACC();
|
||||
|
||||
// TEST_CAM();
|
||||
TEST_PIPELINE();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Created by 庾金科 on 23/10/2017.
|
||||
// Created by Jack Yu on 23/10/2017.
|
||||
//
|
||||
|
||||
#include "../include/CNNRecognizer.h"
|
||||
@@ -16,6 +16,7 @@ void getMaxClass(cv::Mat &probBlob, int *classId, double *classProb)
|
||||
cv::Point classNumber;
|
||||
|
||||
cv::minMaxLoc(probBlob, NULL, classProb, NULL, &classNumber);
|
||||
|
||||
*classId = classNumber.x;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Created by 庾金科 on 16/10/2017.
|
||||
// Created by Jack Yu on 16/10/2017.
|
||||
//
|
||||
|
||||
|
||||
@@ -40,4 +40,4 @@ int main(){
|
||||
TEST_SLIDINGWINDOWS_EVAL();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// Created by Jack Yu on 29/11/2017.
|
||||
//
|
||||
#include "../include/SegmentationFreeRecognizer.h"
|
||||
#include "../include/Pipeline.h"
|
||||
|
||||
#include "../include/PlateInfo.h"
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
cv::Mat image = cv::imread("res/cache/chars_segment.jpg");
|
||||
// cv::transpose(image,image);
|
||||
|
||||
// cv::resize(image,image,cv::Size(160,40));
|
||||
cv::imshow("xxx",image);
|
||||
cv::waitKey(0);
|
||||
pr::SegmentationFreeRecognizer recognizr("model/SegmenationFree-Inception.prototxt","model/ISegmenationFree-Inception.caffemodel");
|
||||
std::pair<std::string,float> res = recognizr.SegmentationFreeForSinglePlate(image,pr::CH_PLATE_CODE);
|
||||
std::cout<<res.first<<" "
|
||||
<<res.second<<std::endl;
|
||||
|
||||
|
||||
// decodeResults(plate,pr::CH_PLATE_CODE);
|
||||
cv::imshow("image",image);
|
||||
cv::waitKey(0);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user