Video Analysis底层库拆分,sdk的go封装
zhangzengfei
2019-11-14 93001d715c38b296bedf2b2e5f4d1efb3151f666
fix:set the plate sdk parameters by api
7个文件已修改
209 ■■■■ 已修改文件
csdk.cpp 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csdk.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
csdk_struct.h 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/buz/plate/detector.cpp 127 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/buz/plate/detector.h 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
go2c.go 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gosdk.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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);
}
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();
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];    // 车牌字符串
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;
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();
}
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
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