Skip to content

Commit

Permalink
update docs for new data structures and utilities of c api
Browse files Browse the repository at this point in the history
  • Loading branch information
ManosMpampis committed Dec 12, 2022
1 parent e649c60 commit 467c1f1
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 13 deletions.
101 changes: 101 additions & 0 deletions docs/reference/c-data-h.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,104 @@ A pointer where image data are stored.
*opendr_image_t* is using internally OpenCV images (*cv::Mat*) for storing images.
Therefore, only a pointer to the memory location of the corresponding *cv::Mat* is stored.
Please note that the user is not expected to directly manipulate these data without first converting them into OpenCV data type or using the corresponding functions provided in *opendr_utils.h*.

### struct *opendr_tensor_t*
```C
struct opendr_tensor {
int batch_size;
int frames;
int channels;
int width;
int height;

float *data;
};
typedef struct opendr_tensor opendr_tensor_t;
```


The *opendr_tensor_t* structure provides a data structure for storing OpenDR structures.
Every function in the C API receiving and return tensors is expected to use this structure.
Helper functions that directly maps data into this format are provided in *opendr_utils.h*.

The *opendr_tensor_t* structure has the following field:

#### `int batch_size` field

An integer that represent the number of batch size in the tensor.

#### `int frames` field

An integer that represent the number of frames in the tensor.

#### `int channels` field

An integer that represent the number of channels in the tensor.

#### `int width` field

An integer that represent the width of the tensor.

#### `int height` field

An integer that represent the height of the tensor.

#### `float *data` field

A pointer where data are stored.
*opendr_tensor_t* is using internally a pointer and corresponding sizes to copy the data into the memory of float *data.
Therefore, only a pointer to the memory location of the corresponding data is stored.
Please note that the user is not expected to directly manipulate these data without first converting them into OpenCV or other form of data type or using the corresponding functions provided in *opendr_utils.h*.

### struct *opendr_tensor_vector_t*
```C
struct opendr_tensor_vector {
int n_tensors;
int *batch_sizes;
int *frames;
int *channels;
int *widths;
int *heights;

float **memories;
};
typedef struct opendr_tensor_vector opendr_tensor_vector_t;
```


The *opendr_tensor_vector_t* structure provides a data structure for storing OpenDR tensor structures.
Every function in the C API receiving and returning multiple tensors is expected to use this structure.
Helper functions that directly maps data into this format are provided in *opendr_utils.h*.

The *opendr_tensor_vector_t* structure has the following field:

#### `int n_tensors` field

An integer that represent the number of tensor in the tensor vector.

#### `int *batch_sizes` field

A pointer of integers that represent the number of batch size in each tensor.

#### `int *frames` field

A pointer of integers that represent the number of frames in each tensor.

#### `int *channels` field

A pointer of integers that represent the number of channels in each tensor.

#### `int *widths` field

A pointer of integers that represent the width of each tensor.

#### `int *heights` field

A pointer of integers that represent the height of each tensor.

#### `float **memories` field

