openncc frame
native_vpu_api.h File Reference

Configure inference engine and pipelines of NCC camera. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for native_vpu_api.h:

Go to the source code of this file.

Classes

struct  NccUsbPortSpec_t
 USB port information to query device serial number. More...
 
struct  NccPipeInput_t
 Frame data send to ncc device for AI inference. More...
 
struct  NccPipeOutput_t
 AI Meta frame with header and data, get back from ncc device after finished one frame AI inference. More...
 
struct  NccPipeHandle_t
 Inference engine handle. After the user initializes the model file information,
the SDK will automatically allocate inference engine resources according to the device conditions
to complete registration and initialization. More...
 
struct  NccTensorSpec_t
 Tensor structure. More...
 

Macros

#define MAX_DEV_NUM   (2)
 The maximum of the ncc devices which the sdk supported by one host APP. More...
 
#define MAX_PIPELINE_NUM   (6)
 The maximum of the AI inference pipelines which one device supported. More...
 

Enumerations

enum  LOG_LEVEL { LOG_INFO, LOG_DEBUG, LOG_ERROR, LOG_SHOW }
 
enum  usb_error {
  USB_SUCCESS = 0, USB_ERROR_IO = -1, USB_ERROR_INVALID_PARAM = -2, USB_ERROR_ACCESS = -3,
  USB_ERROR_NO_DEVICE = -4, USB_ERROR_NOT_FOUND = -5, USB_ERROR_BUSY = -6, USB_ERROR_TIMEOUT = -7,
  USB_ERROR_OVERFLOW = -8, USB_ERROR_PIPE = -9, USB_ERROR_INTERRUPTED = -10, USB_ERROR_NO_MEM = -11,
  USB_ERROR_NOT_SUPPORTED = -12, USB_ERROR_OTHER = -99
}
 The list of the usb error code. More...
 
enum  FRAMETYPE {
  YUV420p = 2, YUV422p, H26X = 22, JPEG,
  METEDATA, BLOB = 27, BLOB_CFG, NONE
}
 The list of the image format which ncc camera supported. More...
 
enum  METATYPE { META_FORMAT_U8 =100, META_FORMAT_FP16, META_FORMAT_FP32 }
 The list of the AI meta format which ncc camera supported. More...
 
enum  PROCESS_MODE { NCC_SYNC, NCC_ASYNC }
 The list of the AI inference mode which ncc camera supported. More...
 

Functions

int sync_process (NccPipeHandle_t *handle, NccPipeInput_t *input, NccPipeOutput_t *output, unsigned int timeout_ms)
 Synchronous inference function,blocking operation.
return when the device inference is completed. More...
 
int async_process (NccPipeHandle_t *handle, NccPipeInput_t *input)
 Inference function,Asynchronous non blocking operation.
When the device inference is completed, the callback is triggered. More...
 
int ncc_pipe_queue_read (NccPipeHandle_t *handle, NccPipeOutput_t *pbuf, int time_out)
 Gets the output tensor information of the current pipeline. More...
 
NccPipeInput_tncc_malloc (int size)
 ncc sdk malloc memory block More...
 
void ncc_free (NccPipeInput_t *buff)
 ncc sdk free memory block More...
 
int ncc_dev_number_get (void)
 scan all the ncc devices connected with the Host More...
 
int ncc_dev_init (char *fw_path, int dev_num)
 Initialize ncc device,if your device don't have flash on it,need download the firmware. More...
 
int ncc_dev_id_get (NccPipeHandle_t *handle)
 Get index of device handle according to handle. More...
 
int ncc_dev_serial_number_get (NccUsbPortSpec_t *port, char *string, int size)
 Get serial number of device according to usb port. More...
 
int ncc_pipe_create (NccPipeHandle_t *handle, PROCESS_MODE mode)
 Initialize the inference engine, read the parameters from the JSON file and
. More...
 
int ncc_dev_start (int dev_id)
 Start all the pipelines on the device with specified serial number. More...
 
int ncc_pipe_id_get (NccPipeHandle_t *handle)
 Get the pipe index of this NccPipeHandle_t on the device.
Generally speaking this pipe index is automatically assigned by SDK. More...
 
int ncc_input_tensor_descriptor_get (NccPipeHandle_t *handle, NccTensorSpec_t *input_tensor)
 Gets the input tensor information of the current pipeline. More...
 
int ncc_output_tensor_descriptor_get (NccPipeHandle_t *handle, NccTensorSpec_t *output_tensor)
 Gets the output tensor information of the current pipeline. More...
 
void set_log_level (LOG_LEVEL level)
 set level of log print More...
 

Detailed Description

Configure inference engine and pipelines of NCC camera.

