NVIDIA DeepStream SDK API Reference

8.0 Release
cuosd.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
13 #ifndef CUOSD_H
14 #define CUOSD_H
15 
16 typedef struct{} cuOSDContext;
18 
19 enum class cuOSDClockFormat : int {
20  None = 0,
21  YYMMDD_HHMMSS = 1,
22  YYMMDD = 2,
23  HHMMSS = 3
24 };
25 
26 enum class cuOSDImageFormat : int {
27  None = 0,
28  RGB = 1,
29  RGBA = 2,
30  BlockLinearNV12 = 3,
31  PitchLinearNV12 = 4
32 };
33 
34 enum class cuOSDTextBackend : int {
35  None = 0,
36  PangoCairo = 1,
37  StbTrueType = 2
38 };
39 
40 typedef struct _cuOSDColor {
41  unsigned char r;
42  unsigned char g;
43  unsigned char b;
44  unsigned char a;
45 } cuOSDColor;
46 
47 // cuosd_context_create: support online generate text bitmap with required font.
49 
50 // set context text rendering backend
51 void cuosd_set_text_backend(cuOSDContext_t context, cuOSDTextBackend text_backend);
52 
53 // cuosd_context_destroy: deallocate all resource related to allocated cuOSD context
55 
56 // cuosd_measure_text: API to get tight width, height and upper offset from the given text's tight bounding box
58  cuOSDContext_t context, const char* utf8_text, int font_size, const char* font, int* width, int* height, int* yoffset);
59 
60 // cuosd_draw_text: draw utf8 text on given cuOSD context.
61 // x, y stands for left upper corner of the text's bounding box.
62 // bg_color stands for textbox background color in case alpha != 0
63 // Draw nothing if font_size <=0, font_size is scaled by 3 and clamped to 10 - 500 pixels by default
64 void cuosd_draw_text(
65  cuOSDContext_t context, const char* utf8_text,int font_size, const char* font, int x, int y, cuOSDColor border_color, cuOSDColor bg_color = {0, 0, 0, 0});
66 
67 // cuosd_draw_clock: draw clock element on given cuOSD context.
68 // x, y stands for left upper corner of the text's bounding box. 3 clock formats are supported:
69 // YYMMDD_HHMMSS, YYMMDD, HHMMSS
70 // Draw nothing if font_size <=0, font_size is scaled by 3 and clamped to 10 - 500 pixels by default
71 void cuosd_draw_clock(
72  cuOSDContext_t context, cuOSDClockFormat format, long time, int font_size, const char* font, int x, int y, cuOSDColor border_color, cuOSDColor bg_color = {0, 0, 0, 0});
73 
74 // cuosd_draw_line: draw line element on given cuOSD context.
75 // x0, y0 stands for start point coordinate of the line, and x1, y1 stands for end point coordinate of the line.
76 void cuosd_draw_line(
77  cuOSDContext_t context, int x0, int y0, int x1, int y1, int thickness, cuOSDColor color, bool interpolation = true);
78 
79 // cuosd_draw_arrow: draw arrow element on given cuOSD context.
80 // x0, y0 stands for start point coordinate of the arrow, and x1, y1 stands for end point coordinate of the arrow.
81 void cuosd_draw_arrow(
82  cuOSDContext_t context, int x0, int y0, int x1, int y1, int arrow_size, int thickness, cuOSDColor color, bool interpolation = false);
83 
84 // cuosd_draw_point: draw point element on given cuOSD context.
85 // cx, cy stands for center point coordinate of the point.
86 void cuosd_draw_point(
87  cuOSDContext_t context, int cx, int cy, int radius, cuOSDColor color);
88 
89 // cuosd_draw_circle: draw circle element on given cuOSD context.
90 // cx, cy stands for center point coordinate of the circle.
91 // thickness stands for border width when thickness > 0; stands for filled mode when thickness = -1.
92 // bg_color stands for inner color inside hollow circle in case alpha != 0
94  cuOSDContext_t context, int cx, int cy, int radius, int thickness, cuOSDColor border_color, cuOSDColor bg_color = {0, 0, 0, 0});
95 
96 // cuosd_draw_rectangle: draw rectangle element on given cuOSD context.
97 // thickness stands for border width when thickness > 0; stands for filled mode when thickness = -1.
98 // bg_color stands for inner color inside hollow rectangle in case alpha != 0
100  cuOSDContext_t context, int left, int top, int right, int bottom, int thickness, cuOSDColor border_color, cuOSDColor bg_color = {0, 0, 0, 0});
101 
102 // cuosd_draw_boxblur: Mean filtering in the region of interest
103 // The region of interest is first scaled to 32x32, filtered, and then scaled to the region of interest by nearest neighbor interpolation
104 // It is executed by a separate kernel function that is independent from the other drawing functions
105 void cuosd_draw_boxblur(
106  cuOSDContext_t context, int left, int top, int right, int bottom, int kernel_size = 7);
107 
108 // cuosd_draw_rotationbox: draw rotated rectangle element on given cuOSD context.
109 // yaw: rotation angle from y-axis, clockwise +, unit in rad.
111  cuOSDContext_t _context, int cx, int cy, int width, int height, float yaw, int thickness, cuOSDColor border_color, bool interpolation = false, cuOSDColor bg_color = {0, 0, 0, 0});
112 
113 // cuosd_draw_segmentmask: draw segmentation mask on given cuOSD context.
114 // d_seg: device pointer of segmentation mask, alpha in seg_color is ignored.
115 // thickness should > 0 for drawing border, threshold: Threshold for binarization
116 // 1. resize mask rect to object rect of given left, top, right, bottom.
117 // 2. set the alpha to 127 if mask value > threshold, else alpha = 0.
119  cuOSDContext_t context, int left, int top, int right, int bottom, int thickness, float* d_seg, int seg_width, int seg_height, float seg_threshold, cuOSDColor border_color, cuOSDColor seg_color = {0, 0, 0, 0});
120 
121 // cuosd_draw_polyline: draw polyline element on given cuOSD context.
122 // h_pts: host point of polyline points in { int x, int y } data format.
123 // d_pts: device point of polyline points, shall not be nullptr if fill_color.a != 0.
124 // n_pts: number of polyline points, thickness: polyline thickness.
125 // is_closed: if the end point shall be connected to start point.
126 // border_color: polyline color, fill_color: polyfill color.
128  cuOSDContext_t context, int* h_pts, int* d_pts, int n_pts, int thickness, bool is_closed, cuOSDColor border_color, bool interpolation = true, cuOSDColor fill_color = {0, 0, 0, 0});
129 
130 // cuosd_draw_rgba_source: draw color from rgba source image on given cuOSD context.
131 // 1. resize incoming rgba source rect to target rect of given left, top, right, bottom.
132 // 2. blend incoming rgba src on target image rect in bilinear interpolation manner.
134  cuOSDContext_t _context, int left, int top, int right, int bottom, void* d_src, int src_width, int src_stride, int src_height);
135 
136 // cuosd_draw_nv12_source: draw color from nv12 source image on given cuOSD context.
137 // 1. resize incoming nv12 source rect to target rect of given left, top, right, bottom.
138 // 2. blend incoming nv12 src on target image rect in bilinear interpolation manner.
139 // note: use unified alpha and can support both PL and BL nv12 format.
141  cuOSDContext_t context, int left, int top, int right, int bottom, void* d_src0, void* d_src1, int src_width, int src_stride, int src_height, unsigned char alpha = 127, bool block_linear= false);
142 
143 // cuosd_apply: calculate bounding box of all elements and transfer drawing commands to GPU.
144 // If format is RGBA, data0 is RGBA buffer, and data1 must be nullptr.
145 // If format is BlockLinearNV12, data0 and data1 is cudaSurfaceObject_t for Luma(Y) plane and Chroma(UV) plane
146 // If format is PitchLinearNV12, data0 is Luma(Y) plane buffer, and data1 is Chroma(UV) plane buffer
147 void cuosd_apply(
148  cuOSDContext_t context, void* data0, void* data1, int width, int stride, int height, cuOSDImageFormat format, void* stream = nullptr, bool launch_and_clear = true);
149 
150 // clear all pushed commands
151 void cuosd_clear(cuOSDContext_t context);
152 
153 // cuosd_launch: launch drawing kernel in async manner.
154 // If format is RGBA, data0 is RGBA buffer, and data1 must be nullptr.
155 // If format is BlockLinearNV12, data0 and data1 is cudaSurfaceObject_t for Luma(Y) plane and Chroma(UV) plane
156 // If format is PitchLinearNV12, data0 is Luma(Y) plane buffer, and data1 is Chroma(UV) plane buffer
157 void cuosd_launch(
158  cuOSDContext_t context, void* data0, void* data1, int width, int stride, int height, cuOSDImageFormat format, void* stream = nullptr);
159 
160 #endif // CUOSD_H
cuOSDImageFormat
cuOSDImageFormat
Definition: cuosd.h:26
cuosd_draw_polyline
void cuosd_draw_polyline(cuOSDContext_t context, int *h_pts, int *d_pts, int n_pts, int thickness, bool is_closed, cuOSDColor border_color, bool interpolation=true, cuOSDColor fill_color={0, 0, 0, 0})
cuOSDClockFormat::None
@ None
cuosd_draw_rgba_source
void cuosd_draw_rgba_source(cuOSDContext_t _context, int left, int top, int right, int bottom, void *d_src, int src_width, int src_stride, int src_height)
cuOSDTextBackend::PangoCairo
@ PangoCairo
cuosd_draw_circle
void cuosd_draw_circle(cuOSDContext_t context, int cx, int cy, int radius, int thickness, cuOSDColor border_color, cuOSDColor bg_color={0, 0, 0, 0})
cuosd_draw_rectangle
void cuosd_draw_rectangle(cuOSDContext_t context, int left, int top, int right, int bottom, int thickness, cuOSDColor border_color, cuOSDColor bg_color={0, 0, 0, 0})
cuosd_draw_line
void cuosd_draw_line(cuOSDContext_t context, int x0, int y0, int x1, int y1, int thickness, cuOSDColor color, bool interpolation=true)
_cuOSDColor::r
unsigned char r
Definition: cuosd.h:41
cuosd_set_text_backend
void cuosd_set_text_backend(cuOSDContext_t context, cuOSDTextBackend text_backend)
cuOSDTextBackend
cuOSDTextBackend
Definition: cuosd.h:34
cuosd_draw_arrow
void cuosd_draw_arrow(cuOSDContext_t context, int x0, int y0, int x1, int y1, int arrow_size, int thickness, cuOSDColor color, bool interpolation=false)
_cuOSDColor::g
unsigned char g
Definition: cuosd.h:42
cuOSDTextBackend::StbTrueType
@ StbTrueType
cuOSDClockFormat::YYMMDD_HHMMSS
@ YYMMDD_HHMMSS
_cuOSDColor
Definition: cuosd.h:40
cuOSDContext
Definition: cuosd.h:16
cuOSDImageFormat::PitchLinearNV12
@ PitchLinearNV12
_cuOSDColor::a
unsigned char a
Definition: cuosd.h:44
cuOSDClockFormat::HHMMSS
@ HHMMSS
_cuOSDColor::b
unsigned char b
Definition: cuosd.h:43
cuOSDColor
struct _cuOSDColor cuOSDColor
cuosd_draw_nv12_source
void cuosd_draw_nv12_source(cuOSDContext_t context, int left, int top, int right, int bottom, void *d_src0, void *d_src1, int src_width, int src_stride, int src_height, unsigned char alpha=127, bool block_linear=false)
cuosd_measure_text
void cuosd_measure_text(cuOSDContext_t context, const char *utf8_text, int font_size, const char *font, int *width, int *height, int *yoffset)
cuOSDClockFormat
cuOSDClockFormat
Definition: cuosd.h:19
cuosd_draw_point
void cuosd_draw_point(cuOSDContext_t context, int cx, int cy, int radius, cuOSDColor color)
cuosd_draw_clock
void cuosd_draw_clock(cuOSDContext_t context, cuOSDClockFormat format, long time, int font_size, const char *font, int x, int y, cuOSDColor border_color, cuOSDColor bg_color={0, 0, 0, 0})
cuosd_draw_boxblur
void cuosd_draw_boxblur(cuOSDContext_t context, int left, int top, int right, int bottom, int kernel_size=7)
cuosd_draw_rotationbox
void cuosd_draw_rotationbox(cuOSDContext_t _context, int cx, int cy, int width, int height, float yaw, int thickness, cuOSDColor border_color, bool interpolation=false, cuOSDColor bg_color={0, 0, 0, 0})
cuosd_clear
void cuosd_clear(cuOSDContext_t context)
cuOSDImageFormat::RGBA
@ RGBA
cuosd_draw_text
void cuosd_draw_text(cuOSDContext_t context, const char *utf8_text, int font_size, const char *font, int x, int y, cuOSDColor border_color, cuOSDColor bg_color={0, 0, 0, 0})
cuosd_context_create
cuOSDContext_t cuosd_context_create()
cuOSDImageFormat::RGB
@ RGB
cuosd_apply
void cuosd_apply(cuOSDContext_t context, void *data0, void *data1, int width, int stride, int height, cuOSDImageFormat format, void *stream=nullptr, bool launch_and_clear=true)
cuOSDImageFormat::BlockLinearNV12
@ BlockLinearNV12
cuOSDContext_t
cuOSDContext * cuOSDContext_t
Definition: cuosd.h:17
cuosd_draw_segmentmask
void cuosd_draw_segmentmask(cuOSDContext_t context, int left, int top, int right, int bottom, int thickness, float *d_seg, int seg_width, int seg_height, float seg_threshold, cuOSDColor border_color, cuOSDColor seg_color={0, 0, 0, 0})
cuOSDClockFormat::YYMMDD
@ YYMMDD
cuosd_launch
void cuosd_launch(cuOSDContext_t context, void *data0, void *data1, int width, int stride, int height, cuOSDImageFormat format, void *stream=nullptr)
cuosd_context_destroy
void cuosd_context_destroy(cuOSDContext_t context)
ds3d::v2xinfer::format
static std::string format(const char *fmt,...)
Definition: sources/libs/ds3d/inference_custom_lib/ds3d_v2x_infer_custom_preprocess/tensor.hpp:26