#include "detector.h" #include #include #include "TH_PlateID.h" #include "csdk_struct.h" namespace csdk_wrap { static TH_PlateIDCfg config; static unsigned char *fmem; static unsigned char *pmem; int init_plate_id_detector(const int width, const int height, char *soPath) { int fMemSize = 0x8000; int pMemSize = 200 * 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.nMaxImageWidth = width; config.nMaxImageHeight = height; config.bVertCompress = 0; config.bIsFieldImage = 0; config.bOutputSingleFrame = 1; config.pFastMemory = fmem; config.nFastMemorySize = fMemSize; config.pMemory = pmem; config.nMemorySize= pMemSize; config.bUTF8 = 1; // 动态模式 config.bMovingImage = 1; config.nImageFormat = ImageFormatBGR; // 静态模式 // config.bMovingImage = 0; // 识别车型 config.bCarModel = 1; // 设置Licence Manager运行路径 int ret = TH_SetSoPath(soPath); // 初始化 sdk ret = TH_InitPlateIDSDK(&config); // 开启新能源车牌识别 ret = TH_SetEnabledPlateFormat(PARAM_NEWENERGY_ON, &config); ret = TH_SetImageFormat(ImageFormatBGR, false, false, &config); // 设置识别阈值 TH_SetRecogThreshold(5, 2, &config); return ret; } 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, 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 && 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