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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在Apollo代码中链接NvBufSurfTransformAsync动态库需要进行以下步骤: 1. 在BUILD.bazel文件中添加动态库链接规则,例如: ``` cc_binary( name = "my_binary", srcs = ["my_binary.cc"], deps = [ "//path/to/nvbufsurftransformasync:libnvbufsurftransformasync.so", # other dependencies ], linkopts = [ "-lnvbufsurftransformasync", # other linker flags ], ) ``` 在这个例子中,`//path/to/nvbufsurftransformasync:libnvbufsurftransformasync.so` 是NvBufSurfTransformAsync动态库的Bazel依赖项。在 `linkopts` 中,使用 `-l` 标志添加库名称。这样,Bazel将自动在链接时查找该库并将其链接到生成的目标二进制文件中。 2. 如果NvBufSurfTransformAsync动态库没有被正确安装,需要将其添加到`LD_LIBRARY_PATH`环境变量中,例如: ``` export LD_LIBRARY_PATH=/path/to/nvbufsurftransformasync:$LD_LIBRARY_PATH ``` 这将使操作系统能够在运行二进制文件时查找并加载动态库。 3. 在代码中使用NvBufSurfTransformAsync动态库中的函数,例如: ``` #include <nvbufsurftransform.h> ... NvBufSurface *input_surf = ...; NvBufSurface *output_surf = ...; NvBufSurfTransform_Error err; err = NvBufSurfTransform(input_surf, output_surf, ...); if (err != NvBufSurfTransform_Error_Success) { // handle error } ... ``` 在这个例子中,`NvBufSurfTransform` 是NvBufSurfTransformAsync动态库中的函数,它可以将输入NvBufSurface转换为输出NvBufSurface。在代码中使用该函数时,需要包含 `nvbufsurftransform.h` 头文件并检查函数调用是否成功。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

山西茄子

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

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

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

打赏作者

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

抵扣说明:

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

余额充值