NvBufSurface

/**
 * Holds information about a single buffer in a batch.       batch的之一。
 */
typedef struct NvBufSurfaceParams {
  /** Holds the width of the buffer. */
  uint32_t width;
  /** Holds the height of the buffer. */
  uint32_t height;
  /** Holds the pitch of the buffer. */
  uint32_t pitch;
  /** Holds the color format of the buffer. */
  NvBufSurfaceColorFormat colorFormat;
  /** Holds BL or PL. For dGPU, only PL is valid. */
  NvBufSurfaceLayout layout;
  /** Holds a DMABUF FD. Valid only for \ref NVBUF_MEM_SURFACE_ARRAY and
   \ref NVBUF_MEM_HANDLE type memory. */
  uint64_t bufferDesc;
  /** Holds the amount of allocated memory. */
  uint32_t dataSize;
  /** Holds a pointer to allocated memory. Not valid for
   \ref NVBUF_MEM_SURFACE_ARRAY or \ref NVBUF_MEM_HANDLE. */
  void * dataPtr;
  /** Holds planewise information (width, height, pitch, offset, etc.). */
  NvBufSurfacePlaneParams planeParams;
  /** Holds pointers to mapped buffers. Initialized to NULL
   when the structure is created. */
  NvBufSurfaceMappedAddr mappedAddr;

  void * _reserved[STRUCTURE_PADDING];
} NvBufSurfaceParams;


/**
 * Holds information about batched buffers.     代表一组buffer。
 */
typedef struct NvBufSurface {
  /** Holds a GPU ID. Valid only for a multi-GPU system. */
  uint32_t gpuId;
  /** Holds the batch size. */
  uint32_t batchSize;
  /** Holds the number valid and filled buffers. Initialized to zero when
   an instance of the structure is created. */
  uint32_t numFilled;
  /** Holds an "is contiguous" flag. If set, memory allocated for the batch
   is contiguous. */
  bool isContiguous;
  /** Holds type of memory for buffers in the batch. */
  NvBufSurfaceMemType memType;
  /** Holds a pointer to an array of batched buffers. */
  NvBufSurfaceParams *surfaceList;

  void * _reserved[STRUCTURE_PADDING];
} NvBufSurface;


怎么从GstBuffer得到NvBufSurface
static GstFlowReturn
gst_nvdspreprocess_submit_input_buffer (GstBaseTransform * btrans,
    gboolean discont, GstBuffer * inbuf)
{
......
  GstMapInfo in_map_info;
  NvBufSurface *in_surf;
  /* Map the buffer contents and get the pointer to NvBufSurface. */
  if (!gst_buffer_map (inbuf, &in_map_info, GST_MAP_READ)) {
    GST_ELEMENT_ERROR (nvdspreprocess, STREAM, FAILED,
        ("%s:gst buffer map to get pointer to NvBufSurface failed", __func__), (NULL));
    return GST_FLOW_ERROR;
  }
  in_surf = (NvBufSurface *) in_map_info.data;
......
}

NvBufSurfTransform
NvBufSurfTransform_Error NvBufSurfTransform (NvBufSurface *src, NvBufSurface *dst,
    NvBufSurfTransformParams *transform_params);
可以看到NvBufSurfTransform以NvBufSurface为参数进行并行变换,NvBufSurfTransformParams是变换参数,包括旋转,缩放等。

以dgpu,输入源为RGB为例,怎么用opencv保存NvBufSurface 的图片?

  char* src_data = NULL;
    for (uint32_t i = 0; i < frameCount; ++i) {
        src_data = (char*) malloc(surface->surfaceList[i].dataSize);
        cudaMemcpy((void*)src_data,
                (void*)surface->surfaceList[i].dataPtr,
                surface->surfaceList[i].dataSize,
                cudaMemcpyDeviceToHost);
    int frame_width = (int)surface->surfaceList[i].width;
    int frame_height = (int)surface->surfaceList[i].height;
    int frame_step = surface->surfaceList[i].pitch;
            
    cv::Mat frame = cv::Mat(frame_height, frame_width, CV_8UC3, src_data, frame_step);
    cv::Mat out_mat = cv::Mat (cv::Size(frame_width, frame_height), CV_8UC3);
    cv::cvtColor(frame, out_mat, COLOR_RGB2BGR);
    static int n = 0;
    int id = uniqueId();
    std::string outName =std::to_string(id) +  "-" + std::to_string(n++) + ".jpg";
    //if(id != 1)   //select gie id.
    cv::imwrite(outName, out_mat);
 
        if(src_data != NULL) {
            free(src_data);
            src_data = NULL;
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山西茄子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值