網頁

2020年10月15日 星期四

DeepStream 之 nvdsosd

nvosd = gst_element_factory_make ("nvdsosd", "nv-onscreendisplay");

不要顯示物件框框
g_object_set (G_OBJECT (nvosd), "display-bbox", 0, NULL);

不要顯示物件說明
g_object_set (G_OBJECT (nvosd), "display-text", 0, NULL);

左上角顯示時間
g_object_set (G_OBJECT (nvosd), "display-clock", 1, NULL);

osd_sink_pad = gst_element_get_static_pad (nvosd, "sink");
gst_pad_add_probe (osd_sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
GstPadProbeCallback, (gpointer)sink, NULL);
gst_object_unref (osd_sink_pad);

static GstPadProbeReturn GstPadProbeCallback(
  GstPad * pad, GstPadProbeInfo * info, gpointer u_data)
{
  GstBuffer *buf = (GstBuffer *) info->data;
  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);
    for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next) 
    {
      obj_meta = (NvDsObjectMeta *) (l_obj->data);
      // NvDsObjectMeta 宣告於 sources/includes/nvdsmeta.h
      // class_id: Holds the index of the object class inferred by the primary detector/classifier.
      // object_id: Holds a unique ID for tracking the object.
      //   UNTRACKED_OBJECT_ID indicates that the object has not been tracked.
      // rect_params: 物件的框框, 有可能來自 tracker
      // text_params: 物件說明 "主分類 track 類別1 類別2..."
      // obj_label: 主分類
      for (GList *l = obj_meta->classifier_meta_list; l != NULL; l = l->next)
      {
        NvDsClassifierMeta *classifierMeta = (NvDsClassifierMeta *) (l->data);
        // NvDsClassifierMeta 宣告於 sources/includes/nvdsmeta.h
        // unique_component_id: 分類 id
        NvDsLabelInfo *pLabel = get_possible_label(classifierMeta);
      }
    }
  }
}

NvDsLabelInfo *get_possible_label (NvDsClassifierMeta * classifierMeta)
{
  NvDsLabelInfo *pLabel = NULL;
  for (GList *n = classifierMeta->label_info_list; n != NULL; n = n->next) {
    NvDsLabelInfo *labelInfo = (NvDsLabelInfo *) (n->data);
    // NvDsLabelInfo 宣告於 sources/includes/nvdsmeta.h
    // result_class_id: 最佳的 分類id
    // result_prob: 可能性
    // result_label: 分類名
    // pResult_label: 當 result_label 太長, 放不下時, 放這裡
    if (pLabel == NULL) {
        pLabel = labelInfo;
    } else if (labelInfo->result_prob > pLabel->result_prob) {
        pLabel = labelInfo;
    }
  }
  return pLabel;
}

沒有留言:

張貼留言