A pointer where stores the data of each *opendr_tensor_t.data* stored in the vector.
*opendr_tensor_vector_t* is using internally pointers and corresponding sizes to copy the data into the memory of *memories* for each tensor that is provided.
Therefore, only a pointer to the memory location of the corresponding data is stored.
Please note that the user is not expected to directly manipulate these data without first converting them into OpenCV or other form of data type or using the corresponding functions provided in *opendr_utils.h*.
20 changes: 10 additions & 10 deletions docs/reference/c-face-recognition-h.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ struct face_recognition_model {
};
typedef struct face_recognition_model face_recognition_model_t;
```
The *face_recognition_model_t* structure keeps all the neccesary information that are required by the OpenDR face recognition tool (e.g., model weights, normalization information, database for person recognition, ONNX session information, etc.).
The *face_recognition_model_t* structure keeps all the necessary information that are required by the OpenDR face recognition tool (e.g., model weights, normalization information, database for person recognition, ONNX session information, etc.).


### Function *load_face_recognition_model()*
```C
void load_face_recognition_model(const char *model_path, face_recognition_model_t *model);
void load_face_recognition_model(const char *modelPath, face_recognition_model_t *model);
```
Loads a face recognition model saved in the local filesystem (*model path*) in OpenDR format.
Loads a face recognition model saved in the local filesystem (*modelPath*) in OpenDR format.
This function also initializes a CPU-based ONNX session for performing inference using this model.
The pre-trained models should follow the OpenDR conventions.
The Python API can be used to train and export an optimized OpenDR model that can be used for inference using the C API.
Expand All @@ -40,25 +40,25 @@ The function returns an OpenDR category structure with the inference results.
### Function *decode_category_face_recognition()*
```C
void decode_category_face_recognition(face_recognition_model_t *model, opendr_category_target_t category, char *person_name);
void decode_category_face_recognition(face_recognition_model_t *model, opendr_category_target_t category, char *personName);
```
Returns the name of a recognized person by decoding the category id into a string (this function uses the information from the built person database).


### Function *build_database_face_recognition()*
```C
void build_database_face_recognition(const char *database_folder, const char *output_path, face_recognition_model_t *model);
void build_database_face_recognition(const char *databaseFolder, const char *outputPath, face_recognition_model_t *model);
```
Build a face recognition database (containing images for persons to be recognized).
This function expects the *database_folder* to have the same format as the main Python toolkit.
The function calculates the features of the person that are contained in the database and it stores it into a binary file that can be then loaded to perform inference (*output_path*).
A loaded face recongition model should be provided (*model*), since this model will be used for the feature extraction process.
This function expects the *databaseFolder* to have the same format as the main Python toolkit.
The function calculates the features of the person that are contained in the database and it stores it into a binary file that can be then loaded to perform inference (*outputPath*).
A loaded face recognition model should be provided (*model*), since this model will be used for the feature extraction process.
### Function *load_database_face_recognition()*
```C
void load_database_face_recognition(const char *database_path, face_recognition_model_t *model);
void load_database_face_recognition(const char *databasePath, face_recognition_model_t *model);
```
Loads an already built database (*database_path) into a face recognition model (*model*).
Loads an already built database (*databasePath*) into a face recognition model (*model*).
After this step, the model can be used for performing inference.

76 changes: 74 additions & 2 deletions docs/reference/c-opendr-utils-h.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,84 @@ The *load_image()* function allows for reading an images from the local file sys
A pointer (*image*) to an OpenDR *opendr_image_t* should be provided.
This function allocates memory during each function call, so be sure to use the *free_image()* function to release the allocated resources, when the corresponding image is no longer needed.
### Function *free_image()*
```C
void free_image(opendr_image_t *image);
```
The *free_image()* function releases the memory allocated for an OpenDR image structure (*image*).
A pointer (*image*) to an OpenDR *opendr_image_t* should be provided.

### Function *initialize_detections_vector()*
```C
void initialize_detections_vector(opendr_detection_vector_target_t *detection_vector);
```
The *initialize_detections_vector()* function initialize the data of an OpenDR detection vector structure (*detection_vector*) with zero values.
A pointer (*detection_vector*) to an OpenDR *detection_vector_target_t* should be provided.
### Function *load_detections_vector()*
```C
void load_detections_vector(opendr_detection_vector_target_t *detection_vector, opendr_detection_target_t *detection,
int vector_size);
```
The *load_detections_vector()* function allows for storing OpenDR detection target structures in to the memory allocated for multiple OpenDR detections structures (*detection*).
A pointer (*detection_vector*) to an OpenDR *opendr_detection_vector_target_t* should be provided.

### Function *free_detections_vector()*
```C
void free_detections_vector(opendr_detection_vector_target_t *detection_vector);
```
The *free_detections_vector()* function releases the memory allocated for an OpenDR detection vector structure (*detection_vector*).
A pointer (*detection_vector*) to an OpenDR *opendr_detection_vector_target_t* should be provided.
### Function *initialize_tensor()*
```C
void initialize_tensor(opendr_tensor_t *opendr_tensor);
```
The *initialize_tensor()* function initialize the data of an OpenDR tensor (*opendr_tensor*) with zero values.
A pointer (*opendr_tensor*) to an OpenDR *opendr_tensor_t* should be provided.

### Function *load_tensor()*
```C
void load_tensor(opendr_tensor_t *opendr_tensor, void *tensor_data, int batch_size, int frames, int channels, int width,
int height);
```
The *load_tensor()* function allows for storing OpenDR tensor structures in to the memory allocated into a pointer into the OpenDR tensor structure (*opendr_tensor*).
A pointer (*opendr_tensor*) to an OpenDR *opendr_tensor_t* along with the pointer into the memory (*tensor_data*) and the (*batch_size*), (*frames*), (*channels*), (*width*) and (*height*) of tensor should be provided.
All integers must have a minimum value of *1*.
### Function *free_tensor()*
```C
void free_tensor(opendr_tensor_t *opendr_tensor);
```
The *free_tensor()* function releases the memory allocated for an OpenDR tensor structure (*opendr_tensor*).
A pointer (*opendr_tensor*) to an OpenDR *opendr_tensor_t* should be provided.

### Function *initialize_tensor_vector()*
```C
void initialize_tensor_vector(opendr_tensor_vector_t *tensor_vector);
```
The *initialize_tensor_vector()* function initialize the data of an OpenDR tensor vector (*tensor_vector*) with zero values.
A pointer (*tensor_vector*) to an OpenDR *opendr_tensor_vector_t* should be provided.
### Function *load_tensor_vector()*
```C
void load_tensor_vector(opendr_tensor_vector_t *tensor_vector, opendr_tensor_t *tensor, int number_of_tensors);
```
The *load_tensor_vector()* function allows for storing multiple OpenDR tensor structures in to the memory allocated into pointers into the OpenDR tensor vector structure (*tensor_vector*).
A pointer (*tensor_vector*) to an OpenDR *opendr_tensor_vector_t* along with the pointer into the memory of a vector or array of OpenDR tensors structure (*tensor*) should be provided.
Moreover the number of tensors (*number_of_tensors*) should be included, and it must be better than *1*.

### Function *free_tensor_vector()*
```C
void free_tensor_vector(opendr_tensor_vector_t *tensor_vector);
```
The *free_tensor_vector()* function releases the memory allocated for an OpenDR tensor vector structure (*opendr_tensor_vector_t*).
A pointer (*tensor_vector*) to an OpenDR *opendr_tensor_vector_t* should be provided.
### Function *iter_tensor_vector()*
```C
void iter_tensor_vector(opendr_tensor_t *output, opendr_tensor_vector_t *tensor_vector, int index);
```
The *iter_tensor_vector()* function is used to help the user to iterate the OpenDR tensor vector.
A single OpenDR tensor (*output*) is loaded with the values of the indexed (*index*) tensor of the vector (*tensor_vector*).
A pointer (*tensor_vector*) to an OpenDR *opendr_tensor_vector_t* and an (*index*) along with a pointer (*output*) to an OpenDR *opendr_tensor_t* should be provided.
71 changes: 70 additions & 1 deletion docs/reference/c-target-h.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ typedef struct opendr_category_target opendr_category_target_t;
```


