Please provide complete information as applicable to your setup.
• Hardware Platform - Jetson
• DeepStream Version - 5.1
• TensorRT Version - 7.1.3
• NVIDIA GPU Driver Version - cuda10.2
• Reading data from NvBufSurface
• Requirement details
I’m currently trying to access the RGB values of a single pixel located at a predetermined location in a frame of video.My current approach to accomplish this is to create a
cv::Mat
fromNvBufSurface
. This approach is derived from the source code ingstdsexample.cpp
, i.e.
struct _GstDsExample
{
GstBaseTransform base_trans;
/*
CODE
*/
// OpenCV mat containing RGB data
cv::Mat *cvmat;
/*
CODE
*/
};
/**
* Scale the entire frame to the processing resolution maintaining aspect ratio.
* Or crop and scale objects to the processing resolution maintaining the aspect
* ratio. Remove the padding required by hardware and convert from RGBA to RGB
* using openCV. These steps can be skipped if the algorithm can work with
* padded data and/or can work with RGBA.
*/
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){
/*
CODE
*/
//Memset the memory
NvBufSurfaceMemSet (nvbuf, 0, 0, 0);
GST_DEBUG_OBJECT (eventdetector, "Scaling and converting input buffer\n");
// Transformation scaling+format conversion if any.
err = NvBufSurfTransform (&ipSurf, nvbuf, &transformParams);
if (err != NvBufSurfTransformError_Success) {
GST_ELEMENT_ERROR (eventdetector, STREAM, FAILED,
("NvBufSurfTransform failed with error %d while converting buffer", err),
(NULL));
return false;
}
// Map the buffer so that it can be accessed by CPU
if (NvBufSurfaceMap (nvbuf, 0, 0, NVBUF_MAP_READ) != 0){
return false;
}
// Cache the mapped data for CPU access
NvBufSurfaceSyncForCpu (nvbuf, 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);
cv::cvtColor (in_mat, *dsexample->cvmat, CV_RGBA2BGR);
/*
CODE
*/
}
However, it was observed that when using this approach, there was a significant drop in performance i.e., fps dropped by nearly 15. On further investigation I was thinking operations like
cv::cvtColor()
,NvBufSurfaceSyncForCpu()
were causing the fps drop. In my application as I will not be using entire converted matrix but accessing the R,G,B values of specific pixel let say (50,50) for example. Is there any different approach to access those R,G,B,A values frominput_buf
for that specific pixel by skipping some of these operations and create R,G,B values ?