Attach objects metadata to gstdsexample probe
This commit is contained in:
parent
92062a514e
commit
8dc2fad1fe
@ -1,5 +1,10 @@
|
|||||||
#include "gstds_example_manager.hpp"
|
#include "gstds_example_manager.hpp"
|
||||||
|
|
||||||
|
#define MAX_DISPLAY_LEN 64
|
||||||
|
#define PGIE_CLASS_ID_PERSON 0
|
||||||
|
|
||||||
|
gint GstdsExampleManager::frame_number = 0;
|
||||||
|
|
||||||
GstdsExampleManager::GstdsExampleManager() {}
|
GstdsExampleManager::GstdsExampleManager() {}
|
||||||
|
|
||||||
bool GstdsExampleManager::create_gstds_example() {
|
bool GstdsExampleManager::create_gstds_example() {
|
||||||
@ -10,4 +15,75 @@ bool GstdsExampleManager::create_gstds_example() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attach probe to a pad in the pipeline
|
||||||
|
void GstdsExampleManager::attach_probe_to_element() {
|
||||||
|
GstPad *src_pad = gst_element_get_static_pad(custom_plugin, "src");
|
||||||
|
if (!src_pad) {
|
||||||
|
std::cerr << "Unable to get gst ds example src pad\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_pad_add_probe(src_pad, GST_PAD_PROBE_TYPE_BUFFER,
|
||||||
|
gstds_example_src_pad_buffer_probe, NULL, NULL);
|
||||||
|
gst_object_unref(src_pad);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This is the buffer probe function that we have registered on the src pad
|
||||||
|
* of the gstds_example element. All the infer elements in the pipeline shall
|
||||||
|
* attach their metadata to the GstBuffer, here we will iterate & process the
|
||||||
|
* metadata forex: class ids to strings, counting of class_id objects etc. */
|
||||||
|
GstPadProbeReturn GstdsExampleManager::gstds_example_src_pad_buffer_probe(
|
||||||
|
GstPad *pad, GstPadProbeInfo *info, gpointer u_data) {
|
||||||
|
(void)pad;
|
||||||
|
(void)u_data;
|
||||||
|
GstBuffer *buf = (GstBuffer *)info->data;
|
||||||
|
guint num_rects = 0;
|
||||||
|
guint person_count = 0;
|
||||||
|
NvDsObjectMeta *obj_meta = NULL;
|
||||||
|
NvDsMetaList *l_frame = NULL;
|
||||||
|
NvDsMetaList *l_obj = NULL;
|
||||||
|
NvDsDisplayMeta *display_meta = NULL;
|
||||||
|
|
||||||
|
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf);
|
||||||
|
|
||||||
|
for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
|
||||||
|
l_frame = l_frame->next) {
|
||||||
|
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data);
|
||||||
|
int offset = 0;
|
||||||
|
for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;
|
||||||
|
l_obj = l_obj->next) {
|
||||||
|
obj_meta = (NvDsObjectMeta *)(l_obj->data);
|
||||||
|
if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) {
|
||||||
|
person_count++;
|
||||||
|
num_rects++;
|
||||||
|
std::cout << "In GstdsExample src "
|
||||||
|
<< "x = " << obj_meta->rect_params.left
|
||||||
|
<< " y = " << obj_meta->rect_params.top
|
||||||
|
<< " w = " << obj_meta->rect_params.width
|
||||||
|
<< " h = " << obj_meta->rect_params.height
|
||||||
|
<< " score = " << obj_meta->confidence
|
||||||
|
<< " Object ID: " << obj_meta->object_id
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
|
||||||
|
NvOSD_TextParams *txt_params = &display_meta->text_params[0];
|
||||||
|
display_meta->num_labels = 1;
|
||||||
|
txt_params->display_text = (gchar *)g_malloc0(MAX_DISPLAY_LEN);
|
||||||
|
offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN,
|
||||||
|
"Person = %d ", person_count);
|
||||||
|
(void)offset;
|
||||||
|
|
||||||
|
nvds_add_display_meta_to_frame(frame_meta, display_meta);
|
||||||
|
}
|
||||||
|
g_print(
|
||||||
|
"In GstdsExample src "
|
||||||
|
"Frame Number = %d "
|
||||||
|
"Person Count = %d\n",
|
||||||
|
frame_number, person_count);
|
||||||
|
|
||||||
|
frame_number++;
|
||||||
|
return GST_PAD_PROBE_OK;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "gstnvdsmeta.h"
|
||||||
class GstdsExampleManager {
|
class GstdsExampleManager {
|
||||||
private:
|
private:
|
||||||
public:
|
public:
|
||||||
@ -7,4 +11,8 @@ class GstdsExampleManager {
|
|||||||
GstdsExampleManager();
|
GstdsExampleManager();
|
||||||
bool create_gstds_example();
|
bool create_gstds_example();
|
||||||
~GstdsExampleManager();
|
~GstdsExampleManager();
|
||||||
|
static gint frame_number;
|
||||||
|
void attach_probe_to_element();
|
||||||
|
static GstPadProbeReturn gstds_example_src_pad_buffer_probe(
|
||||||
|
GstPad *, GstPadProbeInfo *, gpointer);
|
||||||
};
|
};
|
||||||
@ -60,137 +60,140 @@ bool NvInferServerManager::create_nv_infer_server(int num_sources) {
|
|||||||
|
|
||||||
// Probe function to inspect NvDsObjectMeta
|
// Probe function to inspect NvDsObjectMeta
|
||||||
|
|
||||||
GstPadProbeReturn NvInferServerManager::osd_sink_pad_buffer_probe(
|
// GstPadProbeReturn NvInferServerManager::osd_sink_pad_buffer_probe(
|
||||||
GstPad *pad, GstPadProbeInfo *info, gpointer user_data) {
|
// GstPad *pad, GstPadProbeInfo *info, gpointer user_data) {
|
||||||
(void)pad;
|
// (void)pad;
|
||||||
(void)user_data;
|
// (void)user_data;
|
||||||
GstBuffer *buf = (GstBuffer *)info->data;
|
// GstBuffer *buf = (GstBuffer *)info->data;
|
||||||
|
|
||||||
// Retrieve batch metadata from buffer
|
// // Retrieve batch metadata from buffer
|
||||||
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf);
|
// NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf);
|
||||||
if (!batch_meta) {
|
// if (!batch_meta) {
|
||||||
std::cerr << "No batch metadata found\n";
|
// std::cerr << "No batch metadata found\n";
|
||||||
return GST_PAD_PROBE_OK;
|
// return GST_PAD_PROBE_OK;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// probe sees the frame metadata (NvDsFrameMeta) —
|
// // probe sees the frame metadata (NvDsFrameMeta) —
|
||||||
// but no object metadata (NvDsObjectMeta) was attached to that frame.
|
// // but no object metadata (NvDsObjectMeta) was attached to that frame.
|
||||||
|
|
||||||
for (NvDsMetaList *l_frame = batch_meta->frame_meta_list; l_frame != NULL;
|
// for (NvDsMetaList *l_frame = batch_meta->frame_meta_list; l_frame !=
|
||||||
l_frame = l_frame->next) {
|
// NULL;
|
||||||
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data);
|
// l_frame = l_frame->next) {
|
||||||
// std::cout << "Frame number: " << frame_meta->frame_num << std::endl;
|
// NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data);
|
||||||
// if (frame_meta->obj_meta_list == NULL) {
|
// // std::cout << "Frame number: " << frame_meta->frame_num <<
|
||||||
// std::cout << " ⚠️ No object metadata for this frame.\n";
|
// std::endl;
|
||||||
// }
|
// // if (frame_meta->obj_meta_list == NULL) {
|
||||||
|
// // std::cout << " ⚠️ No object metadata for this frame.\n";
|
||||||
|
// // }
|
||||||
|
|
||||||
for (NvDsMetaList *l_obj = frame_meta->obj_meta_list; l_obj != NULL;
|
// for (NvDsMetaList *l_obj = frame_meta->obj_meta_list; l_obj != NULL;
|
||||||
l_obj = l_obj->next) {
|
// l_obj = l_obj->next) {
|
||||||
NvDsObjectMeta *obj_meta = (NvDsObjectMeta *)(l_obj->data);
|
// NvDsObjectMeta *obj_meta = (NvDsObjectMeta *)(l_obj->data);
|
||||||
|
|
||||||
std::cout << " Object ID: " << obj_meta->object_id << std::endl;
|
// std::cout << " Object ID: " << obj_meta->object_id << std::endl;
|
||||||
std::cout << " Class ID: " << obj_meta->class_id << std::endl;
|
// std::cout << " Class ID: " << obj_meta->class_id << std::endl;
|
||||||
std::cout << " Label: "
|
// std::cout << " Label: "
|
||||||
<< (obj_meta->obj_label ? obj_meta->obj_label : "N/A")
|
// << (obj_meta->obj_label ? obj_meta->obj_label : "N/A")
|
||||||
<< std::endl;
|
// << std::endl;
|
||||||
std::cout << " BBox: x=" << obj_meta->rect_params.left
|
// std::cout << " BBox: x=" << obj_meta->rect_params.left
|
||||||
<< " y=" << obj_meta->rect_params.top
|
// << " y=" << obj_meta->rect_params.top
|
||||||
<< " w=" << obj_meta->rect_params.width
|
// << " w=" << obj_meta->rect_params.width
|
||||||
<< " h=" << obj_meta->rect_params.height << std::endl;
|
// << " h=" << obj_meta->rect_params.height << std::endl;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return GST_PAD_PROBE_OK;
|
// return GST_PAD_PROBE_OK;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Attach probe to a pad in the pipeline
|
// // Attach probe to a pad in the pipeline
|
||||||
void NvInferServerManager::attach_probe_to_element(GstElement *nvosd) {
|
// void NvInferServerManager::attach_probe_to_element(GstElement *nvosd) {
|
||||||
GstPad *sink_pad = gst_element_get_static_pad(nvosd, "sink");
|
// GstPad *sink_pad = gst_element_get_static_pad(nvosd, "src");
|
||||||
if (!sink_pad) {
|
// if (!sink_pad) {
|
||||||
std::cerr << "Unable to get nvosd sink pad\n";
|
// std::cerr << "Unable to get nvosd sink pad\n";
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
|
// gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
|
||||||
osd_sink_pad_buffer_probe_new, NULL, NULL);
|
// osd_sink_pad_buffer_probe_new, NULL, NULL);
|
||||||
gst_object_unref(sink_pad);
|
// gst_object_unref(sink_pad);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/* This is the buffer probe function that we have registered on the sink pad
|
// /* This is the buffer probe function that we have registered on the sink pad
|
||||||
* of the OSD element. All the infer elements in the pipeline shall attach
|
// * of the OSD element. All the infer elements in the pipeline shall attach
|
||||||
* their metadata to the GstBuffer, here we will iterate & process the metadata
|
// * their metadata to the GstBuffer, here we will iterate & process the
|
||||||
* forex: class ids to strings, counting of class_id objects etc. */
|
// metadata
|
||||||
GstPadProbeReturn NvInferServerManager::osd_sink_pad_buffer_probe_new(
|
// * forex: class ids to strings, counting of class_id objects etc. */
|
||||||
GstPad *pad, GstPadProbeInfo *info, gpointer u_data) {
|
// GstPadProbeReturn NvInferServerManager::osd_sink_pad_buffer_probe_new(
|
||||||
(void)pad;
|
// GstPad *pad, GstPadProbeInfo *info, gpointer u_data) {
|
||||||
(void)u_data;
|
// (void)pad;
|
||||||
GstBuffer *buf = (GstBuffer *)info->data;
|
// (void)u_data;
|
||||||
guint num_rects = 0;
|
// GstBuffer *buf = (GstBuffer *)info->data;
|
||||||
guint person_count = 0;
|
// guint num_rects = 0;
|
||||||
NvDsObjectMeta *obj_meta = NULL;
|
// guint person_count = 0;
|
||||||
NvDsMetaList *l_frame = NULL;
|
// NvDsObjectMeta *obj_meta = NULL;
|
||||||
NvDsMetaList *l_obj = NULL;
|
// NvDsMetaList *l_frame = NULL;
|
||||||
NvDsDisplayMeta *display_meta = NULL;
|
// NvDsMetaList *l_obj = NULL;
|
||||||
|
// NvDsDisplayMeta *display_meta = NULL;
|
||||||
|
|
||||||
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf);
|
// NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf);
|
||||||
|
|
||||||
for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
|
// for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
|
||||||
l_frame = l_frame->next) {
|
// l_frame = l_frame->next) {
|
||||||
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data);
|
// NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data);
|
||||||
int offset = 0;
|
// int offset = 0;
|
||||||
for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;
|
// for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;
|
||||||
l_obj = l_obj->next) {
|
// l_obj = l_obj->next) {
|
||||||
obj_meta = (NvDsObjectMeta *)(l_obj->data);
|
// obj_meta = (NvDsObjectMeta *)(l_obj->data);
|
||||||
if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) {
|
// if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) {
|
||||||
person_count++;
|
// person_count++;
|
||||||
num_rects++;
|
// num_rects++;
|
||||||
std::cout << "In OSD sink "
|
// std::cout << "In OSD sink "
|
||||||
<< "x = " << obj_meta->rect_params.left
|
// << "x = " << obj_meta->rect_params.left
|
||||||
<< " y = " << obj_meta->rect_params.top
|
// << " y = " << obj_meta->rect_params.top
|
||||||
<< " w = " << obj_meta->rect_params.width
|
// << " w = " << obj_meta->rect_params.width
|
||||||
<< " h = " << obj_meta->rect_params.height
|
// << " h = " << obj_meta->rect_params.height
|
||||||
<< " score = " << obj_meta->confidence
|
// << " score = " << obj_meta->confidence
|
||||||
<< " Object ID: " << obj_meta->object_id
|
// << " Object ID: " << obj_meta->object_id
|
||||||
<< std::endl;
|
// << std::endl;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
|
// display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
|
||||||
NvOSD_TextParams *txt_params = &display_meta->text_params[0];
|
// NvOSD_TextParams *txt_params = &display_meta->text_params[0];
|
||||||
display_meta->num_labels = 1;
|
// display_meta->num_labels = 1;
|
||||||
txt_params->display_text = (gchar *)g_malloc0(MAX_DISPLAY_LEN);
|
// txt_params->display_text = (gchar *)g_malloc0(MAX_DISPLAY_LEN);
|
||||||
offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN,
|
// offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN,
|
||||||
"Person = %d ", person_count);
|
// "Person = %d ", person_count);
|
||||||
(void)offset;
|
// (void)offset;
|
||||||
|
|
||||||
/* Now set the offsets where the string should appear */
|
// /* Now set the offsets where the string should appear */
|
||||||
txt_params->x_offset = 10;
|
// txt_params->x_offset = 10;
|
||||||
txt_params->y_offset = 12;
|
// txt_params->y_offset = 12;
|
||||||
|
|
||||||
/* Font , font-color and font-size */
|
// /* Font , font-color and font-size */
|
||||||
txt_params->font_params.font_name = (gchar *)"Serif";
|
// txt_params->font_params.font_name = (gchar *)"Serif";
|
||||||
txt_params->font_params.font_size = 10;
|
// txt_params->font_params.font_size = 10;
|
||||||
txt_params->font_params.font_color.red = 1.0;
|
// txt_params->font_params.font_color.red = 1.0;
|
||||||
txt_params->font_params.font_color.green = 1.0;
|
// txt_params->font_params.font_color.green = 1.0;
|
||||||
txt_params->font_params.font_color.blue = 1.0;
|
// txt_params->font_params.font_color.blue = 1.0;
|
||||||
txt_params->font_params.font_color.alpha = 1.0;
|
// txt_params->font_params.font_color.alpha = 1.0;
|
||||||
|
|
||||||
/* Text background color */
|
// /* Text background color */
|
||||||
txt_params->set_bg_clr = 1;
|
// txt_params->set_bg_clr = 1;
|
||||||
txt_params->text_bg_clr.red = 0.0;
|
// txt_params->text_bg_clr.red = 0.0;
|
||||||
txt_params->text_bg_clr.green = 0.0;
|
// txt_params->text_bg_clr.green = 0.0;
|
||||||
txt_params->text_bg_clr.blue = 0.0;
|
// txt_params->text_bg_clr.blue = 0.0;
|
||||||
txt_params->text_bg_clr.alpha = 1.0;
|
// txt_params->text_bg_clr.alpha = 1.0;
|
||||||
|
|
||||||
nvds_add_display_meta_to_frame(frame_meta, display_meta);
|
// nvds_add_display_meta_to_frame(frame_meta, display_meta);
|
||||||
}
|
// }
|
||||||
g_print(
|
// g_print(
|
||||||
"In OSD sink "
|
// "In OSD sink "
|
||||||
"Frame Number = %d "
|
// "Frame Number = %d "
|
||||||
"Person Count = %d\n",
|
// "Person Count = %d\n",
|
||||||
frame_number, person_count);
|
// frame_number, person_count);
|
||||||
|
|
||||||
frame_number++;
|
// frame_number++;
|
||||||
return GST_PAD_PROBE_OK;
|
// return GST_PAD_PROBE_OK;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/* This is the buffer probe function that we have registered on the src pad
|
/* This is the buffer probe function that we have registered on the src pad
|
||||||
* of the PGIE's next queue element. PGIE element in the pipeline shall attach
|
* of the PGIE's next queue element. PGIE element in the pipeline shall attach
|
||||||
@ -295,15 +298,16 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe(
|
|||||||
|
|
||||||
uint detected_persons = 0;
|
uint detected_persons = 0;
|
||||||
float *data = static_cast<float *>(layer.buffer);
|
float *data = static_cast<float *>(layer.buffer);
|
||||||
for (unsigned int jkl = 0; jkl < 100; jkl+=4) { // 100 persons for each frame
|
for (unsigned int jkl = 0; jkl < 100;
|
||||||
|
jkl += 4) { // 100 persons for each frame
|
||||||
if (data[jkl * 57 + 4] > threshold_body_detection) {
|
if (data[jkl * 57 + 4] > threshold_body_detection) {
|
||||||
detected_persons++;
|
detected_persons++;
|
||||||
std::cout << "first for x = " << data[jkl * 57 + 0]
|
std::cout
|
||||||
<< " y = " << data[jkl * 57 + 1]
|
<< "nvinferserver first for x = " << data[jkl * 57 + 0]
|
||||||
<< " w = " << data[jkl * 57 + 2]
|
<< " y = " << data[jkl * 57 + 1]
|
||||||
<< " h = " << data[jkl * 57 + 3]
|
<< " w = " << data[jkl * 57 + 2]
|
||||||
<< " score = " << data[jkl * 57 + 4] <<
|
<< " h = " << data[jkl * 57 + 3]
|
||||||
std::endl;
|
<< " score = " << data[jkl * 57 + 4] << std::endl;
|
||||||
for (unsigned int mno = 0; mno < 5; ++mno) {
|
for (unsigned int mno = 0; mno < 5; ++mno) {
|
||||||
float value = data[jkl * 57 + mno];
|
float value = data[jkl * 57 + mno];
|
||||||
(void)value;
|
(void)value;
|
||||||
@ -323,25 +327,23 @@ GstPadProbeReturn NvInferServerManager::pgie_pad_buffer_probe(
|
|||||||
NvOSD_RectParams &rect_params = obj_meta->rect_params;
|
NvOSD_RectParams &rect_params = obj_meta->rect_params;
|
||||||
NvOSD_TextParams &text_params = obj_meta->text_params;
|
NvOSD_TextParams &text_params = obj_meta->text_params;
|
||||||
/* Assign bounding box coordinates. */
|
/* Assign bounding box coordinates. */
|
||||||
rect_params.left =
|
rect_params.left = int(data[index * 57 + 0] *
|
||||||
int(data[index * 57 + 0] * MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH);
|
MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH);
|
||||||
rect_params.top = int(data[index * 57 + 1] * MUXER_OUTPUT_HEIGHT /
|
rect_params.top = int(data[index * 57 + 1] *
|
||||||
PGIE_NET_HEIGHT);
|
MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT);
|
||||||
rect_params.width =
|
rect_params.width =
|
||||||
int((data[index * 57 + 2] - data[index * 57 + 0]) *
|
int((data[index * 57 + 2] - data[index * 57 + 0]) *
|
||||||
MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH);
|
MUXER_OUTPUT_WIDTH / PGIE_NET_WIDTH);
|
||||||
rect_params.height =
|
rect_params.height =
|
||||||
int((data[index * 57 + 3] - data[index * 57 + 1]) *
|
int((data[index * 57 + 3] - data[index * 57 + 1]) *
|
||||||
MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT);
|
MUXER_OUTPUT_HEIGHT / PGIE_NET_HEIGHT);
|
||||||
|
|
||||||
|
std::cout << "nvinferserver second for x = " << rect_params.left
|
||||||
|
<< " y = " << rect_params.top
|
||||||
|
<< " w = " << rect_params.width
|
||||||
|
<< " h = " << rect_params.height
|
||||||
|
<< " score = " << obj_meta->confidence << std::endl;
|
||||||
|
|
||||||
std::cout << "second for x = " << rect_params.left
|
|
||||||
<< " y = " << rect_params.top
|
|
||||||
<< " w = " << rect_params.top
|
|
||||||
<< " h = " << rect_params.width
|
|
||||||
<< " score = " << obj_meta->confidence <<
|
|
||||||
std::endl;
|
|
||||||
|
|
||||||
/* Border of width 3. */
|
/* Border of width 3. */
|
||||||
rect_params.border_width = 3;
|
rect_params.border_width = 3;
|
||||||
rect_params.has_bg_color = 0;
|
rect_params.has_bg_color = 0;
|
||||||
|
|||||||
@ -26,13 +26,13 @@ class NvInferServerManager {
|
|||||||
NvInferServerManager();
|
NvInferServerManager();
|
||||||
bool create_nv_infer_server(int);
|
bool create_nv_infer_server(int);
|
||||||
~NvInferServerManager();
|
~NvInferServerManager();
|
||||||
static GstPadProbeReturn osd_sink_pad_buffer_probe(GstPad *,
|
// static GstPadProbeReturn osd_sink_pad_buffer_probe(GstPad *,
|
||||||
GstPadProbeInfo *,
|
// GstPadProbeInfo *,
|
||||||
gpointer);
|
// gpointer);
|
||||||
void attach_probe_to_element(GstElement *);
|
// void attach_probe_to_element(GstElement *);
|
||||||
static GstPadProbeReturn pgie_pad_buffer_probe(GstPad *, GstPadProbeInfo *,
|
static GstPadProbeReturn pgie_pad_buffer_probe(GstPad *, GstPadProbeInfo *,
|
||||||
gpointer);
|
gpointer);
|
||||||
static GstPadProbeReturn osd_sink_pad_buffer_probe_new(GstPad *,
|
// static GstPadProbeReturn osd_sink_pad_buffer_probe_new(GstPad *,
|
||||||
GstPadProbeInfo *,
|
// GstPadProbeInfo
|
||||||
gpointer);
|
// *, gpointer);
|
||||||
};
|
};
|
||||||
@ -7,6 +7,10 @@
|
|||||||
1 // use GPU to draw rectangles, keypoints and text on frame if
|
1 // use GPU to draw rectangles, keypoints and text on frame if
|
||||||
// OSD_PROCESS_MODE set to 1
|
// OSD_PROCESS_MODE set to 1
|
||||||
#define OSD_DISPLAY_TEXT 1
|
#define OSD_DISPLAY_TEXT 1
|
||||||
|
#define MAX_DISPLAY_LEN 64
|
||||||
|
#define PGIE_CLASS_ID_PERSON 0
|
||||||
|
|
||||||
|
gint NvOsdManager::frame_number = 0;
|
||||||
|
|
||||||
NvOsdManager::NvOsdManager() {}
|
NvOsdManager::NvOsdManager() {}
|
||||||
|
|
||||||
@ -23,4 +27,95 @@ bool NvOsdManager::create_nv_osd() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attach probe to a pad in the pipeline
|
||||||
|
void NvOsdManager::attach_probe_to_element() {
|
||||||
|
GstPad *src_pad = gst_element_get_static_pad(nvosd, "src");
|
||||||
|
if (!src_pad) {
|
||||||
|
std::cerr << "Unable to get nvosd src pad\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_pad_add_probe(src_pad, GST_PAD_PROBE_TYPE_BUFFER,
|
||||||
|
osd_src_pad_buffer_probe, NULL, NULL);
|
||||||
|
gst_object_unref(src_pad);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This is the buffer probe function that we have registered on the sink pad
|
||||||
|
* of the OSD element. All the infer elements in the pipeline shall attach
|
||||||
|
* their metadata to the GstBuffer, here we will iterate & process the metadata
|
||||||
|
* forex: class ids to strings, counting of class_id objects etc. */
|
||||||
|
GstPadProbeReturn NvOsdManager::osd_src_pad_buffer_probe(GstPad *pad,
|
||||||
|
GstPadProbeInfo *info,
|
||||||
|
gpointer u_data) {
|
||||||
|
(void)pad;
|
||||||
|
(void)u_data;
|
||||||
|
GstBuffer *buf = (GstBuffer *)info->data;
|
||||||
|
guint num_rects = 0;
|
||||||
|
guint person_count = 0;
|
||||||
|
NvDsObjectMeta *obj_meta = NULL;
|
||||||
|
NvDsMetaList *l_frame = NULL;
|
||||||
|
NvDsMetaList *l_obj = NULL;
|
||||||
|
NvDsDisplayMeta *display_meta = NULL;
|
||||||
|
|
||||||
|
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf);
|
||||||
|
|
||||||
|
for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
|
||||||
|
l_frame = l_frame->next) {
|
||||||
|
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *)(l_frame->data);
|
||||||
|
int offset = 0;
|
||||||
|
for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;
|
||||||
|
l_obj = l_obj->next) {
|
||||||
|
obj_meta = (NvDsObjectMeta *)(l_obj->data);
|
||||||
|
if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) {
|
||||||
|
person_count++;
|
||||||
|
num_rects++;
|
||||||
|
std::cout << "In OSD sink "
|
||||||
|
<< "x = " << obj_meta->rect_params.left
|
||||||
|
<< " y = " << obj_meta->rect_params.top
|
||||||
|
<< " w = " << obj_meta->rect_params.width
|
||||||
|
<< " h = " << obj_meta->rect_params.height
|
||||||
|
<< " score = " << obj_meta->confidence
|
||||||
|
<< " Object ID: " << obj_meta->object_id
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
|
||||||
|
NvOSD_TextParams *txt_params = &display_meta->text_params[0];
|
||||||
|
display_meta->num_labels = 1;
|
||||||
|
txt_params->display_text = (gchar *)g_malloc0(MAX_DISPLAY_LEN);
|
||||||
|
offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN,
|
||||||
|
"Person = %d ", person_count);
|
||||||
|
(void)offset;
|
||||||
|
|
||||||
|
/* Now set the offsets where the string should appear */
|
||||||
|
txt_params->x_offset = 10;
|
||||||
|
txt_params->y_offset = 12;
|
||||||
|
|
||||||
|
/* Font , font-color and font-size */
|
||||||
|
txt_params->font_params.font_name = (gchar *)"Serif";
|
||||||
|
txt_params->font_params.font_size = 10;
|
||||||
|
txt_params->font_params.font_color.red = 1.0;
|
||||||
|
txt_params->font_params.font_color.green = 1.0;
|
||||||
|
txt_params->font_params.font_color.blue = 1.0;
|
||||||
|
txt_params->font_params.font_color.alpha = 1.0;
|
||||||
|
|
||||||
|
/* Text background color */
|
||||||
|
txt_params->set_bg_clr = 1;
|
||||||
|
txt_params->text_bg_clr.red = 0.0;
|
||||||
|
txt_params->text_bg_clr.green = 0.0;
|
||||||
|
txt_params->text_bg_clr.blue = 0.0;
|
||||||
|
txt_params->text_bg_clr.alpha = 1.0;
|
||||||
|
|
||||||
|
nvds_add_display_meta_to_frame(frame_meta, display_meta);
|
||||||
|
}
|
||||||
|
g_print(
|
||||||
|
"In OSD sink "
|
||||||
|
"Frame Number = %d "
|
||||||
|
"Person Count = %d\n",
|
||||||
|
frame_number, person_count);
|
||||||
|
|
||||||
|
frame_number++;
|
||||||
|
return GST_PAD_PROBE_OK;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "gstnvdsmeta.h"
|
||||||
|
|
||||||
class NvOsdManager {
|
class NvOsdManager {
|
||||||
private:
|
private:
|
||||||
public:
|
public:
|
||||||
@ -7,4 +12,9 @@ class NvOsdManager {
|
|||||||
NvOsdManager();
|
NvOsdManager();
|
||||||
bool create_nv_osd();
|
bool create_nv_osd();
|
||||||
~NvOsdManager();
|
~NvOsdManager();
|
||||||
|
static gint frame_number;
|
||||||
|
void attach_probe_to_element();
|
||||||
|
static GstPadProbeReturn osd_src_pad_buffer_probe(GstPad *,
|
||||||
|
GstPadProbeInfo *,
|
||||||
|
gpointer);
|
||||||
};
|
};
|
||||||
@ -5,7 +5,6 @@
|
|||||||
#define GPU_ID 0
|
#define GPU_ID 0
|
||||||
#define MAX_DISPLAY_LEN 64
|
#define MAX_DISPLAY_LEN 64
|
||||||
#define PGIE_CLASS_ID_PERSON 0
|
#define PGIE_CLASS_ID_PERSON 0
|
||||||
#define PGIE_DETECTED_CLASS_NUM 1
|
|
||||||
|
|
||||||
gint NvTrackerManager::frame_number = 0;
|
gint NvTrackerManager::frame_number = 0;
|
||||||
|
|
||||||
@ -32,23 +31,23 @@ bool NvTrackerManager::create_nv_tracker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attach probe to a pad in the pipeline
|
// Attach probe to a pad in the pipeline
|
||||||
void NvTrackerManager::attach_probe_to_element(GstElement *nvosd) {
|
void NvTrackerManager::attach_probe_to_element() {
|
||||||
GstPad *sink_pad = gst_element_get_static_pad(nvosd, "src");
|
GstPad *src_pad = gst_element_get_static_pad(tracker, "src");
|
||||||
if (!sink_pad) {
|
if (!src_pad) {
|
||||||
std::cerr << "Unable to get nvosd sink pad\n";
|
std::cerr << "Unable to get nvosd src pad\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_pad_add_probe(sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
|
gst_pad_add_probe(src_pad, GST_PAD_PROBE_TYPE_BUFFER,
|
||||||
tracker_sink_pad_buffer_probe, NULL, NULL);
|
tracker_src_pad_buffer_probe, NULL, NULL);
|
||||||
gst_object_unref(sink_pad);
|
gst_object_unref(src_pad);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is the buffer probe function that we have registered on the sink pad
|
/* This is the buffer probe function that we have registered on the sink pad
|
||||||
* of the OSD element. All the infer elements in the pipeline shall attach
|
* of the OSD element. All the infer elements in the pipeline shall attach
|
||||||
* their metadata to the GstBuffer, here we will iterate & process the metadata
|
* their metadata to the GstBuffer, here we will iterate & process the metadata
|
||||||
* forex: class ids to strings, counting of class_id objects etc. */
|
* forex: class ids to strings, counting of class_id objects etc. */
|
||||||
GstPadProbeReturn NvTrackerManager::tracker_sink_pad_buffer_probe(
|
GstPadProbeReturn NvTrackerManager::tracker_src_pad_buffer_probe(
|
||||||
GstPad *pad, GstPadProbeInfo *info, gpointer u_data) {
|
GstPad *pad, GstPadProbeInfo *info, gpointer u_data) {
|
||||||
(void)pad;
|
(void)pad;
|
||||||
(void)u_data;
|
(void)u_data;
|
||||||
|
|||||||
@ -16,8 +16,8 @@ class NvTrackerManager {
|
|||||||
NvTrackerManager();
|
NvTrackerManager();
|
||||||
~NvTrackerManager();
|
~NvTrackerManager();
|
||||||
bool create_nv_tracker();
|
bool create_nv_tracker();
|
||||||
void attach_probe_to_element(GstElement *);
|
void attach_probe_to_element();
|
||||||
static GstPadProbeReturn tracker_sink_pad_buffer_probe(GstPad *,
|
static GstPadProbeReturn tracker_src_pad_buffer_probe(GstPad *,
|
||||||
GstPadProbeInfo *,
|
GstPadProbeInfo *,
|
||||||
gpointer);
|
gpointer);
|
||||||
};
|
};
|
||||||
@ -330,6 +330,8 @@ bool PipelineManager::create_pipeline_elements(int num_sources,
|
|||||||
}
|
}
|
||||||
|
|
||||||
gstds_example_manager->create_gstds_example();
|
gstds_example_manager->create_gstds_example();
|
||||||
|
gstds_example_manager->attach_probe_to_element();
|
||||||
|
|
||||||
tiler_manager->create_tiler(num_sources,
|
tiler_manager->create_tiler(num_sources,
|
||||||
streammux_manager->MUXER_OUTPUT_WIDTH,
|
streammux_manager->MUXER_OUTPUT_WIDTH,
|
||||||
streammux_manager->MUXER_OUTPUT_HEIGHT);
|
streammux_manager->MUXER_OUTPUT_HEIGHT);
|
||||||
@ -350,14 +352,17 @@ bool PipelineManager::create_pipeline_elements(int num_sources,
|
|||||||
|
|
||||||
// GstElement *nvinfer = gst_bin_get_by_name(GST_BIN(pipeline),
|
// GstElement *nvinfer = gst_bin_get_by_name(GST_BIN(pipeline),
|
||||||
// "primary-nvinference-engine");
|
// "primary-nvinference-engine");
|
||||||
nv_infer_server_manager->attach_probe_to_element(
|
// nv_infer_server_manager->attach_probe_to_element(
|
||||||
nv_osd_manager->nvosd); // nvinfer Or use "nvtracker" if after
|
// nv_osd_manager->nvosd); // nvinfer Or use "nvtracker" if after
|
||||||
// tracker
|
// tracker
|
||||||
// gst_object_unref(nvinfer);
|
// gst_object_unref(nvinfer);
|
||||||
|
|
||||||
nv_tracker_manager->create_nv_tracker();
|
nv_tracker_manager->create_nv_tracker();
|
||||||
nv_tracker_manager->attach_probe_to_element(
|
nv_tracker_manager
|
||||||
nv_tracker_manager->tracker); // nvinfer Or use "nvtracker" if after
|
->attach_probe_to_element(); // nvinfer Or use "nvtracker" if after
|
||||||
|
|
||||||
|
nv_osd_manager
|
||||||
|
->attach_probe_to_element(); // nvinfer Or use "nvtracker" if after
|
||||||
|
|
||||||
message_handling->create_message_handler(pipeline, g_run_forever, loop);
|
message_handling->create_message_handler(pipeline, g_run_forever, loop);
|
||||||
setup_pipeline();
|
setup_pipeline();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user