Enable dsexample in test app

The README file for gst ds-example gives instruction on how to use it for the deepstream-app. How do I add it in the pipeline in deepstream-test app?

It’s just a gstreamer plugin, you can add the plugin in your pipeline.

You can add the code like this

--- a/apps/deepstream/sample_apps/deepstream-test1/deepstream_test1_app.c
+++ b/apps/deepstream/sample_apps/deepstream-test1/deepstream_test1_app.c
@@ -149,7 +149,7 @@ main (int argc, char *argv[])
   GMainLoop *loop = NULL;
   GstElement *pipeline = NULL, *source = NULL, *h264parser = NULL,
       *decoder = NULL, *streammux = NULL, *sink = NULL, *pgie = NULL, *nvvidconv = NULL,
-      *nvosd = NULL;
+      *nvosd = NULL, *dsexample = NULL;
 #ifdef PLATFORM_TEGRA
   GstElement *transform = NULL;
 #endif
@@ -193,6 +193,9 @@ main (int argc, char *argv[])
    * behaviour of inferencing is set through config file */
   pgie = gst_element_factory_make ("nvinfer", "primary-nvinference-engine");
 
+  /* Create dsexample*/
+  dsexample = gst_element_factory_make ("dsexample", "ds-example");
+
   /* Use convertor to convert from NV12 to RGBA as required by nvosd */
   nvvidconv = gst_element_factory_make ("nvvideoconvert", "nvvideo-converter");
 
@@ -206,7 +209,7 @@ main (int argc, char *argv[])
   sink = gst_element_factory_make ("nveglglessink", "nvvideo-renderer");
 
   if (!source || !h264parser || !decoder || !pgie
-      || !nvvidconv || !nvosd || !sink) {
+      || !dsexample || !nvvidconv || !nvosd || !sink) {
     g_printerr ("One element could not be created. Exiting.\n");
     return -1;
   }
@@ -240,11 +243,11 @@ main (int argc, char *argv[])
 #ifdef PLATFORM_TEGRA
   gst_bin_add_many (GST_BIN (pipeline),
       source, h264parser, decoder, streammux, pgie,
-      nvvidconv, nvosd, transform, sink, NULL);
+      dsexample, nvvidconv, nvosd, transform, sink, NULL);
 #else
   gst_bin_add_many (GST_BIN (pipeline),
       source, h264parser, decoder, streammux, pgie,
-      nvvidconv, nvosd, sink, NULL);
+      dsexample, nvvidconv, nvosd, sink, NULL);
 #endif
 
   GstPad *sinkpad, *srcpad;
@@ -282,13 +285,13 @@ main (int argc, char *argv[])
 
 #ifdef PLATFORM_TEGRA
   if (!gst_element_link_many (streammux, pgie,
-      nvvidconv, nvosd, transform, sink, NULL)) {
+      dsexample, nvvidconv, nvosd, transform, sink, NULL)) {
     g_printerr ("Elements could not be linked: 2. Exiting.\n");
     return -1;
   }
 #else
   if (!gst_element_link_many (streammux, pgie,
-      nvvidconv, nvosd, sink, NULL)) {
+      dsexample, nvvidconv, nvosd, sink, NULL)) {
     g_printerr ("Elements could not be linked: 2. Exiting.\n");
     return -1;
   }

Thanks bcao, it works. Can you show me how to save without padding? Without changing the resolution of the detection?

Thanks bcao, it works. Can you show me how to save without padding? Without changing the resolution of the detection?

Not very clear about your question, you mean the dsexample plugin changing the resolution or padding?

Yes I would like the out::mat in dsexample to be not padded. I want to save the detection raw.

Did you enable setting “enable-padding” of streammux ? What’s your streammux setting ?

I tried with enable padding as both “0” and “1”. The problem is with the following part

// Use openCV to remove padding and convert RGBA to BGR. Can be skipped if
  // algorithm can handle padded RGBA data.
  in_mat =
      cv::Mat (dsexample->processing_height, dsexample->processing_width,
      CV_8UC4, dsexample->inter_buf->surfaceList[0].mappedAddr.addr[0],
      dsexample->inter_buf->surfaceList[0].pitch);
  out_mat =
      cv::Mat (cv::Size(dest_width, dest_height), CV_8UC3);

  cv::cvtColor (in_mat, out_mat, CV_RGBA2BGR);

Since I am not familiar with openCV on C++, I am not sure how to remove padding with OpenCV as in the comments. Also, I would like to know if this surfaceList[0] is from the direct source as I can notice a decrease in the quality of the saved images. Any suggestions?

Keep streammux width/height equal to be equal to the resolution of input, surfaceList[0] will be from the direct source

Hey Chris, Thanks for the clarification. I still have a problem with padding part. Is there any way to save images without padding? I tried changing the parameters of the below code and also the out_mat from dest_width and height. But it didnt seem to help.

in_mat =
      cv::Mat (dsexample->processing_height, dsexample->processing_width,
      CV_8UC4, dsexample->inter_buf->surfaceList[0].mappedAddr.addr[0],
      dsexample->inter_buf->surfaceList[0].pitch);
  out_mat =
      cv::Mat (cv::Size((dsexample->processing_width, dsexample->processing_height), CV_8UC3);

Can you tell me the part of the dsexample.cpp where the padding happens?

Can you print dsexample->processing_height, dsexample->processing_width, dsexample->inter_buf->surfaceList[0].pitch) ?

Processing_width–400—Processing_Height–200—surfaceList[0].Pitch–1792CAM
These are the sizes that I have given as the dsexample parameters.

Figured it out. Thanks. Dest_width and dest_height are the actual image dimensions.