NVIDIA DeepStream SDK API Reference

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