Please provide complete information as applicable to your setup.
• Hardware Platform (Jetson / GPU) GPU
• DeepStream Version 6.3 (Docker)
• Issue Type( questions, new requirements, bugs) Questions
Hello everyone, I want to extract images from deepstream process by using the code below to convert images in surface objects to RGB images.
static GstPadProbeReturn
pgie_src_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
gpointer u_data)
{
NvDsMetaList *l_obj = NULL;
NvDsObjectMeta *obj_meta = NULL;
GstBuffer *buf = (GstBuffer *) info->data;
NvDsMetaList * l_frame = NULL;
NvDsMetaList * l_user_meta = NULL;
NvDsUserMeta *user_meta = NULL;
NvDsInferSegmentationMeta *seg_meta_data = NULL;
NvBufSurfaceColorFormat *color_format = NULL;
char file_name[128];
// get metadata
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);
for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
l_frame = l_frame->next)
{
NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
GstMapInfo in_map_info;
NvBufSurface *surface = NULL;
memset (&in_map_info, 0, sizeof (in_map_info));
if (!gst_buffer_map (buf, &in_map_info, GST_MAP_READ)) {
g_print ("Error: Failed to map gst buffer\n");
gst_buffer_unmap (buf, &in_map_info);
return GST_PAD_PROBE_OK;
}
cudaError_t cuda_err;
NvBufSurfTransformRect src_rect, dst_rect;
surface = (NvBufSurface *) in_map_info.data;
int batch_size= surface->batchSize;
src_rect.top = 0;
src_rect.left = 0;
src_rect.width = (guint) surface->surfaceList[0].width;
src_rect.height= (guint) surface->surfaceList[0].height;
dst_rect.top = 0;
dst_rect.left = 0;
dst_rect.width = (guint) surface->surfaceList[0].width;
dst_rect.height= (guint) surface->surfaceList[0].height;
NvBufSurfTransformParams nvbufsurface_params;
nvbufsurface_params.src_rect = &src_rect;
nvbufsurface_params.dst_rect = &dst_rect;
nvbufsurface_params.transform_flag = NVBUFSURF_TRANSFORM_CROP_SRC | NVBUFSURF_TRANSFORM_CROP_DST;
nvbufsurface_params.transform_filter = NvBufSurfTransformInter_Default;
NvBufSurface *dst_surface = NULL;
NvBufSurfaceCreateParams nvbufsurface_create_params;
// An intermediate buffer for NV12/RGBA to BGR conversion will be
// required. Can be skipped if custom algorithm can work directly on NV12/RGBA
nvbufsurface_create_params.gpuId = surface->gpuId;
nvbufsurface_create_params.width = (gint) surface->surfaceList[0].width;
nvbufsurface_create_params.height = (gint) surface->surfaceList[0].height;
nvbufsurface_create_params.size = 0;
nvbufsurface_create_params.colorFormat = NVBUF_COLOR_FORMAT_RGB;
nvbufsurface_create_params.layout = NVBUF_LAYOUT_PITCH;
nvbufsurface_create_params.memType = NVBUF_MEM_CUDA_UNIFIED;
cuda_err = cudaSetDevice (surface->gpuId);
cudaStream_t cuda_stream;
cuda_err=cudaStreamCreate (&cuda_stream);
int create_result = NvBufSurfaceCreate(&dst_surface,batch_size,&nvbufsurface_create_params);
NvBufSurfTransformConfigParams transform_config_params;
NvBufSurfTransform_Error err;
transform_config_params.compute_mode = NvBufSurfTransformCompute_Default;
transform_config_params.gpu_id = surface->gpuId;
transform_config_params.cuda_stream = cuda_stream;
err = NvBufSurfTransformSetSessionParams (&transform_config_params);
NvBufSurfaceMemSet (dst_surface, 0, 0, 0);
err = NvBufSurfTransform (surface, dst_surface, &nvbufsurface_params);
if (err != NvBufSurfTransformError_Success) {
g_print ("NvBufSurfTransform failed with error %d while converting buffer\n", err);
}
NvBufSurfaceMap (dst_surface, 0, 0, NVBUF_MAP_READ);
NvBufSurfaceSyncForCpu (dst_surface, 0, 0);
std::cout << "Index " << frame_meta->source_id << std::endl;
std::cout << "Surfacelist.addr " << dst_surface->surfaceList[frame_meta->source_id].mappedAddr.addr[0] << std::endl;
// Will send to vitpose services if it's detect a person.
for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next)
{
obj_meta = (NvDsObjectMeta *) (l_obj->data);
if (obj_meta->class_id == PGIE_CLASS_ID_PERSON)
{
(I got this code from: Access frame pointer in deepstream-app - #30 by cbstryker)
Then I access the frame data by using this
dst_surface->surfaceList[0].mappedAddr.addr[0]
The above method works for one source, but if I increase the number of sources, then I cannot access all of the source frames. e.g., if I have two sources, I can only access the frames for one of the sources…
I tried to access the frame data by using this code.
dst_surface->surfaceList[frame_meta->source_id].mappedAddr.addr[0]
When the frame_meta->source_id is 0 its point to some memory address. e.g., 0x7f412d000000 but when the frame_meta->source_id is 1 it’s return 0 which I suspects it’s point to NULL.
Note: I use Gst-nvmultiurisrcbin to accept input stream, I do not know whether it’s related or not.
Does anyone knows how can I access each frames from each sources.
Appreciate for any kind of help.