#include "detector.h"
|
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include "TH_PlateID.h"
|
|
#include "csdk_struct.h"
|
|
namespace csdk_wrap
|
{
|
static TH_PlateIDCfg config;
|
static unsigned char *fmem;
|
static unsigned char *pmem;
|
|
void init_plate_id_config(const cPlateIDCfg *params);
|
void set_enable_plate_format(const cPlateIDCfg *params);
|
|
int init_plate_id_detector(const cPlateIDCfg *params, char *soPath) {
|
// 初始化配置参数
|
init_plate_id_config(params);
|
|
// 设置Licence Manager运行路径
|
int ret = TH_SetSoPath(soPath);
|
printf("TH_SetSoPath ret %d\n", ret);
|
// 初始化 sdk
|
ret = TH_InitPlateIDSDK(&config);
|
printf("TH_InitPlateIDSDK ret %d\n", ret);
|
|
// 设置车牌类型识别
|
set_enable_plate_format(params);
|
|
// 设置识别阈值
|
TH_SetRecogThreshold(params->bLocateTh, params->bOCRTh, &config);
|
|
return ret;
|
}
|
|
void init_plate_id_config(const cPlateIDCfg *params) {
|
int fMemSize = params->nFastMemorySize * 1024;
|
int pMemSize = params->nMemorySize * 1024 * 1024;
|
|
fmem = (unsigned char*)malloc(fMemSize * sizeof(unsigned char));
|
pmem = (unsigned char*)malloc(pMemSize * sizeof(unsigned char));
|
|
// 默认参数
|
config.nMinPlateWidth = 60;
|
config.nMaxPlateWidth = 400;
|
config.bVertCompress = 0;
|
config.nImageFormat = ImageFormatBGR;
|
config.bOutputSingleFrame = 1;
|
config.bUTF8 = 1;
|
|
config.pFastMemory = fmem;
|
config.nFastMemorySize = fMemSize;
|
config.pMemory = pmem;
|
config.nMemorySize= pMemSize;
|
|
if (params->nMinPlateWidth > 60 && params->nMinPlateWidth < 400) {
|
config.nMinPlateWidth = params->nMinPlateWidth;
|
}
|
if (params->nMaxPlateWidth > 60 && params->nMaxPlateWidth < 400) {
|
config.nMaxPlateWidth = params->nMaxPlateWidth;
|
}
|
|
config.nMaxImageWidth = params->nMaxImageWidth;
|
config.nMaxImageHeight = params->nMaxImageHeight;
|
config.bIsFieldImage = params->bIsFieldImage;
|
config.bMovingImage = params->bMovingImage;
|
config.nOrderOpt = params->nOrderOpt;
|
config.bLeanCorrection = params->bLeanCorrection;
|
config.nImproveSpeed = params->nImproveSpeed;
|
config.bCarLogo = params->bCarLogo;
|
config.bLotDetect = params->bLotDetect;
|
config.bShadow = params->bShadow;
|
config.bShieldRailing = params->bShieldRailing;
|
config.bCarModel = params->bCarModel;
|
}
|
|
void set_enable_plate_format(const cPlateIDCfg *params) {
|
if (params->bOnlyLocation == 1) {
|
TH_SetEnabledPlateFormat(PARAM_ONLY_LOCATION_ON, &config);
|
return;
|
}
|
if (params->bOnlyTwoRowYellow == 1) {
|
TH_SetEnabledPlateFormat(PARAM_ONLY_TWOROWYELLOW_ON, &config);
|
return;
|
}
|
if (params->bIndividual == 1) {
|
TH_SetEnabledPlateFormat(PARAM_INDIVIDUAL_ON, &config);
|
}
|
if (params->bTwoRowYellow == 1) {
|
TH_SetEnabledPlateFormat(PARAM_TWOROWYELLOW_ON, &config);
|
}
|
if (params->bArmPolice == 1) {
|
TH_SetEnabledPlateFormat(PARAM_ARMPOLICE_ON, &config);
|
}
|
if (params->bArmPolice2 == 1) {
|
TH_SetEnabledPlateFormat(PARAM_ARMPOLICE2_ON, &config);
|
}
|
if (params->bTwoRowArmy == 1) {
|
TH_SetEnabledPlateFormat(PARAM_TWOROWARMY_ON, &config);
|
}
|
if (params->bTractor == 1) {
|
TH_SetEnabledPlateFormat(PARAM_TRACTOR_ON, &config);
|
}
|
if (params->bEmbassy == 1) {
|
TH_SetEnabledPlateFormat(PARAM_EMBASSY_ON, &config);
|
}
|
if (params->bChangNei == 1) {
|
TH_SetEnabledPlateFormat(PARAM_CHANGNEI_ON, &config);
|
}
|
if (params->bMinHang == 1) {
|
TH_SetEnabledPlateFormat(PARAM_MINHANG_ON, &config);
|
}
|
if (params->bConsulate == 1) {
|
TH_SetEnabledPlateFormat(PARAM_CONSULATE_ON, &config);
|
}
|
if (params->bNewEnergy == 1) {
|
TH_SetEnabledPlateFormat(PARAM_NEWENERGY_ON, &config);
|
}
|
}
|
|
cPlateIDResult* plate_id_detect(int *plateIDCount, const cIMAGE *img) {
|
if (!img) {
|
return NULL;
|
}
|
|
cPlateIDResult *ppos = NULL;
|
int nResultNum = 1;
|
|
::TH_PlateIDResult result[6];
|
memset(&result[0], 0, sizeof(result));
|
|
// 设置识别区域
|
::TH_RECT rcDetect;
|
rcDetect.top = 0;
|
rcDetect.right = img->width;
|
rcDetect.bottom = img->height;
|
rcDetect.left = 0;
|
|
int ret = TH_RecogImage((BYTE*)(img->data), img->width, img->height, result, &nResultNum, &rcDetect, &config);
|
// printf("TH_RecogImage ret = %d\n", ret);
|
if (ret == 0){
|
ret = TH_EvaluateCarColor((BYTE*)(img->data), img->width, img->height, result, &nResultNum, &rcDetect, &config);
|
}
|
if (ret == 0 && nResultNum > 0){
|
ppos = (cPlateIDResult*)malloc(nResultNum * sizeof(cPlateIDResult));
|
*plateIDCount = nResultNum;
|
memcpy(ppos, result, sizeof(TH_PlateIDResult) * nResultNum);
|
}
|
return ppos;
|
}
|
|
int uninit_plate_id_detector() {
|
free(fmem);
|
free(pmem);
|
fmem = NULL;
|
pmem = NULL;
|
|
return TH_UninitPlateIDSDK(&config);
|
}
|
|
} // csdk_wrap
|