Author
Zed zhang.nosp@m.di@e.nosp@m.yeclo.nosp@m.ud.t.nosp@m.ech
Date
2022.09.01

Macro Definition Documentation

◆ MAX_DEV_NUM

#define MAX_DEV_NUM   (2)

The maximum of the ncc devices which the sdk supported by one host APP.

MAX_DEV_NUM

◆ MAX_PIPELINE_NUM

#define MAX_PIPELINE_NUM   (6)

The maximum of the AI inference pipelines which one device supported.

MAX_PIPELINE_NUM

Enumeration Type Documentation

◆ FRAMETYPE

enum FRAMETYPE

The list of the image format which ncc camera supported.

Enumerator
YUV420p 
YUV422p 

< planar YUV4:2:0 format

H26X 

< planar YUV422 8 bit

JPEG 

< H.264

METEDATA 

< MJPEG

BLOB 

< AI Meta data

BLOB_CFG 

< AI model file for openvino

NONE 

< AI modle config file

< reserve

◆ LOG_LEVEL

enum LOG_LEVEL
Enumerator
LOG_INFO 
LOG_DEBUG 
LOG_ERROR 
LOG_SHOW 

◆ METATYPE

enum METATYPE

The list of the AI meta format which ncc camera supported.

Enumerator
META_FORMAT_U8 
META_FORMAT_FP16 

< U8

META_FORMAT_FP32 

< FP16

◆ PROCESS_MODE

The list of the AI inference mode which ncc camera supported.

Enumerator
NCC_SYNC 
NCC_ASYNC 

◆ usb_error

enum usb_error

The list of the usb error code.

Enumerator
USB_SUCCESS 

< Success (no error)

USB_ERROR_IO 

< Input/output error

USB_ERROR_INVALID_PARAM 

< Invalid parameter Access denied (insufficient permissions)

USB_ERROR_ACCESS 

No such device (it may have been disconnected)

USB_ERROR_NO_DEVICE 

Entity not found

USB_ERROR_NOT_FOUND 

Resource busy

USB_ERROR_BUSY 

Operation timed out

USB_ERROR_TIMEOUT 

Overflow

USB_ERROR_OVERFLOW 

Pipe error

USB_ERROR_PIPE 

System call interrupted (perhaps due to signal)

USB_ERROR_INTERRUPTED 

Insufficient memory

USB_ERROR_NO_MEM 

Operation not supported or unimplemented on this platform

USB_ERROR_NOT_SUPPORTED 
USB_ERROR_OTHER 

Other error

Function Documentation

◆ async_process()

int async_process ( NccPipeHandle_t handle,
NccPipeInput_t input 
)

Inference function,Asynchronous non blocking operation.
When the device inference is completed, the callback is triggered.

Parameters
*handlePointer to the inference handle,which has been initialized by SDK.
*inputPointer NccPipeInput_t
Returns
Successful acquisition return or failure
Return values
0Success
example:
....................
NccPipeInput_t *pInData = ncc_malloc(imageWidth*imageHeight*3);
if(pInData==0)
{
printf("ncc_malloc error\n");
return 0;
}
...........
...........
NccPipeOutput_t pOutData;
int maxOutSize = 1024*1024;
pOutData.output = malloc(maxOutSize);
if(pOutData.output==0)
{
printf("'nccMalloc error\n");
return 0;
}
pOutData.alloc_size = maxOutSize;
......................
async_process(&handle, pInData, &pOutData, 10000);
ncc_pipe_queue_read(handle, &pOutData, 0);

◆ ncc_dev_id_get()

int ncc_dev_id_get ( NccPipeHandle_t handle)

Get index of device handle according to handle.

Parameters
[in]*handlepointer to the NccPipeHandle_t
Returns
Return values
>0index of device which handle allocated to
-1None corresponding handle created

◆ ncc_dev_init()

int ncc_dev_init ( char *  fw_path,
int  dev_num 
)

Initialize ncc device,if your device don't have flash on it,need download the firmware.

Parameters
[in]*fw_pathfile path of firmware
[in]dev_numnumber of devices scanned
Returns
return init state
Return values
>0Number of devices successfully initialized
-1The input parameter exceeds the maximum number of devices
-2There are no devices need to initialize
-3USB initialization failed

◆ ncc_dev_number_get()

int ncc_dev_number_get ( void  )

scan all the ncc devices connected with the Host

Returns
Number of devices scanned
Return values
0None ncc devices scanned,others scanned number

◆ ncc_dev_serial_number_get()

int ncc_dev_serial_number_get ( NccUsbPortSpec_t port,
char *  string,
int  size 
)

Get serial number of device according to usb port.

