add cpp and android

This commit is contained in:
jackyu
2017-10-28 22:53:09 +08:00
parent 58a4b33392
commit c524d33cfb
386 changed files with 44466 additions and 3 deletions
@@ -0,0 +1,4 @@
//
// Created by 庾金科 on 26/10/2017.
//
@@ -0,0 +1,34 @@
//
// Created by 庾金科 on 20/09/2017.
//
#include <../include/PlateDetection.h>
void drawRect(cv::Mat image,cv::Rect rect)
{
cv::Point p1(rect.x,rect.y);
cv::Point p2(rect.x+rect.width,rect.y+rect.height);
cv::rectangle(image,p1,p2,cv::Scalar(0,255,0),1);
}
int main()
{
cv::Mat image = cv::imread("res/test1.jpg");
pr::PlateDetection plateDetection("model/cascade.xml");
std::vector<pr::PlateInfo> plates;
plateDetection.plateDetectionRough(image,plates);
for(pr::PlateInfo platex:plates)
{
drawRect(image,platex.getPlateRect());
cv::imwrite("res/cache/test.png",platex.getPlateImage());
cv::imshow("image",platex.getPlateImage());
cv::waitKey(0);
}
cv::imshow("image",image);
cv::waitKey(0);
return 0 ;
}
@@ -0,0 +1,34 @@
//
// Created by 庾金科 on 02/10/2017.
//
#include <../include/FastDeskew.h>
void drawRect(cv::Mat image,cv::Rect rect)
{
cv::Point p1(rect.x,rect.y);
cv::Point p2(rect.x+rect.width,rect.y+rect.height);
cv::rectangle(image,p1,p2,cv::Scalar(0,255,0),1);
}
void TEST_DESKEW(){
cv::Mat image = cv::imread("res/3.png",cv::IMREAD_GRAYSCALE);
// cv::resize(image,image,cv::Size(136*2,36*2));
cv::Mat deskewed = pr::fastdeskew(image,12);
// cv::imwrite("./res/4.png",deskewed);
// cv::Mat deskewed2 = pr::fastdeskew(deskewed,12);
//
cv::imshow("image",deskewed);
cv::waitKey(0);
}
int main()
{
TEST_DESKEW();
return 0 ;
}
@@ -0,0 +1,25 @@
//
// Created by 庾金科 on 24/09/2017.
//
#include "FineMapping.h"
int main()
{
cv::Mat image = cv::imread("res/cache/test.png");
cv::Mat image_finemapping = pr::FineMapping::FineMappingVertical(image);
pr::FineMapping finemapper = pr::FineMapping("model/HorizonalFinemapping.prototxt","model/HorizonalFinemapping.caffemodel");
image_finemapping = finemapper.FineMappingHorizon(image_finemapping,0,-3);
cv::imwrite("res/cache/finemappingres.png",image_finemapping);
cv::imshow("image",image_finemapping);
cv::waitKey(0);
return 0 ;
}
@@ -0,0 +1,41 @@
//
// Created by 庾金科 on 23/10/2017.
//
#include "../include/Pipeline.h"
void TEST_PIPELINE(){
pr::PipelinePR prc("model/cascade.xml",
"model/HorizonalFinemapping.prototxt","model/HorizonalFinemapping.caffemodel",
"model/Segmentation.prototxt","model/Segmentation.caffemodel",
"model/CharacterRecognization.prototxt","model/CharacterRecognization.caffemodel"
);
cv::Mat image = cv::imread("/Users/yujinke/车牌图片/云南车牌/云A1DZ32.jpg");
cv::imshow("image",image);
cv::waitKey(0);
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;
}
int main()
{
TEST_PIPELINE();
return 0 ;
}
@@ -0,0 +1,53 @@
//
// Created by 庾金科 on 23/10/2017.
//
#include "../include/CNNRecognizer.h"
std::vector<std::string> chars{"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"};
#include <opencv2/dnn.hpp>
using namespace cv::dnn;
void getMaxClass(cv::Mat &probBlob, int *classId, double *classProb)
{
// cv::Mat probMat = probBlob.matRefConst().reshape(1, 1); //reshape the blob to 1x1000 matrix
cv::Point classNumber;
cv::minMaxLoc(probBlob, NULL, classProb, NULL, &classNumber);
*classId = classNumber.x;
}
void TEST_RECOGNIZATION(){
// pr::CNNRecognizer instance("model/CharacterRecognization.prototxt","model/CharacterRecognization.caffemodel");
Net net = cv::dnn::readNetFromCaffe("model/CharacterRecognization.prototxt","model/CharacterRecognization.caffemodel");
cv::Mat image = cv::imread("res/char1.png",cv::IMREAD_GRAYSCALE);
cv::resize(image,image,cv::Size(14,30));
cv::equalizeHist(image,image);
cv::Mat inputBlob = cv::dnn::blobFromImage(image, 1/255.0, cv::Size(14,30), false);
net.setInput(inputBlob,"data");
cv::Mat res = net.forward();
std::cout<<res<<std::endl;
float *p = (float*)res.data;
int maxid= 0;
double prob = 0;
getMaxClass(res,&maxid,&prob);
std::cout<<chars[maxid]<<std::endl;
};
int main()
{TEST_RECOGNIZATION();
}
@@ -0,0 +1,43 @@
//
// Created by 庾金科 on 16/10/2017.
//
#include "../include/PlateSegmentation.h"
#include "../include/CNNRecognizer.h"
#include "../include/Recognizer.h"
std::vector<std::string> chars{"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","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"};
void TEST_SLIDINGWINDOWS_EVAL(){
cv::Mat demo = cv::imread("res/cache/finemappingres.png");
cv::resize(demo,demo,cv::Size(136,36));
cv::Mat respones;
pr::PlateSegmentation plateSegmentation("model/Segmentation.prototxt","model/Segmentation.caffemodel");
pr::PlateInfo plate;
plate.setPlateImage(demo);
std::vector<cv::Rect> rects;
plateSegmentation.segmentPlatePipline(plate,1,rects);
plateSegmentation.ExtractRegions(plate,rects);
pr::GeneralRecognizer *recognizer = new pr::CNNRecognizer("model/CharacterRecognization.prototxt","model/CharacterRecognization.caffemodel");
recognizer->SegmentBasedSequenceRecognition(plate);
std::cout<<plate.decodePlateNormal(chars)<<std::endl;
delete(recognizer);
}
int main(){
TEST_SLIDINGWINDOWS_EVAL();
return 0;
}