Recator draw imprecise face

This commit is contained in:
Barzan Hayati 2025-08-24 09:18:13 +00:00
parent eee2868e7c
commit 65b8f9b9a8
2 changed files with 161 additions and 177 deletions

View File

@ -242,7 +242,6 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe(
(void)stream_height;
(void)stream_width;
// float source_id = (float)frame_meta->source_id;
/* Iterate user metadata in frames to search PGIE's tensor metadata */
for (NvDsMetaList *l_user = frame_meta->frame_user_meta_list;
l_user != NULL; l_user = l_user->next) {
@ -312,22 +311,19 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe(
jkl++) { // 100 persons for each frame
if (data[jkl * 57 + 4] > threshold_body_detection) {
detected_persons++;
// std::cout
// << "nvinferserver first for x = " << data[jkl * 57 +
// 0]
// << " y = " << data[jkl * 57 + 1]
// << " w = " << data[jkl * 57 + 2]
// << " h = " << data[jkl * 57 + 3]
// << " score = " << data[jkl * 57 + 4] << std::endl;
// for (unsigned int mno = 0; mno < 57; ++mno) {
// float value = data[jkl * 57 + mno];
// (void)value;
// // std::cout << "data[" << jkl << "][" << mno
// // << "] = " << value << std::endl;
// }
}
}
update_frame_with_face_body_meta(detected_persons, batch_meta, meta,
data, frame_meta);
}
}
// use_device_mem = 1 - use_device_mem;
return GST_PAD_PROBE_OK;
}
void NvInferServerManager::update_frame_with_face_body_meta(
uint detected_persons, NvDsBatchMeta *batch_meta, NvDsInferTensorMeta *meta,
float *data, NvDsFrameMeta *frame_meta) {
for (uint index = 0; index < detected_persons; index++) {
// imprecise_face_obj_meta is the imprecise face
NvDsObjectMeta *imprecise_face_obj_meta =
@ -371,11 +367,10 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe(
NvOSD_TextParams &text_params_imprecise_face =
imprecise_face_obj_meta->text_params;
/* Assign bounding box coordinates. */
rect_params_imprecise_face.left = int(
data[index * 57 + 0] * MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH);
rect_params_imprecise_face.left =
int(data[index * 57 + 0] * MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH);
rect_params_imprecise_face.top =
int(data[index * 57 + 1] * MUXER_OUTPUT_HEIGHT /
PGIE_NET_HEIGHT);
int(data[index * 57 + 1] * MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT);
float x_shoulder;
float y_shoulder;
if (data[index * 57 + 21] > data[index * 57 + 24]) {
@ -386,11 +381,11 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe(
y_shoulder = data[index * 57 + 25];
}
rect_params_imprecise_face.width =
int((x_shoulder - data[index * 57 + 0]) *
MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH);
int((x_shoulder - data[index * 57 + 0]) * MUXER_OUTPUT_WIDTH /
PGIE_NET_WIDTH);
rect_params_imprecise_face.height =
int((y_shoulder - data[index * 57 + 1]) *
MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT);
int((y_shoulder - data[index * 57 + 1]) * MUXER_OUTPUT_HEIGHT /
PGIE_NET_HEIGHT);
// std::cout << "nvinferserver imprecise face for x = " <<
// rect_params_imprecise_face.left
@ -403,39 +398,32 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe(
/* Border of width 3. */
rect_params_imprecise_face.border_width = 3;
rect_params_imprecise_face.has_bg_color = 0;
rect_params_imprecise_face.border_color =
NvOSD_ColorParams{0, 0, 1, 1};
rect_params_imprecise_face.border_color = NvOSD_ColorParams{0, 0, 1, 1};
/* display_text requires heap allocated memory. */
text_params_imprecise_face.display_text = g_strdup(
imprecise_face_str[0]); // g_strdup(pgie_class_str[0]);
text_params_imprecise_face.display_text =
g_strdup(imprecise_face_str[0]); // g_strdup(pgie_class_str[0]);
/* Display text above the left top corner of the object. */
text_params_imprecise_face.x_offset =
rect_params_imprecise_face.left;
text_params_imprecise_face.x_offset = rect_params_imprecise_face.left;
text_params_imprecise_face.y_offset =
rect_params_imprecise_face.top - 10;
/* Set black background for the text. */
text_params_imprecise_face.set_bg_clr = 1;
text_params_imprecise_face.text_bg_clr =
NvOSD_ColorParams{0, 0, 0, 1};
text_params_imprecise_face.text_bg_clr = NvOSD_ColorParams{0, 0, 0, 1};
/* Font face, size and color. */
text_params_imprecise_face.font_params.font_name =
(gchar *)"Serif";
text_params_imprecise_face.font_params.font_name = (gchar *)"Serif";
text_params_imprecise_face.font_params.font_size = 11;
text_params_imprecise_face.font_params.font_color =
NvOSD_ColorParams{1, 1, 1, 1};
// adding landmarks to imprecise_face_obj_meta as user_meta
NvDsUserMeta *um1 =
nvds_acquire_user_meta_from_pool(batch_meta);
um1->user_meta_data = set_metadata_ptr(
&(data[index * 57])); // Add landmarks here
NvDsUserMeta *um1 = nvds_acquire_user_meta_from_pool(batch_meta);
um1->user_meta_data =
set_metadata_ptr(&(data[index * 57])); // Add landmarks here
um1->base_meta.meta_type =
NVDS_USER_OBJECT_META_LANDMARKS_AND_SOURCE_ID;
um1->base_meta.copy_func = (NvDsMetaCopyFunc)copy_user_meta;
um1->base_meta.release_func =
(NvDsMetaReleaseFunc)release_user_meta;
um1->base_meta.release_func = (NvDsMetaReleaseFunc)release_user_meta;
nvds_add_user_meta_to_obj(imprecise_face_obj_meta, um1);
nvds_add_obj_meta_to_frame(frame_meta, imprecise_face_obj_meta,
NULL);
nvds_add_obj_meta_to_frame(frame_meta, imprecise_face_obj_meta, NULL);
NvDsObjectMeta *body_obj_meta =
nvds_acquire_obj_meta_from_pool(batch_meta);
@ -443,16 +431,14 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe(
body_obj_meta->unique_component_id = meta->unique_id;
body_obj_meta->confidence = data[index * 57 + 4];
// body_obj_meta->object_id = UNTRACKED_OBJECT_ID;
body_obj_meta->class_id =
PGIE_CLASS_ID_PERSON; // 0 for body detection
body_obj_meta->class_id = PGIE_CLASS_ID_PERSON; // 0 for body detection
NvOSD_RectParams &rect_params_body = body_obj_meta->rect_params;
NvOSD_TextParams &text_params_body = body_obj_meta->text_params;
/* Assign bounding box coordinates. */
rect_params_body.left = int(
data[index * 57 + 0] * MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH);
rect_params_body.left =
int(data[index * 57 + 0] * MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH);
rect_params_body.top =
int(data[index * 57 + 1] * MUXER_OUTPUT_HEIGHT /
PGIE_NET_HEIGHT);
int(data[index * 57 + 1] * MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT);
rect_params_body.width =
int((data[index * 57 + 2] - data[index * 57 + 0]) *
MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH);
@ -475,8 +461,7 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe(
/* Font face, size and color. */
text_params_body.font_params.font_name = (gchar *)"Serif";
text_params_body.font_params.font_size = 11;
text_params_body.font_params.font_color =
NvOSD_ColorParams{1, 1, 1, 1};
text_params_body.font_params.font_color = NvOSD_ColorParams{1, 1, 1, 1};
// // adding landmarks to body_obj_meta as user_meta
// NvDsUserMeta *um1 =
// nvds_acquire_user_meta_from_pool(batch_meta);
@ -491,10 +476,6 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe(
nvds_add_obj_meta_to_frame(frame_meta, body_obj_meta, NULL);
}
}
}
// use_device_mem = 1 - use_device_mem;
return GST_PAD_PROBE_OK;
}
// add custom infromation to metadata by: set_metadata_ptr, copy_user_meta,
// release_user_meta

View File

@ -40,4 +40,7 @@ class NvInferServerManager {
static void *set_metadata_ptr(float *);
static gpointer copy_user_meta(gpointer, gpointer);
static void release_user_meta(gpointer, gpointer);
static void update_frame_with_face_body_meta(uint, NvDsBatchMeta *,
NvDsInferTensorMeta *, float *,
NvDsFrameMeta *);
};