Commit d3b1846f authored by wufan3's avatar wufan3
Browse files

Push sugon_apps

parent a15daae3
################################################################################
# Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
################################################################################
infer_config {
unique_id: 5
gpu_ids: [0]
max_batch_size: 1
backend {
triton {
model_name: "Segmentation_Semantic"
version: 1
model_repo {
root: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/triton_model_repo_NV"
strict_model_config: true
#tf_gpu_memory_fraction: 0.0
#tf_disable_soft_placement: 0
backend_dir: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/backends"
#log_level: 3
}
}
inputs {
name: "input"
dims: [ 3, 224, 224 ]
}
}
preprocess {
network_format: IMAGE_FORMAT_RGB
tensor_order: TENSOR_ORDER_LINEAR
maintain_aspect_ratio: 0
frame_scaling_hw: FRAME_SCALING_HW_DEFAULT
frame_scaling_filter: 1
normalize {
scale_factor: 0.00392156862745098
channel_offsets: [0.485, 0.456, 0.406]
}
}
postprocess {
segmentation {
threshold:0
num_segmentation_classes: 21
}
}
extra {
copy_input_to_host_buffers: false
output_buffer_pool_size: 2
}
}
input_control {
process_mode: PROCESS_MODE_FULL_FRAME
interval: 0
}
#include <gst/gst.h>
#include <glib.h>
/* 宏定义:分辨率、批处理超时等参数 */
#define MUXER_OUTPUT_WIDTH 1280
#define MUXER_OUTPUT_HEIGHT 720
#define MUXER_BATCH_TIMEOUT_USEC 4000000
/* 消息处理函数:处理管道错误和EOS事件 */
static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data) {
GMainLoop *loop = (GMainLoop *)data;
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
g_print("End of stream\n");
g_main_loop_quit(loop);
break;
case GST_MESSAGE_ERROR: {
gchar *debug;
GError *err;
gst_message_parse_error(msg, &err, &debug);
g_print("Error: %s\n", (gchar *)err);
g_free(err);
g_free(debug);
g_main_loop_quit(loop);
break;
}
default:
break;
}
return TRUE;
}
int main(int argc, char *argv[]) {
GMainLoop *loop = NULL;
GstElement *pipeline = NULL, *streammux = NULL, *pgie = NULL;
GstElement *sink = NULL, *osd = NULL, *tracker = NULL;
GstBus *bus = NULL;
guint bus_watch_id;
gint i;
/* 检查输入参数(需提供2个视频文件路径) */
if (argc != 3) {
g_printerr("Usage: %s <video1.h264> <video2.h264>\n", argv[0]);
return -1;
}
/* 初始化GStreamer */
gst_init(&argc, &argv);
loop = g_main_loop_new(NULL, FALSE);
/* 创建主管道 */
pipeline = gst_pipeline_new("multi-decode-inference-pipeline");
/* 创建nvstreammux(流合并器) */
streammux = gst_element_factory_make("nvstreammux", "streammux");
if (!streammux) {
g_printerr("Failed to create streammux\n");
return -1;
}
/* 配置streammux:批处理分辨率、超时时间 */
// g_object_set(G_OBJECT(streammux),
// "batched-width", MUXER_OUTPUT_WIDTH,
// "batched-height", MUXER_OUTPUT_HEIGHT,
// "batched-push-timeout", MUXER_BATCH_TIMEOUT_USEC,
// "live-source", FALSE, // 非实时源(文件)
// NULL);
g_object_set (G_OBJECT (streammux), "batch-size", 2, NULL);
/* 创建nvinferserver(推理插件) */
pgie = gst_element_factory_make("nvinferserver", "primary-inference");
if (!pgie) {
g_printerr("Failed to create nvinferserver\n");
return -1;
}
g_object_set(G_OBJECT(pgie), "config-file-path", "dstest1_pgie_nvinferserver_config.txt", NULL);
/* 创建其他辅助插件:跟踪器、OSD、渲染器 */
// tracker = gst_element_factory_make("nvtracker", "tracker");
// osd = gst_element_factory_make("nvdsosd", "onscreendisplay");
sink = gst_element_factory_make("fakesink", "fakesink"); // 3D渲染sink(或用nveglglessink)
if (!sink) {
g_printerr("Failed to create auxiliary elements\n");
return -1;
}
/* 将所有元素添加到管道 */
gst_bin_add_many(GST_BIN(pipeline), streammux, pgie, sink, NULL);
/* 链接推理部分:streammux → pgie → tracker → osd → sink */
if (!gst_element_link_many(streammux, pgie, sink, NULL)) {
g_printerr("Failed to link inference elements\n");
return -1;
}
/* 为每路视频流创建解码分支,并连接到streammux的sink端口 */
for (i = 0; i < 2; i++) {
GstElement *src, *h264parser, *decoder;
gchar *src_name, *parser_name, *decoder_name, *sink_pad_name;
GstPad *sinkpad, *srcpad;
/* 创建元素名称(区分多路流) */
src_name = g_strdup_printf("file-source-%d", i);
parser_name = g_strdup_printf("h264-parser-%d", i);
decoder_name = g_strdup_printf("hy-decoder-%d", i);
/* 创建解码分支元素 */
src = gst_element_factory_make("filesrc", src_name);
h264parser = gst_element_factory_make("h264parse", parser_name);
decoder = gst_element_factory_make("hyh264dec", decoder_name); // NVIDIA硬件解码器
if (!src || !h264parser || !decoder) {
g_printerr("Failed to create elements for stream %d\n", i);
return -1;
}
/* 配置文件源路径 */
g_object_set(G_OBJECT(src), "location", argv[i+1], NULL);
/* 将解码分支元素添加到管道 */
gst_bin_add_many(GST_BIN(pipeline), src, h264parser, decoder,NULL);
/* 链接解码分支:src → parser → decoder */
if (!gst_element_link_many(src, h264parser, decoder,NULL)) {
g_printerr("Failed to link elements for stream %d\n", i);
return -1;
}
/* 将解码分支的输出连接到streammux的sink端口(sink_0, sink_1...) */
srcpad = gst_element_get_static_pad(decoder, "src");
sink_pad_name = g_strdup_printf("sink_%d", i);
sinkpad = gst_element_request_pad_simple(streammux, sink_pad_name);
if (gst_pad_link(srcpad, sinkpad) != GST_PAD_LINK_OK) {
g_printerr("Failed to link stream %d to streammux\n", i);
return -1;
}
/* 释放资源 */
gst_object_unref(srcpad);
gst_object_unref(sinkpad);
g_free(src_name);
g_free(parser_name);
g_free(decoder_name);
g_free(sink_pad_name);
}
/* 启动管道消息循环 */
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
bus_watch_id = gst_bus_add_watch(bus, bus_call, loop);
gst_object_unref(bus);
/* 启动管道 */
gst_element_set_state(pipeline, GST_STATE_PLAYING);
g_print("Running pipeline...\n");
g_main_loop_run(loop);
/* 清理资源 */
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(pipeline));
g_source_remove(bus_watch_id);
g_main_loop_unref(loop);
return 0;
}
################################################################################
# SPDX-FileCopyrightText: Copyright (c) 2018-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
################################################################################
infer_config {
unique_id: 1
gpu_ids: [0]
max_batch_size: 30
backend {
inputs: [ {
name: "input_1:0"
}]
outputs: [
{name: "output_cov/Sigmoid:0"},
{name: "output_bbox/BiasAdd:0"}
]
triton {
model_name: "Primary_Detector"
version: 1
model_repo {
root: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/triton_model_repo_NV"
strict_model_config: true
backend_dir: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/backends"
#log_level: 3
}
}
}
preprocess {
network_format: MEDIA_FORMAT_NONE
tensor_order: TENSOR_ORDER_LINEAR
tensor_name: "input_1:0"
maintain_aspect_ratio: 0
frame_scaling_hw: FRAME_SCALING_HW_DEFAULT
frame_scaling_filter: 1
normalize {
scale_factor: 0.00392156862745098
channel_offsets: [0, 0, 0]
}
}
postprocess {
labelfile_path: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/models/Primary_Detector_NV/labels.txt"
detection {
num_detected_classes: 4
per_class_params {
key: 0
value { pre_threshold: 0.4 }
}
nms {
confidence_threshold:0.2
topk:20
iou_threshold:0.5
}
}
}
extra {
copy_input_to_host_buffers: false
output_buffer_pool_size: 2
}
}
input_control {
process_mode: PROCESS_MODE_FULL_FRAME
operate_on_gie_id: -1
interval: 0
}
/*
gcc deepstream_test1_app.c $(pkg-config --cflags --libs gstreamer-1.0) -I../../../includes -L../../../../sugon_lib/ -lnvds_yml_parser -o deepstream_test1_app
./deepstream_test1_app /workspace/shared_docker/video/cr7_1920x1080.h264
* SPDX-FileCopyrightText: Copyright (c) 2018-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include <gst/gst.h>
#include <glib.h>
#include <stdio.h>
#include <cuda_runtime_api.h>
#include "gstnvdsmeta.h"
#include "nvds_yml_parser.h"
#define MAX_DISPLAY_LEN 64
#define PGIE_CLASS_ID_VEHICLE 0
#define PGIE_CLASS_ID_PERSON 2
/* The muxer output resolution must be set if the input streams will be of
* different resolution. The muxer will scale all the input frames to this
* resolution. */
#define MUXER_OUTPUT_WIDTH 1920
#define MUXER_OUTPUT_HEIGHT 1080
/* Muxer batch formation timeout, for e.g. 40 millisec. Should ideally be set
* based on the fastest source's framerate. */
#define MUXER_BATCH_TIMEOUT_USEC 40000
/* Check for parsing error. */
#define RETURN_ON_PARSER_ERROR(parse_expr) \
if (NVDS_YAML_PARSER_SUCCESS != parse_expr) { \
g_printerr("Error in parsing configuration file.\n"); \
return -1; \
}
gint frame_number = 0;
gchar pgie_classes_str[4][32] = { "Vehicle", "TwoWheeler", "Person",
"Roadsign"
};
/* osd_sink_pad_buffer_probe will extract metadata received on OSD sink pad
* and update params for drawing rectangle, object information etc. */
// static GstPadProbeReturn
// osd_sink_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
// gpointer u_data)
// {
// GstBuffer *buf = (GstBuffer *) info->data;
// guint num_rects = 0;
// NvDsObjectMeta *obj_meta = NULL;
// guint vehicle_count = 0;
// guint person_count = 0;
// NvDsMetaList * l_frame = NULL;
// NvDsMetaList * l_obj = NULL;
// NvDsDisplayMeta *display_meta = NULL;
// NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);
// for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
// l_frame = l_frame->next) {
// NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
// int offset = 0;
// for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;
// l_obj = l_obj->next) {
// obj_meta = (NvDsObjectMeta *) (l_obj->data);
// if (obj_meta->class_id == PGIE_CLASS_ID_VEHICLE) {
// vehicle_count++;
// num_rects++;
// }
// if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) {
// person_count++;
// num_rects++;
// }
// }
// display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
// NvOSD_TextParams *txt_params = &display_meta->text_params[0];
// display_meta->num_labels = 1;
// txt_params->display_text = g_malloc0 (MAX_DISPLAY_LEN);
// offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN, "Person = %d ", person_count);
// offset = snprintf(txt_params->display_text + offset , MAX_DISPLAY_LEN, "Vehicle = %d ", vehicle_count);
// /* Now set the offsets where the string should appear */
// txt_params->x_offset = 10;
// txt_params->y_offset = 12;
// /* Font , font-color and font-size */
// txt_params->font_params.font_name = "Serif";
// txt_params->font_params.font_size = 10;
// txt_params->font_params.font_color.red = 1.0;
// txt_params->font_params.font_color.green = 1.0;
// txt_params->font_params.font_color.blue = 1.0;
// txt_params->font_params.font_color.alpha = 1.0;
// /* Text background color */
// txt_params->set_bg_clr = 1;
// txt_params->text_bg_clr.red = 0.0;
// txt_params->text_bg_clr.green = 0.0;
// txt_params->text_bg_clr.blue = 0.0;
// txt_params->text_bg_clr.alpha = 1.0;
// nvds_add_display_meta_to_frame(frame_meta, display_meta);
// }
// g_print ("Frame Number = %d Number of objects = %d "
// "Vehicle Count = %d Person Count = %d\n",
// frame_number, num_rects, vehicle_count, person_count);
// frame_number++;
// return GST_PAD_PROBE_OK;
// }
static gboolean
bus_call (GstBus * bus, GstMessage * msg, gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
g_main_loop_quit (loop);
break;
case GST_MESSAGE_ERROR:{
gchar *debug = NULL;
GError *error = NULL;
gst_message_parse_error (msg, &error, &debug);
g_printerr ("ERROR from element %s: %s\n",
GST_OBJECT_NAME (msg->src), error->message);
if (debug)
g_printerr ("Error details: %s\n", debug);
g_free (debug);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
int
main (int argc, char *argv[])
{
GMainLoop *loop = NULL;
GstElement *pipeline = NULL, *source = NULL, *h264parser = NULL,
*decoder = NULL, *streammux = NULL, *sink = NULL, *pgie = NULL, *nvvidconv = NULL,
*nvosd = NULL;
GstBus *bus = NULL;
guint bus_watch_id;
GstPad *osd_sink_pad = NULL;
gboolean yaml_config = FALSE;
NvDsGieType pgie_type = NVDS_GIE_PLUGIN_INFER_SERVER;
// int current_device = -1;
// cudaGetDevice(&current_device);
// struct cudaDeviceProp prop;
// cudaGetDeviceProperties(&prop, current_device);
/* Check input arguments */
if (argc != 2) {
g_printerr ("Usage: %s <yml file>\n", argv[0]);
g_printerr ("OR: %s <H264 filename>\n", argv[0]);
return -1;
}
/* Standard GStreamer initialization */
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
/* Parse inference plugin type */
yaml_config = (g_str_has_suffix (argv[1], ".yml") ||
g_str_has_suffix (argv[1], ".yaml"));
if (yaml_config) {
RETURN_ON_PARSER_ERROR(nvds_parse_gie_type(&pgie_type, argv[1],
"primary-gie"));
}
/* Create gstreamer elements */
/* Create Pipeline element that will form a connection of other elements */
pipeline = gst_pipeline_new ("dstest1-pipeline");
/* Source element for reading from the file */
source = gst_element_factory_make ("filesrc", "file-source");
/* Since the data format in the input file is elementary h264 stream,
* we need a h264parser */
h264parser = gst_element_factory_make ("h264parse", "h264-parser");
/* Use nvdec_h264 for hardware accelerated decode on GPU */
decoder = gst_element_factory_make ("hyh264dec", "hy-decoder");
/* Create nvstreammux instance to form batches from one or more sources. */
streammux = gst_element_factory_make ("nvstreammux", "stream-muxer");
if (!pipeline || !streammux) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* Use nvinfer or nvinferserver to run inferencing on decoder's output,
* behaviour of inferencing is set through config file */
if (pgie_type == NVDS_GIE_PLUGIN_INFER_SERVER) {
pgie = gst_element_factory_make ("nvinferserver", "primary-nvinference-engine");
} else {
pgie = gst_element_factory_make ("nvinfer", "primary-nvinference-engine");
}
sink = gst_element_factory_make ("fakesink", "fakesink");
/* Use convertor to convert from NV12 to RGBA as required by nvosd */
// nvvidconv = gst_element_factory_make ("nvvideoconvert", "nvvideo-converter");
/* Create OSD to draw on the converted RGBA buffer */
// nvosd = gst_element_factory_make ("nvdsosd", "nv-onscreendisplay");
/* Finally render the osd output */
// if(prop.integrated) {
// sink = gst_element_factory_make("nv3dsink", "nv3d-sink");
// } else {
// #ifdef __aarch64__
// sink = gst_element_factory_make ("nv3dsink", "nvvideo-renderer");
// #else
// sink = gst_element_factory_make ("nveglglessink", "nvvideo-renderer");
// #endif
// }
if (!source || !h264parser || !decoder || !pgie || !sink) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* we set the input filename to the source element */
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
if (g_str_has_suffix (argv[1], ".h264")) {
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
g_object_set (G_OBJECT (streammux), "batch-size", 1, NULL);
// g_object_set (G_OBJECT (streammux), "width", MUXER_OUTPUT_WIDTH, "height",
// MUXER_OUTPUT_HEIGHT,
// "batched-push-timeout", MUXER_BATCH_TIMEOUT_USEC, NULL);
/* Set all the necessary properties of the nvinfer element,
* the necessary ones are : */
g_object_set (G_OBJECT (pgie),
"config-file-path", "dstest1_pgie_nvinferserver_config.txt", NULL); // 这个函数是 GObject 系统中的核心函数,主要用于设置 GObject 对象的属性值
}
if (yaml_config) {
RETURN_ON_PARSER_ERROR(nvds_parse_file_source(source, argv[1],"source"));
RETURN_ON_PARSER_ERROR(nvds_parse_streammux(streammux, argv[1],"streammux"));
/* Set all the necessary properties of the inference element */
RETURN_ON_PARSER_ERROR(nvds_parse_gie(pgie, argv[1], "primary-gie"));
}
/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
bus_watch_id = gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
/* Set up the pipeline */
/* we add all elements into the pipeline */
gst_bin_add_many (GST_BIN (pipeline),
source, h264parser, decoder, streammux, pgie, sink, NULL);
g_print ("Added elements to bin\n");
GstPad *sinkpad, *srcpad;
gchar pad_name_sink[16] = "sink_0";
gchar pad_name_src[16] = "src";
sinkpad = gst_element_request_pad_simple (streammux, pad_name_sink);
if (!sinkpad) {
g_printerr ("Streammux request sink pad failed. Exiting.\n");
return -1;
}
srcpad = gst_element_get_static_pad (decoder, pad_name_src);
if (!srcpad) {
g_printerr ("Decoder request src pad failed. Exiting.\n");
return -1;
}
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) {
g_printerr ("Failed to link decoder to stream muxer. Exiting.\n");
return -1;
}
gst_object_unref (sinkpad);
gst_object_unref (srcpad);
/* we link the elements together */
/* file-source -> h264-parser -> nvh264-decoder ->
* pgie -> nvvidconv -> nvosd -> video-renderer */
if (!gst_element_link_many (source, h264parser, decoder, NULL)) {
g_printerr ("Elements could not be linked: 1. Exiting.\n");
return -1;
}
if (!gst_element_link_many (streammux, pgie, sink, NULL)) {
g_printerr ("Elements could not be linked: 2. Exiting.\n");
return -1;
}
// /* Lets add probe to get informed of the meta data generated, we add probe to
// * the sink pad of the osd element, since by that time, the buffer would have
// * had got all the metadata. */
// osd_sink_pad = gst_element_get_static_pad (nvosd, "sink");
// if (!osd_sink_pad)
// g_print ("Unable to get sink pad\n");
// else
// gst_pad_add_probe (osd_sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
// osd_sink_pad_buffer_probe, NULL, NULL);
// gst_object_unref (osd_sink_pad);
/* Set the pipeline to "playing" state */
g_print ("Using file: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Wait till pipeline encounters an error or EOS */
g_print ("Running...\n");
g_main_loop_run (loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
g_source_remove (bus_watch_id);
g_main_loop_unref (loop);
return 0;
}
################################################################################
# SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
################################################################################
source:
location: ../../../../samples/streams/sample_720p.h264
streammux:
batch-size: 1
batched-push-timeout: 40000
width: 1920
height: 1080
# Inference using nvinfer:
# primary-gie:
# plugin-type: 0
# config-file-path: dstest1_pgie_config.yml
## Inference using nvinferserver:
primary-gie:
plugin-type: 1
config-file-path: dstest1_pgie_nvinferserver_config.txt
################################################################################
# SPDX-FileCopyrightText: Copyright (c) 2018-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
################################################################################
infer_config {
unique_id: 1
gpu_ids: [0]
max_batch_size: 1
backend {
inputs: [ {
name: "images"
}]
outputs: [
{name: "output"},
{name: "462"},
{name: "520"}
]
triton {
model_name: "Primary_Detector"
version: 1
model_repo {
root: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/triton_model_repo"
strict_model_config: true
backend_dir: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/backends"
}
}
}
preprocess {
network_format: MEDIA_FORMAT_NONE
tensor_order: TENSOR_ORDER_LINEAR
tensor_name: "images"
maintain_aspect_ratio: 0
frame_scaling_hw: FRAME_SCALING_HW_DEFAULT
frame_scaling_filter: 1
normalize {
scale_factor: 0.00392156862745098
channel_offsets: [0, 0, 0]
}
}
postprocess {
labelfile_path: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/models/Primary_Detector/labels.txt"
detection {
num_detected_classes: 80
per_class_params {
key: 0
value { pre_threshold: 0.4 }
}
nms {
confidence_threshold:0.2
topk:20
iou_threshold:0.5
}
}
}
extra {
copy_input_to_host_buffers: false
output_buffer_pool_size: 2
}
}
input_control {
process_mode: PROCESS_MODE_FULL_FRAME
operate_on_gie_id: -1
interval: 0
}
/*
gcc deepstream_test1_app.c $(pkg-config --cflags --libs gstreamer-1.0) -I../../../includes -L../../../../sugon_lib/ -lnvds_yml_parser -o deepstream_test1_app
./deepstream_test1_app /workspace/shared_docker/video/cr7_1920x1080.h264
* SPDX-FileCopyrightText: Copyright (c) 2018-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#include <gst/gst.h>
#include <glib.h>
#include <stdio.h>
#include <cuda_runtime_api.h>
#include "gstnvdsmeta.h"
#include "nvds_yml_parser.h"
#define MAX_DISPLAY_LEN 64
#define PGIE_CLASS_ID_VEHICLE 0
#define PGIE_CLASS_ID_PERSON 2
/* The muxer output resolution must be set if the input streams will be of
* different resolution. The muxer will scale all the input frames to this
* resolution. */
#define MUXER_OUTPUT_WIDTH 1920
#define MUXER_OUTPUT_HEIGHT 1080
/* Muxer batch formation timeout, for e.g. 40 millisec. Should ideally be set
* based on the fastest source's framerate. */
#define MUXER_BATCH_TIMEOUT_USEC 40000
/* Check for parsing error. */
#define RETURN_ON_PARSER_ERROR(parse_expr) \
if (NVDS_YAML_PARSER_SUCCESS != parse_expr) { \
g_printerr("Error in parsing configuration file.\n"); \
return -1; \
}
gint frame_number = 0;
gchar pgie_classes_str[4][32] = { "Vehicle", "TwoWheeler", "Person",
"Roadsign"
};
/* osd_sink_pad_buffer_probe will extract metadata received on OSD sink pad
* and update params for drawing rectangle, object information etc. */
// static GstPadProbeReturn
// osd_sink_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info,
// gpointer u_data)
// {
// GstBuffer *buf = (GstBuffer *) info->data;
// guint num_rects = 0;
// NvDsObjectMeta *obj_meta = NULL;
// guint vehicle_count = 0;
// guint person_count = 0;
// NvDsMetaList * l_frame = NULL;
// NvDsMetaList * l_obj = NULL;
// NvDsDisplayMeta *display_meta = NULL;
// NvDsBatchMeta *batch_meta = gst_buffer_get_nvds_batch_meta (buf);
// for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
// l_frame = l_frame->next) {
// NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
// int offset = 0;
// for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;
// l_obj = l_obj->next) {
// obj_meta = (NvDsObjectMeta *) (l_obj->data);
// if (obj_meta->class_id == PGIE_CLASS_ID_VEHICLE) {
// vehicle_count++;
// num_rects++;
// }
// if (obj_meta->class_id == PGIE_CLASS_ID_PERSON) {
// person_count++;
// num_rects++;
// }
// }
// display_meta = nvds_acquire_display_meta_from_pool(batch_meta);
// NvOSD_TextParams *txt_params = &display_meta->text_params[0];
// display_meta->num_labels = 1;
// txt_params->display_text = g_malloc0 (MAX_DISPLAY_LEN);
// offset = snprintf(txt_params->display_text, MAX_DISPLAY_LEN, "Person = %d ", person_count);
// offset = snprintf(txt_params->display_text + offset , MAX_DISPLAY_LEN, "Vehicle = %d ", vehicle_count);
// /* Now set the offsets where the string should appear */
// txt_params->x_offset = 10;
// txt_params->y_offset = 12;
// /* Font , font-color and font-size */
// txt_params->font_params.font_name = "Serif";
// txt_params->font_params.font_size = 10;
// txt_params->font_params.font_color.red = 1.0;
// txt_params->font_params.font_color.green = 1.0;
// txt_params->font_params.font_color.blue = 1.0;
// txt_params->font_params.font_color.alpha = 1.0;
// /* Text background color */
// txt_params->set_bg_clr = 1;
// txt_params->text_bg_clr.red = 0.0;
// txt_params->text_bg_clr.green = 0.0;
// txt_params->text_bg_clr.blue = 0.0;
// txt_params->text_bg_clr.alpha = 1.0;
// nvds_add_display_meta_to_frame(frame_meta, display_meta);
// }
// g_print ("Frame Number = %d Number of objects = %d "
// "Vehicle Count = %d Person Count = %d\n",
// frame_number, num_rects, vehicle_count, person_count);
// frame_number++;
// return GST_PAD_PROBE_OK;
// }
static gboolean
bus_call (GstBus * bus, GstMessage * msg, gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_EOS:
g_print ("End of stream\n");
g_main_loop_quit (loop);
break;
case GST_MESSAGE_ERROR:{
gchar *debug = NULL;
GError *error = NULL;
gst_message_parse_error (msg, &error, &debug);
g_printerr ("ERROR from element %s: %s\n",
GST_OBJECT_NAME (msg->src), error->message);
if (debug)
g_printerr ("Error details: %s\n", debug);
g_free (debug);
g_error_free (error);
g_main_loop_quit (loop);
break;
}
default:
break;
}
return TRUE;
}
int
main (int argc, char *argv[])
{
GMainLoop *loop = NULL;
GstElement *pipeline = NULL, *source = NULL, *h264parser = NULL,
*decoder = NULL, *streammux = NULL, *sink = NULL, *pgie = NULL, *nvvidconv = NULL,
*nvosd = NULL;
GstBus *bus = NULL;
guint bus_watch_id;
GstPad *osd_sink_pad = NULL;
gboolean yaml_config = FALSE;
NvDsGieType pgie_type = NVDS_GIE_PLUGIN_INFER_SERVER;
// int current_device = -1;
// cudaGetDevice(&current_device);
// struct cudaDeviceProp prop;
// cudaGetDeviceProperties(&prop, current_device);
/* Check input arguments */
if (argc != 2) {
g_printerr ("Usage: %s <yml file>\n", argv[0]);
g_printerr ("OR: %s <H264 filename>\n", argv[0]);
return -1;
}
/* Standard GStreamer initialization */
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE);
/* Parse inference plugin type */
yaml_config = (g_str_has_suffix (argv[1], ".yml") ||
g_str_has_suffix (argv[1], ".yaml"));
if (yaml_config) {
RETURN_ON_PARSER_ERROR(nvds_parse_gie_type(&pgie_type, argv[1],
"primary-gie"));
}
/* Create gstreamer elements */
/* Create Pipeline element that will form a connection of other elements */
pipeline = gst_pipeline_new ("dstest1-pipeline");
/* Source element for reading from the file */
source = gst_element_factory_make ("filesrc", "file-source");
/* Since the data format in the input file is elementary h264 stream,
* we need a h264parser */
h264parser = gst_element_factory_make ("h264parse", "h264-parser");
/* Use nvdec_h264 for hardware accelerated decode on GPU */
decoder = gst_element_factory_make ("hyh264dec", "hy-decoder");
/* Create nvstreammux instance to form batches from one or more sources. */
streammux = gst_element_factory_make ("nvstreammux", "stream-muxer");
if (!pipeline || !streammux) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* Use nvinfer or nvinferserver to run inferencing on decoder's output,
* behaviour of inferencing is set through config file */
if (pgie_type == NVDS_GIE_PLUGIN_INFER_SERVER) {
pgie = gst_element_factory_make ("nvinferserver", "primary-nvinference-engine");
} else {
pgie = gst_element_factory_make ("nvinfer", "primary-nvinference-engine");
}
sink = gst_element_factory_make ("fakesink", "fakesink");
/* Use convertor to convert from NV12 to RGBA as required by nvosd */
// nvvidconv = gst_element_factory_make ("nvvideoconvert", "nvvideo-converter");
/* Create OSD to draw on the converted RGBA buffer */
// nvosd = gst_element_factory_make ("nvdsosd", "nv-onscreendisplay");
/* Finally render the osd output */
// if(prop.integrated) {
// sink = gst_element_factory_make("nv3dsink", "nv3d-sink");
// } else {
// #ifdef __aarch64__
// sink = gst_element_factory_make ("nv3dsink", "nvvideo-renderer");
// #else
// sink = gst_element_factory_make ("nveglglessink", "nvvideo-renderer");
// #endif
// }
if (!source || !h264parser || !decoder || !pgie || !sink) {
g_printerr ("One element could not be created. Exiting.\n");
return -1;
}
/* we set the input filename to the source element */
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
if (g_str_has_suffix (argv[1], ".h264")) {
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
g_object_set (G_OBJECT (streammux), "batch-size", 1, NULL);
// g_object_set (G_OBJECT (streammux), "width", MUXER_OUTPUT_WIDTH, "height",
// MUXER_OUTPUT_HEIGHT,
// "batched-push-timeout", MUXER_BATCH_TIMEOUT_USEC, NULL);
/* Set all the necessary properties of the nvinfer element,
* the necessary ones are : */
g_object_set (G_OBJECT (pgie),
"config-file-path", "dstest1_pgie_nvinferserver_config.txt", NULL); // 这个函数是 GObject 系统中的核心函数,主要用于设置 GObject 对象的属性值
}
if (yaml_config) {
RETURN_ON_PARSER_ERROR(nvds_parse_file_source(source, argv[1],"source"));
RETURN_ON_PARSER_ERROR(nvds_parse_streammux(streammux, argv[1],"streammux"));
/* Set all the necessary properties of the inference element */
RETURN_ON_PARSER_ERROR(nvds_parse_gie(pgie, argv[1], "primary-gie"));
}
/* we add a message handler */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
bus_watch_id = gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus);
/* Set up the pipeline */
/* we add all elements into the pipeline */
gst_bin_add_many (GST_BIN (pipeline),
source, h264parser, decoder, streammux, pgie, sink, NULL);
g_print ("Added elements to bin\n");
GstPad *sinkpad, *srcpad;
gchar pad_name_sink[16] = "sink_0";
gchar pad_name_src[16] = "src";
sinkpad = gst_element_request_pad_simple (streammux, pad_name_sink);
if (!sinkpad) {
g_printerr ("Streammux request sink pad failed. Exiting.\n");
return -1;
}
srcpad = gst_element_get_static_pad (decoder, pad_name_src);
if (!srcpad) {
g_printerr ("Decoder request src pad failed. Exiting.\n");
return -1;
}
if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) {
g_printerr ("Failed to link decoder to stream muxer. Exiting.\n");
return -1;
}
gst_object_unref (sinkpad);
gst_object_unref (srcpad);
/* we link the elements together */
/* file-source -> h264-parser -> nvh264-decoder ->
* pgie -> nvvidconv -> nvosd -> video-renderer */
if (!gst_element_link_many (source, h264parser, decoder, NULL)) {
g_printerr ("Elements could not be linked: 1. Exiting.\n");
return -1;
}
if (!gst_element_link_many (streammux, pgie, sink, NULL)) {
g_printerr ("Elements could not be linked: 2. Exiting.\n");
return -1;
}
// /* Lets add probe to get informed of the meta data generated, we add probe to
// * the sink pad of the osd element, since by that time, the buffer would have
// * had got all the metadata. */
// osd_sink_pad = gst_element_get_static_pad (nvosd, "sink");
// if (!osd_sink_pad)
// g_print ("Unable to get sink pad\n");
// else
// gst_pad_add_probe (osd_sink_pad, GST_PAD_PROBE_TYPE_BUFFER,
// osd_sink_pad_buffer_probe, NULL, NULL);
// gst_object_unref (osd_sink_pad);
/* Set the pipeline to "playing" state */
g_print ("Using file: %s\n", argv[1]);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* Wait till pipeline encounters an error or EOS */
g_print ("Running...\n");
g_main_loop_run (loop);
/* Out of the main loop, clean up nicely */
g_print ("Returned, stopping playback\n");
gst_element_set_state (pipeline, GST_STATE_NULL);
g_print ("Deleting pipeline\n");
gst_object_unref (GST_OBJECT (pipeline));
g_source_remove (bus_watch_id);
g_main_loop_unref (loop);
return 0;
}
################################################################################
# SPDX-FileCopyrightText: Copyright (c) 2018-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
################################################################################
infer_config {
unique_id: 1
gpu_ids: [0]
max_batch_size: 30
backend {
inputs: [ {
name: "input_1:0"
}]
outputs: [
{name: "output_cov/Sigmoid:0"},
{name: "output_bbox/BiasAdd:0"}
]
triton {
model_name: "Primary_Detector"
version: 1
model_repo {
root: "../../../sugon_samples/triton_model_repo_NV"
strict_model_config: true
backend_dir: "./sugon_samples/backends" # relative to the command running directory
#log_level: 3
}
}
}
preprocess {
network_format: MEDIA_FORMAT_NONE
tensor_order: TENSOR_ORDER_LINEAR
tensor_name: "input_1:0"
maintain_aspect_ratio: 0
frame_scaling_hw: FRAME_SCALING_HW_DEFAULT
frame_scaling_filter: 1
normalize {
scale_factor: 0.00392156862745098
channel_offsets: [0, 0, 0]
}
}
postprocess {
labelfile_path: "../../../sugon_samples/models/Primary_Detector_NV/labels.txt"
detection {
num_detected_classes: 4
per_class_params {
key: 0
value { pre_threshold: 0.4 }
}
nms {
confidence_threshold:0.2
topk:20
iou_threshold:0.5
}
}
}
extra {
copy_input_to_host_buffers: false
output_buffer_pool_size: 2
}
}
input_control {
process_mode: PROCESS_MODE_FULL_FRAME
operate_on_gie_id: -1
interval: 0
}
################################################################################
# SPDX-FileCopyrightText: Copyright (c) 2018-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
################################################################################
infer_config {
unique_id: 2
gpu_ids: [0]
max_batch_size: 16
backend {
triton {
model_name: "Secondary_VehicleMake"
version: 1
model_repo {
root: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/triton_model_repo_NV"
strict_model_config: true
backend_dir: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/backends"
}
}
}
preprocess {
network_format: IMAGE_FORMAT_BGR
tensor_order: TENSOR_ORDER_LINEAR
maintain_aspect_ratio: 0
frame_scaling_hw: FRAME_SCALING_HW_DEFAULT
frame_scaling_filter: 1
normalize {
scale_factor: 1
}
}
postprocess {
labelfile_path: "/workspace/shared_docker/packages/opt/nvidia/deepstream/deepstream-7.1/sugon_samples/models/Secondary_VehicleMake/labels.txt"
classification {
threshold: 0.51
}
}
}
input_control {
process_mode: PROCESS_MODE_FULL_FRAME
operate_on_gie_id: -1
interval: 0
#process_mode: PROCESS_MODE_CLIP_OBJECTS
#operate_on_gie_id: 1
#operate_on_class_ids: [0]
#secondary_reinfer_interval: 90
#async_mode: true
#object_control {
# bbox_filter {
# min_width: 64
# min_height: 64
# }
#}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment