-
Notifications
You must be signed in to change notification settings - Fork 2
/
nvdsinfer_context_impl_capi.cpp
123 lines (98 loc) · 3.33 KB
/
nvdsinfer_context_impl_capi.cpp
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved.
*
* NVIDIA Corporation and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA Corporation is strictly prohibited.
*
*/
#include "nvdsinfer_context_impl.h"
#include <cstdio>
/* This file implements the C interface for the NvDsInferContext class. The
* interface is a simple wrapper over the C++ interface. */
using namespace std;
#define NULL_PARAM_CHECK(param, retvalue) \
if (param == nullptr) \
{ \
fprintf(stderr, "Warning: NULL parameter " #param " passed to %s\n", \
__func__); \
return retvalue; \
}
NvDsInferStatus
NvDsInferContext_Create(NvDsInferContextHandle *handle,
NvDsInferContextInitParams *initParams, void *userCtx,
NvDsInferContextLoggingFunc logFunc)
{
NULL_PARAM_CHECK(handle, NVDSINFER_INVALID_PARAMS);
NULL_PARAM_CHECK(initParams, NVDSINFER_INVALID_PARAMS);
return createNvDsInferContext(handle, *initParams, userCtx, logFunc);
}
void
NvDsInferContext_Destroy(NvDsInferContextHandle handle)
{
NULL_PARAM_CHECK(handle, );
handle->destroy();
}
NvDsInferStatus
NvDsInferContext_QueueInputBatch(NvDsInferContextHandle handle,
NvDsInferContextBatchInput *batchInput)
{
NULL_PARAM_CHECK(handle, NVDSINFER_INVALID_PARAMS);
NULL_PARAM_CHECK(batchInput, NVDSINFER_INVALID_PARAMS);
return handle->queueInputBatch(*batchInput);
}
NvDsInferStatus
NvDsInferContext_DequeueOutputBatch(NvDsInferContextHandle handle,
NvDsInferContextBatchOutput *batchOutput)
{
NULL_PARAM_CHECK(handle, NVDSINFER_INVALID_PARAMS);
NULL_PARAM_CHECK(batchOutput, NVDSINFER_INVALID_PARAMS);
return handle->dequeueOutputBatch(*batchOutput);
}
void
NvDsInferContext_ReleaseBatchOutput(NvDsInferContextHandle handle,
NvDsInferContextBatchOutput *batchOutput)
{
NULL_PARAM_CHECK(handle, );
NULL_PARAM_CHECK(batchOutput, );
return handle->releaseBatchOutput(*batchOutput);
}
unsigned int
NvDsInferContext_GetNumLayersInfo(NvDsInferContextHandle handle)
{
NULL_PARAM_CHECK(handle, 0);
std::vector<NvDsInferLayerInfo> layersInfo;
handle->fillLayersInfo(layersInfo);
return layersInfo.size();
}
void
NvDsInferContext_FillLayersInfo(NvDsInferContextHandle handle,
NvDsInferLayerInfo *layersInfo)
{
NULL_PARAM_CHECK(handle, );
NULL_PARAM_CHECK(layersInfo, );
std::vector<NvDsInferLayerInfo> layersInfoVec;
handle->fillLayersInfo(layersInfoVec);
for (unsigned int i = 0; i < layersInfoVec.size(); i++)
layersInfo[i] = layersInfoVec[i];
}
void
NvDsInferContext_GetNetworkInfo(NvDsInferContextHandle handle,
NvDsInferNetworkInfo *networkInfo)
{
NULL_PARAM_CHECK(handle, );
NULL_PARAM_CHECK(networkInfo, );
return handle->getNetworkInfo(*networkInfo);
}
const char*
NvDsInferContext_GetLabel(NvDsInferContextHandle handle, unsigned int id,
unsigned int value)
{
NULL_PARAM_CHECK(handle, nullptr);
auto labels = handle->getLabels();
if (labels.size() > id && labels[id].size() > value)
return labels[id][value].c_str();
return nullptr;
}