You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.3 KiB
C++

7 years ago
//
// Created by Coleflowers on 20/06/2018.
// Updated by Justid on 02/07/2018.
7 years ago
//
#include <phpcpp.h>
#include <iostream>
#include "PlateSegmentation.h"
#include "CNNRecognizer.h"
#include "Recognizer.h"
#include "PlateDetection.h"
#include "FastDeskew.h"
#include "FineMapping.h"
#include "Pipeline.h"
7 years ago
/* 关闭原opencv报错输出 */
int handleError( int status, const char* func_name,
const char* err_msg, const char* file_name,
int line, void* userdata )
{
//Do nothing -- will suppress console output
return 0; //Return value is not used
}
7 years ago
/**
*
* @params imgpath
* @params modelpath
* @params confidence 0.75
7 years ago
* @return
*/
cv::String scan(std::string imgpath, std::string modelpath, double confidence){
cv::redirectError(handleError);
try {
pr::PipelinePR prc(modelpath+"/cascade.xml",
modelpath+"/HorizonalFinemapping.prototxt",modelpath+"/HorizonalFinemapping.caffemodel",
modelpath+"/Segmentation.prototxt",modelpath+"/Segmentation.caffemodel",
modelpath+"/CharacterRecognization.prototxt",modelpath+"/CharacterRecognization.caffemodel",
modelpath+"/SegmentationFree.prototxt",modelpath+"/SegmentationFree.caffemodel"
);
cv::Mat image = cv::imread(imgpath);
std::vector<pr::PlateInfo> res = prc.RunPiplineAsImage(image,pr::SEGMENTATION_FREE_METHOD);
7 years ago
cv::String platenum = "";
for(auto st:res) {
if(st.confidence>confidence) {
platenum = st.getPlateName();
break;
}
}
7 years ago
return platenum;
}
catch( cv::Exception& e )
{
const char* err_msg = e.what();
throw Php::Exception(err_msg);
}
7 years ago
}
Php::Value funcWrapper(Php::Parameters &params) {
// 图片路径
std::string img = params[0];
// 模型路径(文件夹)
std::string model = params[1];
// 可信度要求
double confidence = 0.75;
if (params.size() == 3){
confidence = (double)params[2];
}
7 years ago
cv::String res = scan(img, model, confidence);
return res.c_str();
7 years ago
}
/**
* tell the compiler that the get_module is a pure C function
*/
extern "C" {
/**
* Function that is called by PHP right after the PHP process
* has started, and that returns an address of an internal PHP
* strucure with all the details and features of your extension
*
* @return void* a pointer to an address that is understood by PHP
*/
PHPCPP_EXPORT void *get_module() {
// static(!) Php::Extension object that should stay in memory
// for the entire duration of the process (that's why it's static)
static Php::Extension extension("platescan", "1.0");
// @todo add your own functions, classes, namespaces to the extension
extension.add<funcWrapper>("platescan", {
Php::ByVal("imgpath", Php::Type::String, true),
Php::ByVal("modelpath", Php::Type::String, true),
Php::ByVal("confidence", Php::Type::Float, false)
});
7 years ago
// return the extension
return extension;
}
}