NVIDIA DeepStream SDK API Reference

9.1 Release
9.1/service-maker/sources/modules/sample_video_probe/sample_video_probe.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024-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 #include <iostream>
19 #include <string>
20 #include <memory>
21 #include <vector>
22 
23 #include "buffer_probe.hpp"
24 
25 using namespace std;
26 
27 #define MAX_DISPLAY_LEN 64
28 #define PGIE_CLASS_ID_VEHICLE 0
29 #define PGIE_CLASS_ID_PERSON 2
30 
31 namespace deepstream
32 {
33 
34  class CountMarker : public BufferProbe::IBatchMetadataOperator
35  {
36  public:
38  virtual ~CountMarker() {}
39 
41  {
42  FrameMetadata::Iterator frame_itr;
43  for (data.initiateIterator(frame_itr); !frame_itr->done(); frame_itr->next())
44  {
45  auto vehicle_count = 0;
46  auto person_count = 0;
47  FrameMetadata &frame_meta = frame_itr->get();
49  for (frame_meta.initiateIterator(obj_itr); !obj_itr->done(); obj_itr->next())
50  {
51  ObjectMetadata &object_meta = obj_itr->get();
52  auto class_id = object_meta.classId();
53  if (class_id == PGIE_CLASS_ID_VEHICLE)
54  {
55  vehicle_count++;
56  }
57  else if (class_id == PGIE_CLASS_ID_PERSON)
58  {
59  person_count++;
60  }
61  }
62  DisplayMetadata display_meta;
63  if (data.acquire(display_meta))
64  {
65  std::stringstream ss;
66  ss << "Person=" << person_count << ",Vehicle=" << vehicle_count;
67  std::string str = ss.str();
68  int font_size = 0;
69  char font[] = "Serif";
70  probe.getProperty("font-size", font_size);
72  (char *)str.c_str(),
73  10, //< x offset
74  12, //< y offset
75  {font, (unsigned int)font_size, {1.0, 1.0, 1.0, 1.0}}, //< font and color
76  1,
77  {0.0, 0.0, 0.0, 1.0} //< background
78  };
79  display_meta.add(label);
80  (*frame_itr)->append(display_meta);
81  }
82  }
83 
84  return probeReturn::Probe_Ok;
85  }
86  };
87 
88 }
deepstream::ObjectMetadata::Iterator
std::unique_ptr< AbstractIterator< ObjectMetadata > > Iterator
Definition: service-maker/includes/metadata.hpp:184
deepstream::BufferProbe
Represent a custom object for the purpose of probing output buffers.
Definition: service-maker/includes/buffer_probe.hpp:63
deepstream::ObjectMetadata::classId
unsigned int classId() const
Number to identify the class of the object.
deepstream::CountMarker::~CountMarker
virtual ~CountMarker()
Definition: 9.1/service-maker/sources/modules/sample_video_probe/sample_video_probe.hpp:38
PGIE_CLASS_ID_PERSON
#define PGIE_CLASS_ID_PERSON
Definition: 9.1/service-maker/sources/modules/sample_video_probe/sample_video_probe.hpp:29
deepstream::FrameMetadata::initiateIterator
void initiateIterator(ObjectMetadata::Iterator &) const
Get the iterator for object metadata within it.
deepstream::ObjectMetadata
Object metadata.
Definition: service-maker/includes/metadata.hpp:182
deepstream::probeReturn
probeReturn
Return values from user implemented probe interfaces.
Definition: service-maker/includes/buffer_probe.hpp:47
deepstream
Definition: service-maker/includes/buffer.hpp:38
deepstream::BatchMetadata::initiateIterator
void initiateIterator(FrameMetadata::Iterator &) const
Get the iterator for frame metadata within it.
deepstream::BatchMetadata
Holds information about a formed batch containingframes from different sources.
Definition: service-maker/includes/metadata.hpp:797
deepstream::FrameMetadata::Iterator
std::unique_ptr< AbstractIterator< FrameMetadata > > Iterator
Definition: service-maker/includes/metadata.hpp:456
deepstream::DisplayMetadata
Metadata for overlay display on a frame.
Definition: service-maker/includes/metadata.hpp:409
deepstream::CountMarker::handleData
virtual probeReturn handleData(BufferProbe &probe, BatchMetadata &data)
Definition: 9.1/service-maker/sources/modules/sample_video_probe/sample_video_probe.hpp:40
_NvOSD_TextParams
Holds parameters of text to be overlayed.
Definition: sources/includes/nvll_osd_struct.h:120
PGIE_CLASS_ID_VEHICLE
#define PGIE_CLASS_ID_VEHICLE
Definition: 9.1/service-maker/sources/modules/sample_video_probe/sample_video_probe.hpp:28
deepstream::CountMarker::CountMarker
CountMarker()
Definition: 9.1/service-maker/sources/modules/sample_video_probe/sample_video_probe.hpp:37
deepstream::BatchMetadata::acquire
bool acquire(DisplayMetadata &)
Initialize an empty display metadata.
deepstream::Object::getProperty
Object & getProperty(const std::string &name, T &value, Args &... args)
Template for getting multiple properties.
Definition: service-maker/includes/object.hpp:176
deepstream::FrameMetadata
Holds information for a single frame.
Definition: service-maker/includes/metadata.hpp:454
deepstream::DisplayMetadata::add
bool add(NvOSD_TextParams &)
Add a text label.