C API minimal examples¶
Video processing¶
This example shows how to initialize the video intelligence class and process a video frame.
#include <stdio.h>
#include <stdlib.h>
#include "plumerai/video_intelligence_c.h"
int main(void) {
// Settings, to be changed as needed
const int width = 1600; // camera image width in pixels
const int height = 1200; // camera image height in pixels
// Initialize the video intelligence algorithm
CPlumeraiVideoIntelligence pvi =
plumerai_video_intelligence_create(height, width);
// Pre-allocate space for the input image (*3 for RGB)
unsigned char *image = (unsigned char *)malloc(height * width * 3);
// Loop over frames in a video stream (example: 10 times)
for (int t = 0; t < 10; ++t) {
// Some example input here, normally this is where camera data is acquired
image[0] = 12;
image[1] = 143;
// etc...
// The time between two video frames in seconds
// In this example we assume a constant frame rate of 30 fps, but variable
// rates are supported.
const float delta_t = 1.f / 30.f;
// Process the frame
PlumeraiErrorCode error_code =
plumerai_video_intelligence_process_frame_packed_rgb888(pvi, image,
delta_t);
if (error_code != PLUMERAI_SUCCESS) {
printf("Error: %s\n", plumerai_error_code_string(error_code));
return 1;
}
const BoxPrediction *predictions = NULL;
size_t num_results = 0;
error_code = plumerai_object_detection_get_detections(pvi, &predictions,
&num_results);
if (error_code != PLUMERAI_SUCCESS) {
printf("Error: %s\n", plumerai_error_code_string(error_code));
return 1;
}
// Display the results to stdout
for (size_t i = 0; i < num_results; ++i) {
BoxPrediction p = predictions[i];
printf("Box #%d of class %d @ (x,y) -> (%.2f,%.2f) till (%.2f,%.2f)\n",
p.id, p.class_id, p.x_min, p.y_min, p.x_max, p.y_max);
}
if (num_results == 0) {
printf("No bounding boxes found in frame\n");
}
}
// Clean-up
free(image);
plumerai_video_intelligence_destroy(pvi);
return 0;
}