How to modify dsexample plugin to add filter to sgie1 input?

• Hardware Platform (Jetson / GPU)
Jetson Orin
• DeepStream Version
6.1.1
• JetPack Version (valid for Jetson only)
5.0.2
• TensorRT Version
8.4.1-1+cuda11.4

Hello I am trying to modify gstdsexample.cpp to add a black-and-white filter for the input of my third detector. I have added dsexample plugin to my pipeline and successfully blur the detections using OpenCV.

I tried to modify the blur_objects function and added the filter but it does not have any effect on the video.

How can I modify gstdsexample.cpp to only apply the filter to the input of my third detector?

What’s your whole pipeline and where did you add the gstdsexample plugin?

I added gstdsexample plugin after my secondary detector before the third detector.

preprocessing = Gst.ElementFactory.make("dsexample", "pre-processing")
preprocessing.set_property('processing-width', 640)
preprocessing.set_property('processing-height', 480)
preprocessing.set_property('full-frame', 0)
preprocessing.set_property('unique-id', 15)
preprocessing.set_property('gpu-id', 0)
preprocessing.set_property('blur-objects', 1)

pipeline.add(q)
pipeline.add(pgie)
pipeline.add(tracker)
pipeline.add(sgie1)

pipeline.add(preprocessing)

pipeline.add(sgie2)
pipeline.add(nvstreamdemux)
pipeline.add(nvvidconvert_pre)
pipeline.add(filter1_pre)
pipeline.add(queue1)
pipeline.add(queue2)
pipeline.add(tee)
pipeline.add(msgconv)
pipeline.add(msgbroker)
  
streammux.link(q)
q.link(pgie)
pgie.link(tracker)
tracker.link(nvvidconvert_pre)
nvvidconvert_pre.link(filter1_pre)
filter1_pre.link(sgie1)

sgie1.link(preprocessing)
preprocessing.link(sgie2)

sgie2.link(tee)
queue1.link(msgconv)
msgconv.link(msgbroker)
queue2.link(nvstreamdemux)

How did you modify the blur_objects function? Did you compile it and put the new libnvdsgst_dsexample.so to the lib path?

#ifdef WITH_OPENCV
/*
 * Blur the detected objects when processing in object mode (full-frame=0)
 */
static GstFlowReturn
blur_objects (GstDsExample * dsexample, gint idx,
    NvOSD_RectParams * crop_rect_params, cv::Mat in_mat)
{
  cv::Rect crop_rect;

  if ((crop_rect_params->width == 0) || (crop_rect_params->height == 0)) {
    GST_ELEMENT_ERROR (dsexample, STREAM, FAILED,
        ("%s:crop_rect_params dimensions are zero",__func__), (NULL));
    return GST_FLOW_ERROR;
  }

/* rectangle for cropped objects */
  crop_rect = cv::Rect (crop_rect_params->left, crop_rect_params->top,
  crop_rect_params->width, crop_rect_params->height);

/* apply gaussian blur to the detected objects */
  //GaussianBlur(in_mat(crop_rect), in_mat(crop_rect), cv::Size(15,15), 4);
  cv::Mat greyMat1;
  cv::Mat greyMat2;
  cv::Mat greyMat3;
  cv::Mat out;
  

  cv::cvtColor(in_mat(crop_rect), greyMat1, cv::COLOR_BGR2GRAY);
  cv::cvtColor(in_mat(crop_rect), greyMat2, cv::COLOR_BGR2GRAY);
  cv::cvtColor(in_mat(crop_rect), greyMat3, cv::COLOR_BGR2GRAY);
  
  cv::Mat in[3] = {greyMat1,greyMat2,greyMat3};
  cv::merge(in, 3, out);
  in_mat(crop_rect) = out.clone();

  return GST_FLOW_OK;
}
#endif

I did compile it, but I didn’t add it to the lib path. Probably that is what I am missing. When you said lib path, what exactly do you mean? I comment out the blurring part and compiled it and the blurring do not happen. Not sure where I need to copy the libnvdsgst_dsexample.so

There is no update from you for a period, assuming this is not an issue anymore.
Hence we are closing this topic. If need further support, please open a new one.
Thanks

You need put it in the following path:

/usr/lib/aarch64-linux-gnu/gstreamer-1.0/deepstream/

We suggest you make a backup of the original library first. Then, you put the lib generated in the path.