Parameters
[in]*portpointer to NccUsbPortSpec_t
[in]*stringbuffer to storage serial number
[in]*sizesize of string buffer
Returns
Return values
0Get successfully
-1No corresponding serial number found
-2Size of buffer is shorter than length of serial number

◆ ncc_dev_start()

int ncc_dev_start ( int  dev_id)

Start all the pipelines on the device with specified serial number.

Parameters
[in]dev_idserial number of the device
Returns
Successful acquisition return or failure
Return values
0Success
-1Failure

◆ ncc_free()

void ncc_free ( NccPipeInput_t buff)

ncc sdk free memory block

Parameters
[in]*pDatapointer to the NccPipeInput_t memory block
Returns
None

◆ ncc_input_tensor_descriptor_get()

int ncc_input_tensor_descriptor_get ( NccPipeHandle_t handle,
NccTensorSpec_t input_tensor 
)

Gets the input tensor information of the current pipeline.

Parameters
[in]*handlepointer to the NccPipeHandle_t
[in]*input_tensorpointer to the NccTensorSpec_t
Returns
Return values
0Success
-1Failure

◆ ncc_malloc()

NccPipeInput_t* ncc_malloc ( int  size)

ncc sdk malloc memory block

Parameters
[in]sizememory byte size want to malloc
Returns
Pointer to the NccPipeInput_t memory block
Return values
0Failure

◆ ncc_output_tensor_descriptor_get()

int ncc_output_tensor_descriptor_get ( NccPipeHandle_t handle,
NccTensorSpec_t output_tensor 
)

Gets the output tensor information of the current pipeline.

Parameters
[in]*handlepointer to the NccPipeHandle_t
[in]*output_tensorpointer to the NccTensorSpec_t
Returns
Return values
0Success
-1Failure

◆ ncc_pipe_create()

int ncc_pipe_create ( NccPipeHandle_t handle,
PROCESS_MODE  mode 
)

Initialize the inference engine, read the parameters from the JSON file and
.

Parameters
[in]*handlepointer to the NccPipeHandle_t
[in]modeenum PROCESS_MODE
Returns
Successful acquisition return or failure
Sync blocking mode demo:
NccPipeHandle_t handle = { NULL,\
"auto",\
"face-detection-retail-0004",\
"/usr/lib/openncc/model_zoo/ncc/openvino_2021.4/face-detection-retail-0004/face-detection-retail-0004.blob",\
"/usr/lib/openncc/model_zoo/ncc/openvino_2021.4/face-detection-retail-0004/config/input_BGR.json"};
ret=ncc_pipe_create(&handle, NCC_SYNC);
if(ret>0)
{
printf("ncc_pipe_create error %d !\n", ret);
return -1;
}
...
...

◆ ncc_pipe_id_get()

int ncc_pipe_id_get ( NccPipeHandle_t handle)

Get the pipe index of this NccPipeHandle_t on the device.
Generally speaking this pipe index is automatically assigned by SDK.

Parameters
[in]*handlepointer to the NccPipeHandle_t
Returns
Index of pipe

◆ ncc_pipe_queue_read()

int ncc_pipe_queue_read ( NccPipeHandle_t handle,
NccPipeOutput_t pbuf,
int  time_out 
)

Gets the output tensor information of the current pipeline.

Parameters
[in]*handlepointer to the NccPipeHandle_t
[in]*pbufpointer to buffer
[in]time_outoption to control blocking read.
Returns
Successful acquisition return or failure
Return values
0Success
-1Read error

◆ set_log_level()

void set_log_level ( LOG_LEVEL  level)

set level of log print

Parameters
[in]levelenum LOG_LEVEL

◆ sync_process()

int sync_process ( NccPipeHandle_t handle,
NccPipeInput_t input,
NccPipeOutput_t output,
unsigned int  timeout_ms 
)

Synchronous inference function,blocking operation.
return when the device inference is completed.

Parameters
[in]*handlePointer to the inference handle,which has been initialized by SDK.
[in]*inputPointer to the NccPipeInput_t
[out]*outputPointer NccPipeOutput_t
[in]timeout_mstime out millisecond. The sdk would return after timeout
Returns
Successful acquisition return or failure
Return values
0Success
-1Timeout
-2Repeated call
....................
NccPipeInput_t *pInData = ncc_malloc(imageWidth*imageHeight*3);
if(pInData==0)
{
printf("ncc_malloc error\n");
return 0;
}
...........
...........
NccPipeOutput_t pOutData;
int maxOutSize = 1024*1024;
pOutData.output = malloc(maxOutSize);
if(pOutData.output==0)
{
printf("'nccMalloc error\n");
return 0;
}
pOutData.alloc_size = maxOutSize;
......................
ret = sync_process(&handle, pInData, &pOutData, 10000);