Skip to content

Commit a845b05

Browse files
committed
Add tensor metadata registry and keypoint detection support
- Introduce meta_registry.py for centralized metadata management - Update region_of_interest.py and tensor.py for metadata handling - Enhance util.py with utility functions - Add tensor conversion tests (C++ and Python) - Include keypoint detection sample pipeline - Update CMakeLists.txt for new tests
1 parent cf8d5ad commit a845b05

7 files changed

Lines changed: 1364 additions & 26 deletions

File tree

python/gstgva/meta_registry.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# ==============================================================================
2+
# Copyright (C) 2026 Intel Corporation
3+
#
4+
# SPDX-License-Identifier: MIT
5+
# ==============================================================================
6+
7+
"""Register DLStreamerMeta metadata types (GroupMtd, KeypointMtd) with the
8+
GstAnalytics Python override so that the RelationMeta iterator wraps them
9+
into the correct Python types and isinstance() checks work.
10+
11+
Import this module once before iterating over GstAnalytics.RelationMeta
12+
that may contain DLStreamerMeta metadata::
13+
14+
import gstgva.meta_registry # side-effect: registers types
15+
# or
16+
from gstgva import meta_registry # same effect
17+
"""
18+
19+
import gi
20+
21+
gi.require_version("GstAnalytics", "1.0")
22+
gi.require_version("DLStreamerMeta", "1.0")
23+
24+
# pylint: disable=no-name-in-module
25+
from gi.repository import DLStreamerMeta
26+
from gi.overrides import GstAnalytics as _GstAnalyticsOverride
27+
# pylint: enable=no-name-in-module
28+
29+
# pylint: disable=protected-access
30+
_GstAnalyticsOverride._wrap_mtd(
31+
DLStreamerMeta,
32+
'KeypointMtd',
33+
DLStreamerMeta.relation_meta_get_keypoint_mtd
34+
)
35+
_GstAnalyticsOverride._wrap_mtd(
36+
DLStreamerMeta,
37+
'GroupMtd',
38+
DLStreamerMeta.relation_meta_get_group_mtd
39+
)
40+
# pylint: enable=protected-access

python/gstgva/region_of_interest.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,13 @@
2222
# GObject Introspection modules are dynamically generated, pylint cannot introspect them
2323
# pylint: disable=no-name-in-module,unused-import,wrong-import-position
2424
from gi.repository import GstVideo, GLib, GObject, Gst, GstAnalytics, DLStreamerMeta
25-
from gi.overrides import GstAnalytics as GstAnalyticsOverride
2625
# pylint: enable=no-name-in-module,unused-import
2726

2827
from .tensor import Tensor
2928
from .util import VideoRegionOfInterestMeta, GstStructureHandle
3029
from .util import libgst, libgstvideo
31-
32-
# Register custom DLStreamerMeta metadata types
33-
# pylint: disable=protected-access
30+
from . import meta_registry # noqa: F401 — registers DLStreamerMeta types with GstAnalytics
3431
# pylint: enable=wrong-import-position
35-
GstAnalyticsOverride._wrap_mtd(
36-
DLStreamerMeta,
37-
'KeypointMtd',
38-
DLStreamerMeta.relation_meta_get_keypoint_mtd
39-
)
40-
GstAnalyticsOverride._wrap_mtd(
41-
DLStreamerMeta,
42-
'GroupMtd',
43-
DLStreamerMeta.relation_meta_get_group_mtd
44-
)
45-
# pylint: enable=protected-access
4632

4733
Rect = namedtuple("Rect", "x y w h")
4834

@@ -71,6 +57,7 @@ def __init__(
7157
tensor = Tensor(tensor_structure)
7258
if (
7359
tensor.name() != "object_id"
60+
and tensor.type() != "keypoints"
7461
and tensor.type() != "classification_result"
7562
):
7663
self._tensors.append(tensor)
@@ -321,7 +308,7 @@ def add_tensor(self, tensor: Tensor):
321308
raise ValueError("RegionOfInterest:add_tensor: Invalid tensor structure")
322309
libgstvideo.gst_video_region_of_interest_meta_add_param(self.meta(), s)
323310

324-
tensor_mtd = tensor.convert_to_meta(self.__od_meta.meta)
311+
tensor_mtd = tensor.convert_to_meta(self.__od_meta.meta, self.__od_meta)
325312
if tensor_mtd is not None:
326313
if not self.__od_meta.meta.set_relation(
327314
GstAnalytics.RelTypes.CONTAIN, self.__od_meta.id, tensor_mtd.id

0 commit comments

Comments
 (0)