dsexample

I hope to make ROI so I did test by using NvOSD_LineParams

I think it’s hard to make ROI I want and everytime this line blinks if I used NvOSD_LineParams in Jetson Nano, not Jetson AGX Xavier

so I hope to make ROI Plugin (Element) by using openCV

now I am making new PlugIn so now refer to dsexmple PlugIn source

everytime I tried to insert my putText or drawContours into dsexample

my deepstream I made is not working propery but it’s working well if not define JETSON_NANO

How do I insert line or text not using NvOSD_TextParams and NvOSD_RectParams and NvOSD_LineParams ?

because I don’t want to use Rectangle

static GstFlowReturn
get_converted_mat (GstDsExample * dsexample, NvBufSurface *input_buf, gint idx,
    NvOSD_RectParams * crop_rect_params, gdouble & ratio, gint input_width,
    gint input_height)

...............
  // Cache the mapped data for CPU access
  NvBufSurfaceSyncForCpu (dsexample->inter_buf, 0, 0);

  // 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); 

#if defined(JETSON_NANO) // installed /opt/nvidia/deepstream/deepstream-4.0/lib/gst-plugins/  after build this plugin
  {
using namespace std;
using namespace cv;
	  string label = "Testing Text Rendering";
	  cv::Point center;
	  double font_scale = 0.5;
	  Scalar font_color(0, 0, 255);
	  int line_thickness = 2;
	  int font=FONT_HERSHEY_SCRIPT_SIMPLEX;

	  center.x = 10;
	  center.y = 40;

	  cv::putText(in_mat,
	                    label,
	                    center,
	                    font,
	                    font_scale,
	                    font_color,
	                    line_thickness);

  }
#endif 

  cv::cvtColor (in_mat, *dsexample->cvmat, CV_RGBA2BGR);

  if (NvBufSurfaceUnMap (dsexample->inter_buf, 0, 0)){
    goto error;
  }

Hi,
Please call NvBufSurfaceSyncForDevice() after cv::putText().

Hi,
NvOSD_LineParams is open for public. It should not trigger blink on Jetson Nano. We recently released DS4.0.1. If you still observe the issue on it, please share us a test code/patch to reproduce the issue.

Thanks for your help
I added NvBufSurfaceSyncForDevice() after cv::putText() but it’s not working
it’s same

........
NvBufSurfaceSyncForDevice(roi->inter_buf, 0, 0);
.........

now, I don’t use NvOSD_LineParams anymore
I will report this to you again and share it if I find it again

Thanks

Hi,
in_mat is a RGBA surface. Maybe cv::putText() accepts BGR surface only?

Yes, I think so

so I used cv::cvtColor (in_mat, *roi->cvmat, CV_RGBA2BGR);

I think cv::putText is not working properly, just simple test for OpenCV
now I am trying to find the reason why it does not work

I think NvBufSurfaceSyncForCpu or NvBufSurfaceSyncForDevice used mapped Memory for sharing between CPU and GPU

static GstFlowReturn
get_converted_mat (GstDsExample * dsexample, NvBufSurface *input_buf, gint idx,
    NvOSD_RectParams * crop_rect_params, gdouble & ratio, gint input_width,
    gint input_height)
{
...........
  // Map the buffer so that it can be accessed by CPU
  if (NvBufSurfaceMap (dsexample->inter_buf, 0, 0, NVBUF_MAP_READ) != 0){
    goto error;
  }

  // Cache the mapped data for CPU access
  NvBufSurfaceSyncForCpu (dsexample->inter_buf, 0, 0);

  // 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);

#if defined(JETSON_NANO)
  {
using namespace std;
using namespace cv;
	  string label = "Testing Text Rendering";
	  cv::Point center;
	  double font_scale = 0.5;
	  Scalar font_color(0, 0, 255);
	  int line_thickness = 2;
	  int font=FONT_HERSHEY_SCRIPT_SIMPLEX;

	  center.x = 10;
	  center.y = 40;
          
         // it don't work here , 
	  cv::putText(in_mat,
	                    label,
	                    center,
	                    font,
	                    font_scale,
	                    font_color,
	                    line_thickness);

  }
#endif

  cv::cvtColor (in_mat, *dsexample->cvmat, CV_RGBA2BGR);

#if 0 //defined(JETSON_NANO)
  NvBufSurfaceSyncForDevice(roi->inter_buf, 0, 0);
#endif

  if (NvBufSurfaceUnMap (dsexample->inter_buf, 0, 0)){
    goto error;
  }

Hi,
The call sequence should like:

//pseudo code
cv::cvtColor (in_mat, *dsexample->cvmat, CV_RGBA2BGR);
cv::putText(*dsexample->cvmat);
cv::cvtColor (*dsexample->cvmat, in_mat, CV_BGR2RGBA);

in_mat is dsexample->inter_buf and you need to transform it back to &ip_surf:

NvBufSurfTransform (dsexample->inter_buf, &ip_surf, &transform_params);

cv APIs take CPU loading and may hit performance issue. Suggest you use NvOSD implementations.