您好,欢迎来到年旅网。
搜索
您的当前位置:首页NvBufSurface

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;
        }
    }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务