Of course,to begin with,the EdgeDection is defined in the deepstream_app_config_parser_yaml.cpp:
//custom function
void EdgeDection(guint height,guint width,NvBufSurface *surface,NvDsFrameMeta *frame_meta,float * angle){
Mat nv12_mat = Mat(height*3/2, width, CV_8UC1, surface->surfaceList[frame_meta->batch_id].mappedAddr.addr[0],
surface->surfaceList[frame_meta->batch_id].pitch);
//Convert nv12 to RGBA to apply algo based on RGBA
Mat rgba_mat;
cvtColor(nv12_mat, rgba_mat, COLOR_YUV2BGRA_NV12);
for (NvDsMetaList * l_obj = frame_meta->obj_meta_list; l_obj != NULL;
l_obj = l_obj->next) {
NvDsObjectMeta *obj = (NvDsObjectMeta *) l_obj->data;
Rect bbox(obj->rect_params.left, obj->rect_params.top,
obj->rect_params.width, obj->rect_params.height);
Mat roi = rgba_mat(bbox);
float angle;
Ellipse_feature_extraction(roi,angle);
}
}
the Ellipse_feature_extraction is another custom function to get the angle of the detected object.
And the declaration in deepstream_app.h:
gboolean
parse_config_file_yaml (NvDsConfig * config, gchar * cfg_file_path);
void EdgeDection(int height,int width,NvBufSurface *surface,NvDsFrameMeta *frame_meta, float * angle);
the parse_config_file_yaml function, just like what I have mentioned,is originally defined in that cpp file and can be used in the deepstream_app_main.c
After that,my custom funtion is used in the deepstream_app.c,the code snippet:
static GstPadProbeReturn
gie_processing_done_buf_prob (GstPad * pad, GstPadProbeInfo * info,
gpointer u_data)
{
GstBuffer *buf = (GstBuffer *) info->data;
NvDsInstanceBin *bin = (NvDsInstanceBin *) u_data;
guint index = bin->index;
AppCtx *appCtx = bin->appCtx;
//extra
NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta(buf);
// Get original raw data
GstMapInfo 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;
}
NvBufSurface *surface = (NvBufSurface *)in_map_info.data;
for (NvDsMetaList * l_frame = batch_meta->frame_meta_list; l_frame != NULL;
l_frame = l_frame->next) {
NvDsFrameMeta *frame_meta = l_frame->data;
//TODO for cuda device memory we need to use cudamemcpy
NvBufSurfaceMap (surface, -1, -1, NVBUF_MAP_READ);
/* Cache the mapped data for CPU access */
NvBufSurfaceSyncForCpu (surface, 0, 0); //will do nothing for unified memory type on dGPU
guint height = surface->surfaceList[frame_meta->batch_id].height;
guint width = surface->surfaceList[frame_meta->batch_id].width;
float angle;
EdgeDection(height,width,surface,frame_meta,& angle);
}
}
As you can see,I call that funtion in the end,trying to get the ultimate angle parameter.If there are other codes you want to know,please feel free to tell me.