Opencv in deepstream and memory usage %

When I run this line in deepstream
cv::addWeighted(color, alpha, roi, 1.0 - alpha, 0.0, roi);

Memory usage by deepstream % is 205 and skyrocketed as shown in attached image.

If I close that line, the mem % usage by deepstream is 11.5% only.

What could be issue?

Can you share the reproduce step? So I can check it in my side.

I used deepstream-app.
Then gstdsexample is enabled in config file as


Then full-frame is enabled and inside the following function

static GstFlowReturn
gst_dsexample_transform_ip (GstBaseTransform * btrans, GstBuffer * inbuf){}

You can plot a rectangle with a transparency as

cv::Mat roi = in_mat(cv::Rect(x1, y1, x2-x1, y2-y1 )); 
cv::Mat color(roi.size(), CV_8UC4, cv::Scalar( 0, 0, 255 ));
double alpha = 0.3;
cv::addWeighted(color, alpha, roi, 1.0 - alpha, 0.0, roi);

I used TOP to see memory %.

At the same time, when you check the issue can please check also why this color value cv::Scalar( 0, 0, 255 ) doesn’t reflect in display? Say I like to change to red, but it shows gray only.

Can you share the patch or gstdsexample.cpp which can reproduce your issue?

I used this file.
gstdsexample.cpp (43.2 KB)
Pls let me know if you need more.

@kesong may I have reply?

Crazy busy. Will reproduce it later and feedback you. Thanks.

@kesong Thanks. Because I need to deploy the solution on Friday. I like to settle before deployment.

Please try latest release DS5.1. Latest release always has better quality.

I tried latest version. Speed is definitely much faster. But memory % still increasing.

OpenCV will excute on CPU. Suggest to use other HW accelerated function if possible.

How can I do that?

Can you describe the purpose of the plugin?

I need to get tracking bounding boxes of detected objects and do next level of decision making. Then I also need to draw additional boxes on image.

Is it enough for you with below plugin? Or you need more feature for the plugin?

Gst-nvdsosd — DeepStream 5.1 Release documentation (

How can I use this plugin? I need to use c++ vector. So in .c file, I can’t use c++ vector, right?

Did you try use nvdsanalytics to draw rectangle, trigger object move in this rectangle and get bounding of object

example test5 custom: deepstream-occupancy-analytics/config at master · NVIDIA-AI-IOT/deepstream-occupancy-analytics · Git

Thanks I can get bounding box. Just have memory issue in plotting rectangles.

Is it possible to use below API for your task? I think below API shouldn’t have memory issue.