Video Analysis底层库拆分,sdk的go封装
zhangzengfei
2019-11-14 6c5479bec34af351eebf956adf993975ab12e2ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#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;
 
    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