Create nvosd

This commit is contained in:
Barzan Hayati 2025-06-30 20:03:38 +00:00
parent 638177c8d1
commit b1a7ca5dfa
5 changed files with 41 additions and 1 deletions

View File

@ -53,10 +53,11 @@ include_directories(${PROJECT_SOURCE_DIR}/source_bin.hpp)
include_directories(${PROJECT_SOURCE_DIR}/gstds_example_manager.hpp)
include_directories(${PROJECT_SOURCE_DIR}/tiler_manager.hpp)
include_directories(${PROJECT_SOURCE_DIR}/nv_video_convert_manager.hpp)
include_directories(${PROJECT_SOURCE_DIR}/nv_osd_manager.hpp)
set(SOURCES src/main.cpp src/camera_manager.cpp src/pipeline_manager.cpp src/streammux_manager.cpp src/source_bin.cpp src/gstds_example_manager.cpp src/tiler_manager.cpp
src/nv_video_convert_manager.cpp)
src/nv_video_convert_manager.cpp src/nv_osd_manager.cpp)
# Create the executable
add_executable(${PROJECT_NAME} ${SOURCES})

26
src/nv_osd_manager.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "nv_osd_manager.hpp"
#define SET_GPU_ID(object, gpu_id) \
g_object_set(G_OBJECT(object), "gpu-id", gpu_id, NULL);
#define GPU_ID 0
#define OSD_PROCESS_MODE \
1 // use GPU to draw rectangles, keypoints and text on frame if
// OSD_PROCESS_MODE set to 1
#define OSD_DISPLAY_TEXT 1
NvOsdManager::NvOsdManager() {}
bool NvOsdManager::create_nv_osd() {
/* Create OSD to draw on the converted RGBA buffer */
nvosd = gst_element_factory_make("nvdsosd", "nv-onscreendisplay");
/* Finally render the osd output */
g_object_set(G_OBJECT(nvosd), "process-mode", OSD_PROCESS_MODE,
"display-text", OSD_DISPLAY_TEXT, NULL);
SET_GPU_ID(nvosd, GPU_ID);
if (!nvosd) {
g_printerr("Unable to create NVOSD. Exiting.\n");
return false;
}
return true;
}

10
src/nv_osd_manager.hpp Normal file
View File

@ -0,0 +1,10 @@
#include <gst/gst.h>
class NvOsdManager {
private:
public:
GstElement *nvosd = NULL;
NvOsdManager();
bool create_nv_osd();
~NvOsdManager();
};

View File

@ -62,6 +62,7 @@ bool PipelineManager::create_pipeline_elements(int num_sources,
streammux_manager->MUXER_OUTPUT_WIDTH,
streammux_manager->MUXER_OUTPUT_HEIGHT);
nv_video_convert_manager->create_nv_video_convert();
nv_osd_manager->create_nv_osd();
return true;
}

View File

@ -3,6 +3,7 @@
#include "cuda_runtime_api.h"
#include "gstds_example_manager.hpp"
#include "nv_osd_manager.hpp"
#include "nv_video_convert_manager.hpp"
#include "source_bin.hpp"
#include "streammux_manager.hpp"
@ -19,6 +20,7 @@ class PipelineManager {
TilerManager *tiler_manager = new TilerManager();
NvVideoConvertManager *nv_video_convert_manager =
new NvVideoConvertManager();
NvOsdManager *nv_osd_manager = new NvOsdManager();
public:
int current_device = -1;