Debian Codegraph @

gst/tensordecoders/gstyolotensordecoder.h

raw
1 /*
2 * GStreamer gstreamer-yolotensordecoder
3 * Copyright (C) 2024 Collabora Ltd
4 * Authors: Daniel Morin <[email protected]>
5 * Vineet Suryan <[email protected]>
6 * Santosh Mahto <[email protected]>
7 *
8 * gstyolotensordecoder.h
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
19 *
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25
26
27 #ifndef __GST_YOLO_TENSOR_DECODER_H__
28 #define __GST_YOLO_TENSOR_DECODER_H__
29
30 #include <gst/gst.h>
31 #include <gst/video/video.h>
32 #include <gst/base/base.h>
33 #include <gst/analytics/analytics.h>
34
35 GType gst_yolo_tensor_decoder_get_type (void);
36
37 #define GST_TYPE_YOLO_TENSOR_DECODER (gst_yolo_tensor_decoder_get_type ())
38 #define GST_YOLO_TENSOR_DECODER(obj) \
39 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_YOLO_TENSOR_DECODER, GstYoloTensorDecoder))
40 #define GST_YOLO_TENSOR_DECODER_CLASS(klass) \
41 (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_YOLO_TENSOR_DECODER, GstYoloTensorDecoderClass))
42 #define GST_IS_YOLO_TENSOR_DECODER(obj) \
43 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_YOLO_TENSOR_DECODER))
44 #define GST_IS_YOLO_TENSOR_DECODER_CLASS(klass) \
45 (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_YOLO_TENSOR_DECODER))
46 #define GST_YOLO_TENSOR_DECODER_GET_CLASS(obj) \
47 (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_YOLO_TENSOR_DECODER, GstYoloTensorDecoderClass))
48
49 typedef struct _GstYoloTensorDecoder GstYoloTensorDecoder;
50 typedef struct _GstYoloTensorDecoderClass GstYoloTensorDecoderClass;
51
52 typedef struct _BBox
53 {
54 gint x;
55 gint y;
56 guint w;
57 guint h;
58 } BBox;
59
60 struct _GstYoloTensorDecoder
61 {
62 GstBaseTransform basetransform;
63 /* Box confidence threshold */
64 gfloat box_confi_thresh;
65 /* Class confidence threshold */
66 gfloat cls_confi_thresh;
67 /* Intersection-of-Union threshold */
68 gfloat iou_thresh;
69 /* Maximum detection/mask */
70 gsize max_detection;
71 /* Candidates with a class confidence level above threshold. */
72 GArray *sel_candidates;
73 /* Final candidates selected that respect class confidence level,
74 * NMS and maximum detection. */
75 GPtrArray *selected;
76 /* Video Info */
77 GstVideoInfo video_info;
78 /* Labels file */
79 gchar *label_file;
80 /* Labels */
81 GArray *labels;
82 };
83
84 struct _GstYoloTensorDecoderClass
85 {
86 GstBaseTransformClass parent_class;
87
88 void (*object_found) (GstYoloTensorDecoder *self,
89 GstAnalyticsRelationMeta *rmeta, BBox *bb, gfloat confidence,
90 GQuark class_quark, const gfloat *candidate_masks, gsize offset,
91 guint count);
92 };
93
94 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GstYoloTensorDecoder, g_object_unref)
95
96 GST_ELEMENT_REGISTER_DECLARE (yolo_tensor_decoder)
97
98 gboolean
99 gst_yolo_tensor_decoder_decode_f32 (GstYoloTensorDecoder * self,
100 GstAnalyticsRelationMeta * rmeta, const GstTensor * detections_tensor,
101 guint num_masks);
102
103 #endif /* __GST_YOLO_TENSOR_DECODER_H__ */