美文网首页
deepstream6.0 保存图片

deepstream6.0 保存图片

作者: leon_tly | 来源:发表于2022-12-04 11:14 被阅读0次

    code

    static GstPadProbeReturn
    tiler_src_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
        gpointer u_data)
    {
        GstBuffer *buf = (GstBuffer *)info->data;
        GstMapInfo in_map_info;
        NvBufSurface *surface = NULL;
        guint num_rects = 0;
        NvDsObjectMeta *obj_meta = NULL;
        guint vehicle_count = 0;
        guint person_count = 0;
        NvDsMetaList * l_frame = NULL;
        NvDsMetaList * l_obj = NULL;
        //NvDsDisplayMeta *display_meta = NULL;
        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);
            if (!gst_buffer_map (buf, &in_map_info, GST_MAP_READ))
            {
                g_print ("gst_buffer_map() error!");
                gst_buffer_unmap(buf, &in_map_info);
                return (GstPadProbeReturn)NULL;
            }
            surface =  (NvBufSurface *) in_map_info.data;
            char *src_data = (char*)malloc(surface->surfaceList[frame_meta->batch_id].dataSize);
            cudaMemcpy((void *)src_data,
                         (void *)surface->surfaceList[frame_meta->batch_id].dataPtr,
                         surface->surfaceList[frame_meta->batch_id].dataSize,
                         cudaMemcpyDeviceToHost);
            gint frame_width = (gint)surface->surfaceList[frame_meta->batch_id].width;
            gint frame_height = (gint)surface->surfaceList[frame_meta->batch_id].height;
            size_t frame_step = surface->surfaceList[frame_meta->batch_id].pitch;
    
            cv::Mat frame = cv::Mat(frame_height*3/2 , frame_width, CV_8UC1, src_data, frame_step);
            cv::Mat src_mat_BGRA;
            cv::cvtColor(frame, src_mat_BGRA, CV_YUV2BGR_NV12);
            char filename[200];
            printf("frame number:%d\n", frame_num);
            sprintf(filename,"./images/file_%dx%d_%d_%.5d.jpg",frame_width,frame_height, frame_meta->source_id, frame_num);
            frame_num++;
            cv::imwrite(filename, src_mat_BGRA);
            free(src_data);
            gst_buffer_unmap (buf, &in_map_info);
        }
        return GST_PAD_PROBE_OK;
    }
    

    相关文章

      网友评论

          本文标题:deepstream6.0 保存图片

          本文链接:https://www.haomeiwen.com/subject/kvhvfdtx.html