mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 16:26:39 +00:00
analytics: Implement scale meta transform for Object detection meta
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5863>
This commit is contained in:
parent
5d3035553c
commit
745197d386
5 changed files with 64 additions and 8 deletions
|
@ -204,7 +204,7 @@ Get instance size</doc>
|
|||
<parameter name="transbuf" transfer-ownership="none">
|
||||
<type name="Gst.Buffer" c:type="GstBuffer*"/>
|
||||
</parameter>
|
||||
<parameter name="mtd" transfer-ownership="none">
|
||||
<parameter name="transmtd" transfer-ownership="none">
|
||||
<type name="Mtd" c:type="GstAnalyticsMtd*"/>
|
||||
</parameter>
|
||||
<parameter name="buffer" transfer-ownership="none">
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include "gstanalyticsmeta.h"
|
||||
|
||||
#include <gst/video/video.h>
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (an_relation_meta_debug);
|
||||
#define GST_CAT_AN_RELATION an_relation_meta_debug
|
||||
|
||||
|
@ -252,7 +254,12 @@ GType
|
|||
gst_analytics_relation_meta_api_get_type (void)
|
||||
{
|
||||
static GType type = 0;
|
||||
static const gchar *tags[] = { NULL };
|
||||
static const gchar *tags[] = {
|
||||
GST_META_TAG_VIDEO_SIZE_STR,
|
||||
GST_META_TAG_VIDEO_ORIENTATION_STR,
|
||||
GST_META_TAG_VIDEO_STR,
|
||||
NULL
|
||||
};
|
||||
if (g_once_init_enter (&type)) {
|
||||
GType newType =
|
||||
gst_meta_api_type_register ("GstAnalyticsRelationMetaAPI", tags);
|
||||
|
@ -319,7 +326,8 @@ gst_analytics_relation_meta_transform (GstBuffer * transbuf,
|
|||
GST_CAT_TRACE (GST_CAT_AN_RELATION, "meta transform %s",
|
||||
g_quark_to_string (type));
|
||||
|
||||
if (GST_META_TRANSFORM_IS_COPY (type)) {
|
||||
if (GST_META_TRANSFORM_IS_COPY (type) ||
|
||||
GST_VIDEO_META_TRANSFORM_IS_SCALE (type)) {
|
||||
GstAnalyticsRelationMeta *rmeta = (GstAnalyticsRelationMeta *) meta;
|
||||
GstAnalyticsRelationMeta *new = (GstAnalyticsRelationMeta *)
|
||||
gst_buffer_get_meta (transbuf, GST_ANALYTICS_RELATION_META_API_TYPE);
|
||||
|
@ -339,6 +347,7 @@ gst_analytics_relation_meta_transform (GstBuffer * transbuf,
|
|||
}
|
||||
|
||||
if (new->offset == 0) {
|
||||
guint i;
|
||||
|
||||
if (new->rel_order < rmeta->rel_order) {
|
||||
g_free (new->adj_mat);
|
||||
|
@ -372,6 +381,18 @@ gst_analytics_relation_meta_transform (GstBuffer * transbuf,
|
|||
new->next_id = rmeta->next_id;
|
||||
new->offset = rmeta->offset;
|
||||
|
||||
for (i = 0; i < new->length; i++) {
|
||||
GstAnalyticsRelatableMtdData *rlt_mtd_data =
|
||||
(GstAnalyticsRelatableMtdData *) (new->mtd_data_lookup[i] +
|
||||
new->analysis_results);
|
||||
if (rlt_mtd_data->impl && rlt_mtd_data->impl->mtd_meta_transform) {
|
||||
GstAnalyticsMtd transmtd;
|
||||
transmtd.id = rlt_mtd_data->id;
|
||||
transmtd.meta = new;
|
||||
rlt_mtd_data->impl->mtd_meta_transform (transbuf, &transmtd, buffer,
|
||||
type, data);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
} else {
|
||||
g_warning ("Trying to copy GstAnalyticsRelationMeta into non-empty meta");
|
||||
|
|
|
@ -78,7 +78,7 @@ struct _GstAnalyticsMtd
|
|||
typedef struct {
|
||||
const char *name;
|
||||
|
||||
gboolean (*mtd_meta_transform) (GstBuffer *transbuf, GstAnalyticsMtd *mtd,
|
||||
gboolean (*mtd_meta_transform) (GstBuffer *transbuf, GstAnalyticsMtd *transmtd,
|
||||
GstBuffer *buffer, GQuark type,
|
||||
gpointer data);
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
#include "gstanalyticsobjectdetectionmtd.h"
|
||||
|
||||
#include <gst/video/video.h>
|
||||
|
||||
typedef struct _GstAnalyticsODMtdData GstAnalyticsODMtdData;
|
||||
|
||||
/**
|
||||
|
@ -49,9 +51,42 @@ struct _GstAnalyticsODMtdData
|
|||
gfloat location_confidence_lvl;
|
||||
};
|
||||
|
||||
static gboolean
|
||||
gst_analytics_od_mtd_meta_transform (GstBuffer * transbuf,
|
||||
GstAnalyticsMtd * transmtd, GstBuffer * buffer, GQuark type, gpointer data)
|
||||
{
|
||||
if (GST_VIDEO_META_TRANSFORM_IS_SCALE (type)) {
|
||||
GstVideoMetaTransform *trans = data;
|
||||
gint ow, oh, nw, nh;
|
||||
GstAnalyticsODMtdData *oddata;
|
||||
|
||||
ow = GST_VIDEO_INFO_WIDTH (trans->in_info);
|
||||
nw = GST_VIDEO_INFO_WIDTH (trans->out_info);
|
||||
oh = GST_VIDEO_INFO_HEIGHT (trans->in_info);
|
||||
nh = GST_VIDEO_INFO_HEIGHT (trans->out_info);
|
||||
|
||||
oddata = gst_analytics_relation_meta_get_mtd_data (transmtd->meta,
|
||||
transmtd->id);
|
||||
|
||||
oddata->x *= nw;
|
||||
oddata->x /= ow;
|
||||
|
||||
oddata->w *= nw;
|
||||
oddata->w /= ow;
|
||||
|
||||
oddata->y *= nh;
|
||||
oddata->y /= oh;
|
||||
|
||||
oddata->h *= nh;
|
||||
oddata->h /= oh;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static const GstAnalyticsMtdImpl od_impl = {
|
||||
"object-detection",
|
||||
NULL
|
||||
gst_analytics_od_mtd_meta_transform
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,7 @@ gstanalytics = library('gstanalytics-' + api_version,
|
|||
soversion : soversion,
|
||||
darwin_versions : osxversion,
|
||||
install : true,
|
||||
dependencies : [gstbase_dep])
|
||||
dependencies : [gstbase_dep, gstvideo_dep])
|
||||
|
||||
gst_libraries += [[pkg_name, {'lib': gstanalytics}]]
|
||||
pkgconfig.generate(gstanalytics,
|
||||
|
@ -43,7 +43,7 @@ if build_gir
|
|||
'includes' : ['Gst-1.0', 'GstBase-1.0'],
|
||||
'install' : true,
|
||||
'extra_args' : gir_init_section + ['-DGST_USE_UNSTABLE_API'],
|
||||
'dependencies' : [gstbase_dep]
|
||||
'dependencies' : [gstbase_dep, gstvideo_dep]
|
||||
}
|
||||
library_def += {'gir': [gir]}
|
||||
if not static_build
|
||||
|
@ -59,6 +59,6 @@ gst_libraries += [[pkg_name, library_def]]
|
|||
gstanalytics_dep = declare_dependency(link_with : gstanalytics,
|
||||
include_directories : [libsinc],
|
||||
sources: gen_sources,
|
||||
dependencies : [gstbase_dep])
|
||||
dependencies : [gstbase_dep, gstvideo_dep])
|
||||
|
||||
meson.override_dependency(pkg_name, gstanalytics_dep)
|
||||
|
|
Loading…
Reference in a new issue