Video Analysis底层库拆分,sdk的go封装
zhangzengfei
2019-11-20 308defe0578c2184d35a59fde31b9cb007f2f889
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
#include "detector.h"
#include "ItsVehicleTypeRec.h"
 
#include <stdio.h>
#include <stdlib.h>
 
#include "csdk_struct.h"
 
namespace csdk_wrap
{
    static void* pITSInstance;
 
    int init_vehicle_its_detector(int sceneMode, int modelMode, char *keyPath, char *modelPath) {
        // 初始化授权
        int iInitFlag = ITS_ThreadInit(keyPath);
        if(iInitFlag != OK)
        {
            return iInitFlag;
        }
 
        // 初始化配置
        ::ITS_Rec_Param itsParam;
        itsParam.iSceneMode = sceneMode;
        itsParam.iModelMode = modelMode;
 
        // 初始化SDK
        pITSInstance = ITS_VehicleRecInit(modelPath, iInitFlag, itsParam);
 
        return pITSInstance == NULL ? 1 : 0;
    }
 
    cVehicleITSResult* vehicle_its_detect(int *plateIDCount, const cIMAGE *img, const cRECT *rect) {
        if (!img) {
            return NULL;
        }
 
        cVehicleITSResult *ppos = NULL;
 
        ::V_Image* pImage = new(V_Image);
        pImage->pImageData = (BYTE*)(img->data);
        pImage->iImageHeight = img->height;
        pImage->iImageWidth = img->width;
        pImage->eType = E_BGR;
 
        ::ITS_Vehicle_Result result;
        memset(&result, 0, sizeof(ITS_Vehicle_Result));
 
        // 设置识别区域
        ::S_Rect rcDetect = {rect->left, rect->top, rect->right, rect->bottom};
 
        int iVehicleNum = ITS_VehicleTypeRec(pITSInstance, pImage, &rcDetect, &result);
 
        if (iVehicleNum > 0){
            ppos = (cVehicleITSResult*)malloc(iVehicleNum * sizeof(cVehicleITSResult));
            *plateIDCount = iVehicleNum;
            memcpy(ppos, result.tempResult, sizeof(ITS_Vehicle_Result_Single) * iVehicleNum);
        }
 
        return ppos;
    }
 
    void uninit_vehicle_its_detector() {
        ITS_VehicleRecRelease(pITSInstance);
    }
 
} // csdk_wrap