The *opendr_category_target_t* structure provides a data structure for storing inference outputs of classification models.
The *opendr_category_target_t* structure provides a data structure for storing inference outputs of classification models.
Every function in the C API that outputs a classification decision is expected to use this structure.

The *opendr_category_target_t* structure has the following field:
Expand All @@ -25,3 +25,72 @@ A numerical id of the category to which the input objects belongs to.
#### `float confidence` field

The decision confidence (a value between 0 and 1).


### struct *opendr_detection_target_t*
```C
struct opendr_detection_target {
int name;
float left;
float top;
float width;
float height;
float score;
};
typedef struct opendr_detection_target opendr_detection_target_t;
```


The *opendr_detection_target_t* structure provides a data structure for storing inference outputs of detection models.
Every function in the C API that outputs a detection decision is expected to use this structure or a vector of this structure.

The *opendr_detection_target_t* structure has the following field:

#### `int name` field

A numerical id of the category to which the input objects belongs to.

#### `float left` field

A numerical value that corresponds to the X value of the top,left point of a detection.

#### `float top` field

A numerical value that corresponds to the Y value of the top,left point of a detection.

#### `float width` field

A numerical value that corresponds to the width of a detection.

#### `float height` field

A numerical value that corresponds to the height of a detection.

#### `float score` field

The decision score (a value between 0 and 1).



### struct *opendr_detection_vector_target_t*
```C
struct opendr_detection_vector_target {
opendr_detection_target_t *starting_pointer;
int size;
};
typedef struct opendr_detection_vector_target opendr_detection_vector_target_t;
```


The *opendr_detection_vector_target_t* structure provides a data structure for storing multiple inference outputs of detection models.
Every function in the C API that outputs a detection decision is expected to use this or a *detection_target_t* structure.

The *opendr_detection_vector_target_t* structure has the following field:

#### `opendr_detection_target_t starting_pointer` field

A pointer to a memory of multiple OpenDR detection targets.

#### `int size` field

A numerical value that represents the number of OpenDR detection structures that are stored.

0 comments on commit 467c1f1

Please sign in to comment.