From 93001d715c38b296bedf2b2e5f4d1efb3151f666 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@iotlink.com>
Date: 星期四, 14 十一月 2019 16:31:24 +0800
Subject: [PATCH] fix:set the plate sdk parameters by api
---
csdk.h | 2
csrc/buz/plate/detector.h | 3
csdk.cpp | 6
go2c.go | 33 ++++++++
gosdk.go | 4
csrc/buz/plate/detector.cpp | 127 ++++++++++++++++++++++---------
csdk_struct.h | 34 ++++++++
7 files changed, 166 insertions(+), 43 deletions(-)
diff --git a/csdk.cpp b/csdk.cpp
index 5f128eb..052fd84 100644
--- a/csdk.cpp
+++ b/csdk.cpp
@@ -103,11 +103,11 @@
}
// plateid api
-int c_api_plate_id_init(const int width, const int height, char *soPath) {
- return init_plate_id_detector(width, height, soPath);
+int c_api_plate_id_init(const cPlateIDCfg *config, char *soPath) {
+ return init_plate_id_detector(config, soPath);
}
-cPlateIDResult* c_api_plate_id_detect(int *plateIDCount, uchar*data, const int w, const int h) {
+cPlateIDResult* c_api_plate_id_detect(int *plateIDCount, uchar *data, const int w, const int h) {
const cIMAGE img{data, w, h, 3};
return plate_id_detect(plateIDCount, &img);
}
diff --git a/csdk.h b/csdk.h
index a17e811..e4f9961 100644
--- a/csdk.h
+++ b/csdk.h
@@ -41,7 +41,7 @@
const char* c_api_yolo_obj_name(const int typ);
// plateid api
-int c_api_plate_id_init(const int width, const int height, char *soPath);
+int c_api_plate_id_init(const cPlateIDCfg *config, char *soPath);
cPlateIDResult* c_api_plate_id_detect(int *plateIDCount, uchar*data, const int w, const int h);
int c_api_plate_id_free();
diff --git a/csdk_struct.h b/csdk_struct.h
index 5d8d74f..db913fa 100644
--- a/csdk_struct.h
+++ b/csdk_struct.h
@@ -69,6 +69,40 @@
float prob;
} cObjInfo;
+typedef struct _cPlateIDCfg {
+ int nMinPlateWidth; // 妫�娴嬬殑鏈�灏忚溅鐗屽搴︼紝浠ュ儚绱犱负鍗曚綅
+ int nMaxPlateWidth; // 妫�娴嬬殑鏈�澶ц溅鐗屽搴︼紝浠ュ儚绱犱负鍗曚綅
+ int nMaxImageWidth; // 鏈�澶у浘鍍忓搴�
+ int nMaxImageHeight; // 鏈�澶у浘鍍忛珮搴�
+
+ unsigned char bIsFieldImage; // 鏄惁鏄満鍥惧儚
+ unsigned char bMovingImage; // 璇嗗埆杩愬姩or闈欐鍥惧儚
+ unsigned char nOrderOpt; // 杈撳嚭椤哄簭閫夐」 0-缃俊搴� 1-鑷笂鑰屼笅 2-鑷笅鑰屼笂
+ unsigned char bLeanCorrection; // 鏄惁鍚敤杞︾墝鏃嬭浆鍔熻兘锛岄粯璁ゅ紑鍚�
+ unsigned char nImproveSpeed; // 0: 璇嗗埆鐜囦紭鍏� 1:璇嗗埆閫熷害浼樺厛
+ unsigned char bCarLogo; // 0: 涓嶆娴嬭溅鏍� 1: 妫�娴嬭溅鏍�
+ unsigned char bLotDetect; // 0: 涓嶆娴嬭溅浣� 1: 妫�娴嬭溅浣�
+ unsigned char bShadow; // 0: 閽堝鏃犻槾褰辩殑杞︾墝 1锛氶拡瀵规湁闃村奖鐨勮溅鐗岋紝榛樿寮�鍚�
+ unsigned char bShieldRailing; // 0: 灞忚斀鏍忔潌骞叉壈锛� 1:涓嶅睆钄芥爮鏉嗗共鎵�
+ unsigned char bCarModel; // 0: 涓嶈瘑鍒溅鍨嬶紝 1: 璇嗗埆杞﹀瀷
+ unsigned char bLocateTh; // 杞︾墝瀹氫綅闃堝��
+ unsigned char bOCRTh; // 杞︾墝璇嗗埆闃堝��
+
+ unsigned char bIndividual; // 涓�у寲杞︾墝寮�鍚�
+ unsigned char bTwoRowYellow; // 鍙屽眰榛勮壊杞︾墝寮�鍚�
+ unsigned char bArmPolice; // 鍗曞眰姝﹁杞︾墝寮�鍚�
+ unsigned char bArmPolice2; // 鍙屽眰姝﹁杞︾墝寮�鍚�
+ unsigned char bTwoRowArmy; // 鍙屽眰鍐涢槦杞︾墝寮�鍚�
+ unsigned char bTractor; // 鍐滅敤杞﹁溅鐗屽紑鍚�
+ unsigned char bEmbassy; // 浣块杞︾墝寮�鍚�
+ unsigned char bChangNei; // 鍘傚唴杞︾墝寮�鍚�
+ unsigned char bMinHang; // 姘戣埅杞︾墝寮�鍚�
+ unsigned char bConsulate; // 棰嗕簨棣嗚溅鐗屽紑鍚�
+ unsigned char bNewEnergy; // 鏂拌兘婧愯溅鐗屽紑鍚�
+ unsigned char bOnlyTwoRowYellow;// 鍙瘑鍒弻灞傞粍鐗屽紑鍚�
+ unsigned char bOnlyLocation; // 鍙畾浣嶈溅鐗屽紑鍚�
+}cPlateIDCfg;
+
typedef struct _cPlateIDResult
{
char license[16]; // 杞︾墝瀛楃涓�
diff --git a/csrc/buz/plate/detector.cpp b/csrc/buz/plate/detector.cpp
index 81b2874..17e2747 100644
--- a/csrc/buz/plate/detector.cpp
+++ b/csrc/buz/plate/detector.cpp
@@ -12,38 +12,12 @@
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;
+ void init_plate_id_config(const cPlateIDCfg *params);
+ void set_enable_plate_format(const cPlateIDCfg *params);
- 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;
+ int init_plate_id_detector(const cPlateIDCfg *params, char *soPath) {
+ // 鍒濆鍖栭厤缃弬鏁�
+ init_plate_id_config(params);
// 璁剧疆Licence Manager杩愯璺緞
int ret = TH_SetSoPath(soPath);
@@ -51,17 +25,98 @@
// 鍒濆鍖� sdk
ret = TH_InitPlateIDSDK(&config);
- // 寮�鍚柊鑳芥簮杞︾墝璇嗗埆
- ret = TH_SetEnabledPlateFormat(PARAM_NEWENERGY_ON, &config);
-
- ret = TH_SetImageFormat(ImageFormatBGR, false, false, &config);
+ // 璁剧疆杞︾墝绫诲瀷璇嗗埆
+ set_enable_plate_format(params);
// 璁剧疆璇嗗埆闃堝��
- TH_SetRecogThreshold(5, 2, &config);
+ TH_SetRecogThreshold(params->bLocateTh, params->bOCRTh, &config);
return ret;
}
+ void init_plate_id_config(const cPlateIDCfg *params) {
+ 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.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);
+ }
+ if (params->bOnlyTwoRowYellow == 1) {
+ TH_SetEnabledPlateFormat(PARAM_ONLY_TWOROWYELLOW_ON, &config);
+ }
+ 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;
diff --git a/csrc/buz/plate/detector.h b/csrc/buz/plate/detector.h
index c2fe9ac..2889503 100644
--- a/csrc/buz/plate/detector.h
+++ b/csrc/buz/plate/detector.h
@@ -3,11 +3,12 @@
#include "../base.hpp"
+struct _cPlateIDCfg;
struct _cPlateIDResult;
struct _cIMAGE;
namespace csdk_wrap{
- int init_plate_id_detector(const int width, const int height, char *soPath);
+ int init_plate_id_detector(const cPlateIDCfg *params, char *soPath);
cPlateIDResult* plate_id_detect(int *plateIDCount, const cIMAGE *img);
int uninit_plate_id_detector();
}
diff --git a/go2c.go b/go2c.go
index 0e663a3..6431f48 100644
--- a/go2c.go
+++ b/go2c.go
@@ -66,6 +66,39 @@
ID uint64
}
+type CPlateIDCfg struct {
+ MinPlateWidth int32 // 妫�娴嬬殑鏈�灏忚溅鐗屽搴︼紝浠ュ儚绱犱负鍗曚綅
+ MaxPlateWidth int32 // 妫�娴嬬殑鏈�澶ц溅鐗屽搴︼紝浠ュ儚绱犱负鍗曚綅
+ MaxImageWidth int32 // 鏈�澶у浘鍍忓搴�
+ MaxImageHeight int32 // 鏈�澶у浘鍍忛珮搴�
+ IsFieldImage uint8 // 鏄惁鏄満鍥惧儚
+ MovingImage uint8 // 璇嗗埆杩愬姩or闈欐鍥惧儚
+ OrderOpt uint8 // 杈撳嚭椤哄簭閫夐」 0-缃俊搴� 1-鑷笂鑰屼笅 2-鑷笅鑰屼笂
+ LeanCorrection uint8 // 鏄惁鍚敤杞︾墝鏃嬭浆鍔熻兘锛岄粯璁ゅ紑鍚�
+ ImproveSpeed uint8 // 0: 璇嗗埆鐜囦紭鍏� 1:璇嗗埆閫熷害浼樺厛
+ CarLogo uint8 // 0: 涓嶆娴嬭溅鏍� 1: 妫�娴嬭溅鏍�
+ LotDetect uint8 // 0: 涓嶆娴嬭溅浣� 1: 妫�娴嬭溅浣�
+ Shadow uint8 // 0: 閽堝鏃犻槾褰辩殑杞︾墝 1锛氶拡瀵规湁闃村奖鐨勮溅鐗岋紝榛樿寮�鍚�
+ ShieldRailing uint8 // 0: 灞忚斀鏍忔潌骞叉壈锛� 1:涓嶅睆钄芥爮鏉嗗共鎵�
+ CarModel uint8 // 0: 涓嶈瘑鍒溅鍨嬶紝 1: 璇嗗埆杞﹀瀷
+ LocateTh uint8 // 杞︾墝瀹氫綅闃堝��
+ OCRTh uint8 // 杞︾墝璇嗗埆闃堝��
+
+ Individual uint8 // 涓�у寲杞︾墝寮�鍚�
+ TwoRowYellow uint8 // 鍙屽眰榛勮壊杞︾墝寮�鍚�
+ ArmPolice uint8 // 鍗曞眰姝﹁杞︾墝寮�鍚�
+ ArmPolice2 uint8 // 鍙屽眰姝﹁杞︾墝寮�鍚�
+ TwoRowArmy uint8 // 鍙屽眰鍐涢槦杞︾墝寮�鍚�
+ Tractor uint8 // 鍐滅敤杞﹁溅鐗屽紑鍚�
+ Embassy uint8 // 浣块杞︾墝寮�鍚�
+ ChangNei uint8 // 鍘傚唴杞︾墝寮�鍚�
+ MinHang uint8 // 姘戣埅杞︾墝寮�鍚�
+ Consulate uint8 // 棰嗕簨棣嗚溅鐗屽紑鍚�
+ NewEnergy uint8 // 鏂拌兘婧愯溅鐗屽紑鍚�
+ OnlyTwoRowYellow uint8 // 鍙瘑鍒弻灞傞粍鐗屽紑鍚�
+ OnlyLocation uint8 // 鍙畾浣嶈溅鐗屽紑鍚�
+}
+
type CPlateIDResult struct {
License [16]uint8
Color [8]uint8
diff --git a/gosdk.go b/gosdk.go
index 8c0a914..c22a8ae 100644
--- a/gosdk.go
+++ b/gosdk.go
@@ -412,8 +412,8 @@
}
// InitPlateIDDetector init plateid detector
-func InitPlateIDDetector(width, height int, soPath []byte) {
- C.c_api_plate_id_init(C.int(width), C.int(height), (*C.char)(unsafe.Pointer(&soPath[0])))
+func InitPlateIDDetector(config *CPlateIDCfg, soPath []byte) {
+ C.c_api_plate_id_init((*C.cPlateIDCfg)(unsafe.Pointer(config)), (*C.char)(unsafe.Pointer(&soPath[0])))
}
// PlateIDDetect plateid detect
--
Gitblit v1.8.0