├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── COPYING
├── README.md
├── docker
├── Dockerfile-Ubuntu-16.04
└── README.md
├── docs
├── meson.build
└── plugins
│ ├── gst-inference-plugin-sections.txt
│ ├── gst-inference-plugin.types
│ └── meson.build
├── ext
├── meson.build
├── opencv
│ ├── gstinferenceoverlay.cc
│ ├── gstinferenceoverlay.h
│ ├── gstplugin.cc
│ └── meson.build
└── r2inference
│ ├── gstinceptionv1.c
│ ├── gstinceptionv1.h
│ ├── gstinceptionv2.c
│ ├── gstinceptionv2.h
│ ├── gstinceptionv3.c
│ ├── gstinceptionv3.h
│ ├── gstinceptionv4.c
│ ├── gstinceptionv4.h
│ ├── gstinference.c
│ ├── gstmobilenetv2.c
│ ├── gstmobilenetv2.h
│ ├── gstmobilenetv2ssd.c
│ ├── gstmobilenetv2ssd.h
│ ├── gstresnet50v1.c
│ ├── gstresnet50v1.h
│ ├── gstrosetta.c
│ ├── gstrosetta.h
│ ├── gsttinyyolov2.c
│ ├── gsttinyyolov2.h
│ ├── gsttinyyolov3.c
│ ├── gsttinyyolov3.h
│ └── meson.build
├── gst-libs
├── gst
│ ├── meson.build
│ ├── opencv
│ │ ├── gstinferencebaseoverlay.cc
│ │ ├── gstinferencebaseoverlay.h
│ │ └── meson.build
│ └── r2inference
│ │ ├── gstbasebackend.cc
│ │ ├── gstbasebackend.h
│ │ ├── gstbasebackendsubclass.h
│ │ ├── gstchildinspector.c
│ │ ├── gstchildinspector.h
│ │ ├── gstinferencebackend.cc
│ │ ├── gstinferencebackends.cc
│ │ ├── gstinferencebackends.h
│ │ ├── gstinferenceclassification.c
│ │ ├── gstinferenceclassification.h
│ │ ├── gstinferencedebug.c
│ │ ├── gstinferencedebug.h
│ │ ├── gstinferencemeta.c
│ │ ├── gstinferencemeta.h
│ │ ├── gstinferencepostprocess.c
│ │ ├── gstinferencepostprocess.h
│ │ ├── gstinferenceprediction.c
│ │ ├── gstinferenceprediction.h
│ │ ├── gstinferencepreprocess.c
│ │ ├── gstinferencepreprocess.h
│ │ ├── gstvideoinference.c
│ │ ├── gstvideoinference.h
│ │ └── meson.build
└── meson.build
├── gst
├── inferenceutils
│ ├── cropelement.cc
│ ├── cropelement.h
│ ├── gstinferencebin.c
│ ├── gstinferencebin.h
│ ├── gstinferencecrop.cc
│ ├── gstinferencecrop.h
│ ├── gstinferencedebug.c
│ ├── gstinferencedebug.h
│ ├── gstinferencefilter.c
│ ├── gstinferencefilter.h
│ ├── gstinferenceutils.c
│ ├── meson.build
│ ├── videocrop.cc
│ └── videocrop.h
└── meson.build
├── hooks
└── pre-commit.hook
├── meson.build
├── meson_options.txt
└── tests
├── benchmark
└── run_benchmark.sh
├── check
├── meson.build
└── process
│ ├── meson.build
│ ├── preprocess_functions_utils.c
│ ├── preprocess_functions_utils.h
│ ├── test_gst_normalize_function.c
│ ├── test_gst_pixel_to_float_function.c
│ └── test_gst_subtract_mean_function.c
├── examples
├── classification
│ ├── README.md
│ ├── customlogic.cc
│ ├── customlogic.h
│ ├── gstclassification.c
│ └── meson.build
├── detection
│ ├── README.md
│ ├── customlogic.cc
│ ├── customlogic.h
│ ├── gstdetection.c
│ └── meson.build
└── meson.build
└── meson.build
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: gst-inference CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | - dev-*
8 | pull_request:
9 | branches:
10 | - dev-*
11 |
12 | jobs:
13 | build_meson:
14 | runs-on: ubuntu-18.04
15 | strategy:
16 | matrix:
17 | container: ["ridgerun/r2inference-ubuntu-18.04:v0.1.5", "ridgerun/r2inference-ubuntu-16.04:v0.3.1"]
18 | container:
19 | image: ${{ matrix.container }}
20 | env:
21 | PREFIX: /usr
22 | CFLAGS: -Werror
23 | CXXFLAGS: -Werror
24 | steps:
25 | - uses: actions/checkout@v2
26 | - name: Build backend
27 | run: |
28 | tar -C /usr/local -xzf /root/r2inference/backends/tensorflow/v1.15.0/libtensorflow-cpu-linux-x86_64-1.15.0.tar.gz
29 | ldconfig
30 | - name: Checkout r2i repo
31 | uses: actions/checkout@master
32 | with:
33 | repository: RidgeRun/r2inference
34 | - name: Build r2i
35 | run: |
36 | CFLAGS="${{ env.CFLAGS }}"
37 | CXXFLAGS="${{ env.CXXFLAGS }}"
38 | meson build --prefix $PREFIX -Denable-tensorflow=true -Denable-docs=disabled
39 | ninja -C build
40 | ninja -C build install
41 | - name: Checkout gst-inference repo
42 | uses: actions/checkout@v2
43 | with:
44 | submodules: true
45 | - name: Build gst-inference
46 | env:
47 | LD_LIBRARY_PATH: /usr/local/lib/
48 | run: |
49 | meson build --prefix $PREFIX -Denable-gtk-doc=false
50 | ninja -C build
51 | - name: Check gst-inference
52 | env:
53 | LD_LIBRARY_PATH: /usr/local/lib/
54 | run: ninja -C build test -v
55 | - name: Install gst-inference
56 | run: |
57 | ninja -C build install
58 | - name: Check gst-inference install
59 | env:
60 | LD_LIBRARY_PATH: /usr/local/lib/
61 | run: gst-inspect-1.0 inference
62 | - name: Run GStreamer pipeline
63 | env:
64 | ROOT: /root/r2inference/resources/InceptionV1_TensorFlow
65 | LD_LIBRARY_PATH: /usr/local/lib/
66 | run: |
67 | GST_DEBUG=2,inferencebin:6 gst-launch-1.0 filesrc location=$ROOT/Egyptian_cat.jpg ! jpegparse ! jpegdec ! \
68 | inferencebin arch='inceptionv1' model-location=$ROOT/graph_inceptionv1_tensorflow.pb \
69 | backend='tensorflow' input-layer='input' output-layer='InceptionV1/Logits/Predictions/Reshape_1' \
70 | labels=$ROOT/imagenet_labels.txt crop=false overlay=true filter=-1 ! \
71 | fakesink silent=false sync=false async=false -v
72 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Editor backup
2 | *~
3 | *.bak
4 | \#*
5 | *.orig
6 |
7 | # Build outputs
8 | *.o
9 |
10 | # Git conflict files
11 | .merge_file_*
12 |
13 | # GtkDoc
14 | docs/version.entities
15 | docs/plugins/*.txt
16 | docs/plugins/*.sgml
17 | docs/plugins/*.new
18 | docs/plugins/*.args
19 | docs/plugins/*.hierarchy
20 | docs/plugins/*.interfaces
21 | docs/plugins/*.prerequisites
22 | docs/plugins/*.signals
23 | docs/plugins/*.stamp
24 | docs/plugins/html/
25 | docs/plugins/xml/
26 |
27 | # Tests
28 | test-driver
29 | *.xml
30 | *.log
31 | *.trs
32 |
33 | # 3rd party tools
34 | .clang_complete
35 | cscope.files
36 | cscope.out
37 |
38 | # Examples
39 | tests/examples/classification/classification
40 | tests/examples/detection/detection
41 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | GstInference | Coral from Google
2 | :-------------------------:|:-------------------------:
3 | [
](https://developer.ridgerun.com/wiki/index.php?title=GstInference) | [
](https://coral.ai/products/#prototyping-products)
4 |
5 | # GstInference
6 |
7 | >See the **[GstInference wiki](https://developer.ridgerun.com/wiki/index.php?title=GstInference)** for the complete documentation.
8 |
9 | GstInference is an open-source project from Ridgerun Engineering that provides a framework for integrating deep learning inference into GStreamer. Either use one of the included elements to do out-of-the box inference using the most popular deep learning architectures, or leverage the base classes and utilities to support your own custom architecture.
10 |
11 | This repo uses **[R²Inference](https://github.com/RidgeRun/r2inference)**, an abstraction layer in C/C++ for a variety of machine learning frameworks. With R²Inference a single C/C++ application may work with models on different frameworks. This is useful to execute inference taking advantage of different hardware resources such as CPU, GPU, or AI optimized acelerators.
12 |
13 | GstInference provides several example elements for common applications, such as [`Inception v4`](ext/r2inference/gstinceptionv4.c) for image classification and [`TinyYOLO v2`](ext/r2inference/gsttinyyolov2.c) for object detection. Examples are provided for performing inference on any GStreamer video stream.
14 |
15 |
16 |
17 | ## Installing GstInference
18 |
19 | Follow the steps to get GstInference running on your platform:
20 |
21 | * [Clone or download R²Inference](https://github.com/RidgeRun/r2inference)
22 | * [Build R²Inference](https://developer.ridgerun.com/wiki/index.php?title=R2Inference/Getting_started/Building_the_library)
23 | * [Clone or download GstInference](https://github.com/RidgeRun/gst-inference)
24 | * [Build GstInference](https://developer.ridgerun.com/wiki/index.php?title=GstInference/Getting_started/Building_the_plugin)
25 |
26 | ## Examples
27 |
28 | We provide GStreamer [example pipelines](https://developer.ridgerun.com/wiki/index.php?title=GstInference/Example_pipelines) for all our suported platforms,architectures and backends.
29 |
30 | We also provide [example applications](https://developer.ridgerun.com/wiki/index.php?title=GstInference/Example_Applications) for classification and detection.
31 |
32 | We also provide example trained models on our [model zoo](https://developer.ridgerun.com/wiki/index.php?title=GstInference/Model_Zoo)
33 |
--------------------------------------------------------------------------------
/docker/Dockerfile-Ubuntu-16.04:
--------------------------------------------------------------------------------
1 | FROM ubuntu:16.04
2 |
3 | # Install all needed packages
4 | RUN apt-get update && apt-get install -y \
5 | build-essential \
6 | apt-utils software-properties-common \
7 | python3-pip python3-dev \
8 | libgstreamer1.0-0 gstreamer1.0-plugins-base \
9 | libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
10 | gstreamer1.0-plugins-good gstreamer1.0-plugins-bad \
11 | gstreamer1.0-plugins-ugly gstreamer1.0-libav \
12 | gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x \
13 | cmake cpputest automake libtool pkg-config \
14 | unzip doxygen libgtk2.0-dev \
15 | wget vim \
16 | libcv2.4 libopencv-contrib-dev libopencv-contrib2.4v5 \
17 | libopencv-core-dev libopencv-core2.4v5 libopencv-dev \
18 | libopencv-highgui-dev libopencv-highgui2.4v5 \
19 | libopencv-imgproc-dev libopencv-imgproc2.4v5 \
20 | libopencv-legacy-dev libopencv-legacy2.4v5 \
21 | libopencv-video-dev libopencv-video2.4v5
22 |
23 | RUN rm -rf /var/lib/apt/lists/* \
24 | && pip3 install meson ninja numpy
25 |
26 | # Install latest git version
27 | RUN apt-add-repository ppa:git-core/ppa \
28 | && apt-get update \
29 | && apt-get install -y git
30 |
31 | # Copy tar package with tensorflow and tensorflow lite dependencies
32 | COPY r2inference-dependencies-linux-x86_64-v0.1.0.tar.gz /root
33 |
34 | RUN tar -C /root -xzf /root/r2inference-dependencies-linux-x86_64-v0.1.0.tar.gz \
35 | && rm /root/r2inference-dependencies-linux-x86_64-v0.1.0.tar.gz
36 |
37 | CMD ["/bin/bash"]
38 |
--------------------------------------------------------------------------------
/docker/README.md:
--------------------------------------------------------------------------------
1 | ## Prerequisites
2 | * Docker engine. You can find a very detailed installation guide here
3 | https://docs.docker.com/engine/install/ubuntu/
4 |
5 | * Download dependencies tarball (needed by Dockerfile)
6 | https://drive.google.com/file/d/1vi_oqMxt_4fQzRE1nnv5abSDIP4Cpv82/view?usp=sharing
7 |
8 | The tarball should be placed in the same path as the Dockerfile.
9 |
10 | The tarball contains precompiled TensorFlow and TensorFlow Lite libraries
11 | aswell as some resources needed to run a GStreamer pipeline.
12 | It should have the following structure:
13 |
14 | ```
15 | r2inference
16 | ├── backends
17 | │ ├── tensorflow
18 | │ │ └── v1.15.0
19 | │ │ └── libtensorflow-cpu-linux-x86_64-1.15.0.tar.gz
20 | │ └── tflite
21 | │ └── v2.0.1
22 | │ ├── binaries
23 | │ │ └── libtensorflow-lite.a
24 | │ └── include
25 | │ └── tensorflow
26 | │ └── tensorflow
27 | │ ├── core
28 | │ └── lite
29 | └── resources
30 | └── InceptionV1_TensorFlow
31 | ├── Egyptian_cat.jpg
32 | ├── graph_inceptionv1_tensorflow.pb
33 | └── imagenet_labels.txt
34 |
35 | ```
36 |
37 | ## Build instructions
38 | `sudo docker build -t r2inference-ubuntu-16.04 -f Dockerfile-Ubuntu-16.04 .`
39 |
40 | ## Run a container from the image
41 | `sudo docker run -ti -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix r2inference-ubuntu-16.04`
42 |
43 | ## Building GstInference
44 | For instructions on how to build and test the pluging you can refer to:
45 | * The file .github/workflows/main.yml in this repository
46 | * https://developer.ridgerun.com/wiki/index.php?title=GstInference/Getting_started/Building_the_plugin
47 | * https://developer.ridgerun.com/wiki/index.php?title=R2Inference/Getting_started/Building_the_library
48 |
49 | ## Notes
50 | * This Dockerfile creates an image that has been succesfully tested to
51 | build r2inference with TensorFlow backend only.
52 |
--------------------------------------------------------------------------------
/docs/meson.build:
--------------------------------------------------------------------------------
1 | if get_option('enable-gtk-doc')
2 | subdir('plugins')
3 | endif
4 |
--------------------------------------------------------------------------------
/docs/plugins/gst-inference-plugin-sections.txt:
--------------------------------------------------------------------------------
1 |
2 | element-example
3 | example
4 | GstExample
5 |
6 | GstExampleClass
7 | GST_EXAMPLE
8 | GST_EXAMPLE_CAST
9 | GST_IS_EXAMPLE
10 | GST_EXAMPLE_CLASS
11 | GST_IS_EXAMPLE_CLASS
12 | GST_TYPE_EXAMPLE
13 |
14 | gst_example_get_type
15 |
16 |
--------------------------------------------------------------------------------
/docs/plugins/gst-inference-plugin.types:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RidgeRun/gst-inference/56f6fe603f435b684cca87b4bf0084e1025b0599/docs/plugins/gst-inference-plugin.types
--------------------------------------------------------------------------------
/docs/plugins/meson.build:
--------------------------------------------------------------------------------
1 | # Copy the file provided in input: to a file in the build directory with
2 | # the name output: in the current directory.
3 |
4 | types = configure_file(input : 'gst-inference-plugin.types',
5 | output : 'gst-inference-plugin.types',
6 | copy : true)
7 |
8 | version_conf = configuration_data()
9 | version_conf.set('PACKAGE_VERSION', meson.project_version())
10 | version_conf.set('GST_API_VERSION', api_version)
11 | version_conf.set('PACKAGE_NAME', 'GstInference')
12 | version_conf.set('PACKAGE_URL', plugin_url)
13 |
14 | # Compiles and installs gtkdoc documentation into prefix/share/gtk-doc/html.
15 | gnome.gtkdoc('gst-inference-plugin-1.0',
16 | main_sgml : '@0@/gst-inference-plugin-docs.sgml'.format(meson.current_build_dir()),
17 | src_dir : ['@0@/ext/'.format(meson.source_root()), meson.current_build_dir()],
18 | gobject_typesfile : types,
19 | #content_files : [version_entities],
20 | dependencies : [plugin_deps],
21 | install : true)
22 |
--------------------------------------------------------------------------------
/ext/meson.build:
--------------------------------------------------------------------------------
1 | subdir('opencv')
2 | subdir('r2inference')
3 |
--------------------------------------------------------------------------------
/ext/opencv/gstinferenceoverlay.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_INFERENCE_OVERLAY_H_
23 | #define _GST_INFERENCE_OVERLAY_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_INFERENCE_OVERLAY (gst_inference_overlay_get_type())
30 | G_DECLARE_FINAL_TYPE (GstInferenceOverlay, gst_inference_overlay, GST, INFERENCE_OVERLAY, GstInferenceBaseOverlay)
31 |
32 | G_END_DECLS
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/ext/opencv/gstplugin.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifdef HAVE_CONFIG_H
23 | #include "config.h"
24 | #endif
25 |
26 | #include "gstinferenceoverlay.h"
27 |
28 | static gboolean
29 | plugin_init (GstPlugin * plugin)
30 | {
31 | gboolean ret = TRUE;
32 |
33 | ret =
34 | gst_element_register (plugin, "inferenceoverlay", GST_RANK_NONE,
35 | GST_TYPE_INFERENCE_OVERLAY);
36 | if (!ret) {
37 | goto out;
38 | }
39 |
40 | out:
41 | return ret;
42 | }
43 |
44 | GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
45 | GST_VERSION_MINOR,
46 | inferenceoverlayplugin,
47 | "Create overlays on incomming image frames with proper inference metadata",
48 | plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)
49 |
--------------------------------------------------------------------------------
/ext/opencv/meson.build:
--------------------------------------------------------------------------------
1 | gstinference_sources = [
2 | 'gstplugin.cc',
3 | 'gstinferenceoverlay.cc',
4 | ]
5 |
6 | if opencv_dep.found()
7 | opencv_all_dependencies = [gst_base_dep, gst_video_dep, opencv_dep, inferencebaseoverlay_dep, gstinference_dep]
8 |
9 | gstinferenceoverlay = library('gstinferenceoverlayplugin',
10 | gstinference_sources,
11 | cpp_args : cpp_args,
12 | include_directories : [configinc, inference_inc_dir],
13 | dependencies : opencv_all_dependencies,
14 | install : true,
15 | install_dir : plugins_install_dir,
16 | )
17 |
18 | plugins += [gstinferenceoverlay]
19 | else
20 | warning('OpenCV not found in this system. Overlay plug-ins will not be built.')
21 | endif
22 |
--------------------------------------------------------------------------------
/ext/r2inference/gstinceptionv1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | /**
23 | * SECTION:element-gstinceptionv1
24 | *
25 | * The inceptionv1 element allows the user to infer/execute a pretrained model
26 | * based on the GoogLeNet (Inception v1 or Inception v2) architectures on
27 | * incoming image frames.
28 | *
29 | *
30 | * Example launch line
31 | * |[
32 | * gst-launch-1.0 -v videotestsrc ! inceptionv1 ! xvimagesink
33 | * ]|
34 | * Process video frames from the camera using a GoogLeNet (Inception v1 or
35 | * Inception v2) model.
36 | *
37 | */
38 |
39 | #ifdef HAVE_CONFIG_H
40 | #include "config.h"
41 | #endif
42 |
43 | #include "gstinceptionv1.h"
44 | #include "gst/r2inference/gstinferencemeta.h"
45 | #include
46 | #include "gst/r2inference/gstinferencepreprocess.h"
47 | #include "gst/r2inference/gstinferencepostprocess.h"
48 | #include "gst/r2inference/gstinferencedebug.h"
49 |
50 | GST_DEBUG_CATEGORY_STATIC (gst_inceptionv1_debug_category);
51 | #define GST_CAT_DEFAULT gst_inceptionv1_debug_category
52 |
53 | #define MEAN 128.0
54 | #define STD 1/128.0
55 | #define MODEL_CHANNELS 3
56 |
57 | static gboolean gst_inceptionv1_preprocess (GstVideoInference * vi,
58 | GstVideoFrame * inframe, GstVideoFrame * outframe);
59 | static gboolean gst_inceptionv1_postprocess (GstVideoInference * vi,
60 | const gpointer prediction, gsize predsize, GstMeta * meta_model,
61 | GstVideoInfo * info_model, gboolean * valid_prediction,
62 | gchar ** labels_list, gint num_labels);
63 | static gboolean gst_inceptionv1_start (GstVideoInference * vi);
64 | static gboolean gst_inceptionv1_stop (GstVideoInference * vi);
65 |
66 | enum
67 | {
68 | PROP_0
69 | };
70 |
71 | /* pad templates */
72 | #define CAPS \
73 | "video/x-raw, " \
74 | "width=224, " \
75 | "height=224, " \
76 | "format={RGB, RGBx, RGBA, BGR, BGRx, BGRA, xRGB, ARGB, xBGR, ABGR}"
77 |
78 | static GstStaticPadTemplate sink_model_factory =
79 | GST_STATIC_PAD_TEMPLATE ("sink_model",
80 | GST_PAD_SINK,
81 | GST_PAD_REQUEST,
82 | GST_STATIC_CAPS (CAPS)
83 | );
84 |
85 | static GstStaticPadTemplate src_model_factory =
86 | GST_STATIC_PAD_TEMPLATE ("src_model",
87 | GST_PAD_SRC,
88 | GST_PAD_REQUEST,
89 | GST_STATIC_CAPS (CAPS)
90 | );
91 |
92 | struct _GstInceptionv1
93 | {
94 | GstVideoInference parent;
95 | };
96 |
97 | struct _GstInceptionv1Class
98 | {
99 | GstVideoInferenceClass parent;
100 | };
101 |
102 | /* class initialization */
103 |
104 | G_DEFINE_TYPE_WITH_CODE (GstInceptionv1, gst_inceptionv1,
105 | GST_TYPE_VIDEO_INFERENCE,
106 | GST_DEBUG_CATEGORY_INIT (gst_inceptionv1_debug_category, "inceptionv1", 0,
107 | "debug category for inceptionv1 element"));
108 |
109 | static void
110 | gst_inceptionv1_class_init (GstInceptionv1Class * klass)
111 | {
112 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
113 | GstVideoInferenceClass *vi_class = GST_VIDEO_INFERENCE_CLASS (klass);
114 |
115 | gst_element_class_add_static_pad_template (element_class,
116 | &sink_model_factory);
117 | gst_element_class_add_static_pad_template (element_class, &src_model_factory);
118 |
119 | gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
120 | "inceptionv1", "Filter",
121 | "Infers incoming image frames using a pretrained GoogLeNet (Inception v1 or Inception v2) model",
122 | "Carlos Rodriguez \n\t\t\t"
123 | " Jose Jimenez \n\t\t\t"
124 | " Michael Gruner \n\t\t\t"
125 | " Mauricio Montero ");
126 |
127 | vi_class->start = GST_DEBUG_FUNCPTR (gst_inceptionv1_start);
128 | vi_class->stop = GST_DEBUG_FUNCPTR (gst_inceptionv1_stop);
129 | vi_class->preprocess = GST_DEBUG_FUNCPTR (gst_inceptionv1_preprocess);
130 | vi_class->postprocess = GST_DEBUG_FUNCPTR (gst_inceptionv1_postprocess);
131 | }
132 |
133 | static void
134 | gst_inceptionv1_init (GstInceptionv1 * inceptionv1)
135 | {
136 | }
137 |
138 | static gboolean
139 | gst_inceptionv1_preprocess (GstVideoInference * vi,
140 | GstVideoFrame * inframe, GstVideoFrame * outframe)
141 | {
142 | GST_LOG_OBJECT (vi, "Preprocess");
143 | return gst_normalize (inframe, outframe, MEAN, STD, MODEL_CHANNELS);
144 | }
145 |
146 | static gboolean
147 | gst_inceptionv1_postprocess (GstVideoInference * vi, const gpointer prediction,
148 | gsize predsize, GstMeta * meta_model, GstVideoInfo * info_model,
149 | gboolean * valid_prediction, gchar ** labels_list, gint num_labels)
150 | {
151 | GstInferenceMeta *imeta = NULL;
152 | GstInferenceClassification *c = NULL;
153 | GstInferencePrediction *root = NULL;
154 | gboolean ret = TRUE;
155 |
156 | g_return_val_if_fail (vi != NULL, FALSE);
157 | g_return_val_if_fail (meta_model != NULL, FALSE);
158 | g_return_val_if_fail (info_model != NULL, FALSE);
159 |
160 | GST_LOG_OBJECT (vi, "Postprocess Meta");
161 |
162 | imeta = (GstInferenceMeta *) meta_model;
163 |
164 | root = imeta->prediction;
165 | if (!root) {
166 | GST_ERROR_OBJECT (vi, "Prediction is not part of the Inference Meta");
167 | ret = FALSE;
168 | goto out;
169 | }
170 |
171 | c = gst_create_class_from_prediction (vi, prediction, predsize, labels_list,
172 | num_labels);
173 | gst_inference_prediction_append_classification (root, c);
174 | gst_inference_print_predictions (vi, gst_inceptionv1_debug_category, imeta);
175 |
176 | *valid_prediction = TRUE;
177 |
178 | out:
179 | return ret;
180 | }
181 |
182 | static gboolean
183 | gst_inceptionv1_start (GstVideoInference * vi)
184 | {
185 | GST_INFO_OBJECT (vi, "Starting Inception v1");
186 |
187 | return TRUE;
188 | }
189 |
190 | static gboolean
191 | gst_inceptionv1_stop (GstVideoInference * vi)
192 | {
193 | GST_INFO_OBJECT (vi, "Stopping Inception v1");
194 |
195 | return TRUE;
196 | }
197 |
--------------------------------------------------------------------------------
/ext/r2inference/gstinceptionv1.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_INCEPTIONV1_H_
23 | #define _GST_INCEPTIONV1_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_INCEPTIONV1 gst_inceptionv1_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstInceptionv1, gst_inceptionv1, GST, INCEPTIONV1, GstVideoInference)
31 |
32 | G_END_DECLS
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/ext/r2inference/gstinceptionv2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | /**
23 | * SECTION:element-gstinceptionv2
24 | *
25 | * The inceptionv2 element allows the user to infer/execute a pretrained model
26 | * based on the GoogLeNet (Inception v1 or Inception v2) architectures on
27 | * incoming image frames.
28 | *
29 | *
30 | * Example launch line
31 | * |[
32 | * gst-launch-1.0 -v videotestsrc ! inceptionv2 ! xvimagesink
33 | * ]|
34 | * Process video frames from the camera using a GoogLeNet (Inception v1 or
35 | * Inception v2) model.
36 | *
37 | */
38 |
39 | #ifdef HAVE_CONFIG_H
40 | #include "config.h"
41 | #endif
42 |
43 | #include "gstinceptionv2.h"
44 | #include "gst/r2inference/gstinferencemeta.h"
45 | #include
46 | #include "gst/r2inference/gstinferencepreprocess.h"
47 | #include "gst/r2inference/gstinferencepostprocess.h"
48 | #include "gst/r2inference/gstinferencedebug.h"
49 |
50 | GST_DEBUG_CATEGORY_STATIC (gst_inceptionv2_debug_category);
51 | #define GST_CAT_DEFAULT gst_inceptionv2_debug_category
52 |
53 | #define MEAN 128.0
54 | #define STD 1/128.0
55 | #define MODEL_CHANNELS 3
56 |
57 | /* prototypes */
58 | static void gst_inceptionv2_set_property (GObject * object,
59 | guint property_id, const GValue * value, GParamSpec * pspec);
60 | static void gst_inceptionv2_get_property (GObject * object,
61 | guint property_id, GValue * value, GParamSpec * pspec);
62 | static void gst_inceptionv2_dispose (GObject * object);
63 | static void gst_inceptionv2_finalize (GObject * object);
64 |
65 | static gboolean gst_inceptionv2_preprocess (GstVideoInference * vi,
66 | GstVideoFrame * inframe, GstVideoFrame * outframe);
67 | static gboolean gst_inceptionv2_postprocess (GstVideoInference * vi,
68 | const gpointer prediction, gsize predsize, GstMeta * meta_model,
69 | GstVideoInfo * info_model, gboolean * valid_prediction,
70 | gchar ** labels_list, gint num_labels);
71 | static gboolean gst_inceptionv2_start (GstVideoInference * vi);
72 | static gboolean gst_inceptionv2_stop (GstVideoInference * vi);
73 |
74 | enum
75 | {
76 | PROP_0
77 | };
78 |
79 | /* pad templates */
80 | #define CAPS \
81 | "video/x-raw, " \
82 | "width=224, " \
83 | "height=224, " \
84 | "format={RGB, RGBx, RGBA, BGR, BGRx, BGRA, xRGB, ARGB, xBGR, ABGR}"
85 |
86 | static GstStaticPadTemplate sink_model_factory =
87 | GST_STATIC_PAD_TEMPLATE ("sink_model",
88 | GST_PAD_SINK,
89 | GST_PAD_REQUEST,
90 | GST_STATIC_CAPS (CAPS)
91 | );
92 |
93 | static GstStaticPadTemplate src_model_factory =
94 | GST_STATIC_PAD_TEMPLATE ("src_model",
95 | GST_PAD_SRC,
96 | GST_PAD_REQUEST,
97 | GST_STATIC_CAPS (CAPS)
98 | );
99 |
100 | struct _GstInceptionv2
101 | {
102 | GstVideoInference parent;
103 | };
104 |
105 | struct _GstInceptionv2Class
106 | {
107 | GstVideoInferenceClass parent;
108 | };
109 |
110 | /* class initialization */
111 |
112 | G_DEFINE_TYPE_WITH_CODE (GstInceptionv2, gst_inceptionv2,
113 | GST_TYPE_VIDEO_INFERENCE,
114 | GST_DEBUG_CATEGORY_INIT (gst_inceptionv2_debug_category, "inceptionv2", 0,
115 | "debug category for inceptionv2 element"));
116 |
117 | static void
118 | gst_inceptionv2_class_init (GstInceptionv2Class * klass)
119 | {
120 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
121 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
122 | GstVideoInferenceClass *vi_class = GST_VIDEO_INFERENCE_CLASS (klass);
123 |
124 | gst_element_class_add_static_pad_template (element_class,
125 | &sink_model_factory);
126 | gst_element_class_add_static_pad_template (element_class, &src_model_factory);
127 |
128 | gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
129 | "inceptionv2", "Filter",
130 | "Infers incoming image frames using a pretrained GoogLeNet (Inception v1 or Inception v2) model",
131 | "Carlos Rodriguez \n\t\t\t"
132 | " Jose Jimenez \n\t\t\t"
133 | " Michael Gruner ");
134 |
135 | gobject_class->set_property = gst_inceptionv2_set_property;
136 | gobject_class->get_property = gst_inceptionv2_get_property;
137 | gobject_class->dispose = gst_inceptionv2_dispose;
138 | gobject_class->finalize = gst_inceptionv2_finalize;
139 |
140 | vi_class->start = GST_DEBUG_FUNCPTR (gst_inceptionv2_start);
141 | vi_class->stop = GST_DEBUG_FUNCPTR (gst_inceptionv2_stop);
142 | vi_class->preprocess = GST_DEBUG_FUNCPTR (gst_inceptionv2_preprocess);
143 | vi_class->postprocess = GST_DEBUG_FUNCPTR (gst_inceptionv2_postprocess);
144 | }
145 |
146 | static void
147 | gst_inceptionv2_init (GstInceptionv2 * inceptionv2)
148 | {
149 | }
150 |
151 | void
152 | gst_inceptionv2_set_property (GObject * object, guint property_id,
153 | const GValue * value, GParamSpec * pspec)
154 | {
155 | GstInceptionv2 *inceptionv2 = GST_INCEPTIONV2 (object);
156 |
157 | GST_DEBUG_OBJECT (inceptionv2, "set_property");
158 |
159 | switch (property_id) {
160 | default:
161 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
162 | break;
163 | }
164 | }
165 |
166 | void
167 | gst_inceptionv2_get_property (GObject * object, guint property_id,
168 | GValue * value, GParamSpec * pspec)
169 | {
170 | GstInceptionv2 *inceptionv2 = GST_INCEPTIONV2 (object);
171 |
172 | GST_DEBUG_OBJECT (inceptionv2, "get_property");
173 |
174 | switch (property_id) {
175 | default:
176 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
177 | break;
178 | }
179 | }
180 |
181 | void
182 | gst_inceptionv2_dispose (GObject * object)
183 | {
184 | GstInceptionv2 *inceptionv2 = GST_INCEPTIONV2 (object);
185 |
186 | GST_DEBUG_OBJECT (inceptionv2, "dispose");
187 |
188 | /* clean up as possible. may be called multiple times */
189 |
190 | G_OBJECT_CLASS (gst_inceptionv2_parent_class)->dispose (object);
191 | }
192 |
193 | void
194 | gst_inceptionv2_finalize (GObject * object)
195 | {
196 | GstInceptionv2 *inceptionv2 = GST_INCEPTIONV2 (object);
197 |
198 | GST_DEBUG_OBJECT (inceptionv2, "finalize");
199 |
200 | /* clean up object here */
201 |
202 | G_OBJECT_CLASS (gst_inceptionv2_parent_class)->finalize (object);
203 | }
204 |
205 | static gboolean
206 | gst_inceptionv2_preprocess (GstVideoInference * vi,
207 | GstVideoFrame * inframe, GstVideoFrame * outframe)
208 | {
209 | GST_LOG_OBJECT (vi, "Preprocess");
210 | return gst_normalize (inframe, outframe, MEAN, STD, MODEL_CHANNELS);
211 | }
212 |
213 | static gboolean
214 | gst_inceptionv2_postprocess (GstVideoInference * vi, const gpointer prediction,
215 | gsize predsize, GstMeta * meta_model, GstVideoInfo * info_model,
216 | gboolean * valid_prediction, gchar ** labels_list, gint num_labels)
217 | {
218 | GstInferenceMeta *imeta = NULL;
219 | GstInferenceClassification *c = NULL;
220 | GstInferencePrediction *root = NULL;
221 | gboolean ret = TRUE;
222 |
223 | g_return_val_if_fail (vi != NULL, FALSE);
224 | g_return_val_if_fail (meta_model != NULL, FALSE);
225 | g_return_val_if_fail (info_model != NULL, FALSE);
226 |
227 | GST_LOG_OBJECT (vi, "Postprocess Meta");
228 |
229 | imeta = (GstInferenceMeta *) meta_model;
230 |
231 | root = imeta->prediction;
232 | if (!root) {
233 | GST_ERROR_OBJECT (vi, "Prediction is not part of the Inference Meta");
234 | ret = FALSE;
235 | goto out;
236 | }
237 |
238 | c = gst_create_class_from_prediction (vi, prediction, predsize, labels_list,
239 | num_labels);
240 | gst_inference_prediction_append_classification (root, c);
241 | gst_inference_print_predictions (vi, gst_inceptionv2_debug_category, imeta);
242 |
243 | *valid_prediction = TRUE;
244 |
245 | out:
246 | return ret;
247 | }
248 |
249 | static gboolean
250 | gst_inceptionv2_start (GstVideoInference * vi)
251 | {
252 | GST_INFO_OBJECT (vi, "Starting Inception v2");
253 |
254 | return TRUE;
255 | }
256 |
257 | static gboolean
258 | gst_inceptionv2_stop (GstVideoInference * vi)
259 | {
260 | GST_INFO_OBJECT (vi, "Stopping Inception v2");
261 |
262 | return TRUE;
263 | }
264 |
--------------------------------------------------------------------------------
/ext/r2inference/gstinceptionv2.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_INCEPTIONV2_H_
23 | #define _GST_INCEPTIONV2_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_INCEPTIONV2 gst_inceptionv2_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstInceptionv2, gst_inceptionv2, GST, INCEPTIONV2, GstVideoInference)
31 |
32 | G_END_DECLS
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/ext/r2inference/gstinceptionv3.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | /**
23 | * SECTION:element-gstinceptionv4
24 | *
25 | * The inceptionv3 element allows the user to infer/execute a pretrained model
26 | * based on the GoogLeNet (Inception v3 or Inception v4) architecture on
27 | * incoming image frames.
28 | *
29 | *
30 | * Example launch line
31 | * |[
32 | * gst-launch-1.0 -v videotestsrc ! inceptionv3 ! xvimagesink
33 | * ]|
34 | * Process video frames from the camera using a GoogLeNet (Inception v3 or Inception v4) model.
35 | *
36 | */
37 |
38 | #ifdef HAVE_CONFIG_H
39 | #include "config.h"
40 | #endif
41 |
42 | #include "gstinceptionv3.h"
43 | #include "gst/r2inference/gstinferencemeta.h"
44 | #include
45 | #include "gst/r2inference/gstinferencepreprocess.h"
46 | #include "gst/r2inference/gstinferencepostprocess.h"
47 | #include "gst/r2inference/gstinferencedebug.h"
48 |
49 | GST_DEBUG_CATEGORY_STATIC (gst_inceptionv3_debug_category);
50 | #define GST_CAT_DEFAULT gst_inceptionv3_debug_category
51 |
52 | #define MEAN 128.0
53 | #define STD 1/128.0
54 | #define MODEL_CHANNELS 3
55 |
56 | static gboolean gst_inceptionv3_preprocess (GstVideoInference * vi,
57 | GstVideoFrame * inframe, GstVideoFrame * outframe);
58 | static gboolean gst_inceptionv3_postprocess (GstVideoInference * vi,
59 | const gpointer prediction, gsize predsize, GstMeta * meta_model,
60 | GstVideoInfo * info_model, gboolean * valid_prediction,
61 | gchar ** labels_list, gint num_labels);
62 | static gboolean gst_inceptionv3_start (GstVideoInference * vi);
63 | static gboolean gst_inceptionv3_stop (GstVideoInference * vi);
64 |
65 | enum
66 | {
67 | PROP_0
68 | };
69 |
70 | /* pad templates */
71 | #define CAPS \
72 | "video/x-raw, " \
73 | "width=299, " \
74 | "height=299, " \
75 | "format={RGB, RGBx, RGBA, BGR, BGRx, BGRA, xRGB, ARGB, xBGR, ABGR}"
76 |
77 | static GstStaticPadTemplate sink_model_factory =
78 | GST_STATIC_PAD_TEMPLATE ("sink_model",
79 | GST_PAD_SINK,
80 | GST_PAD_REQUEST,
81 | GST_STATIC_CAPS (CAPS)
82 | );
83 |
84 | static GstStaticPadTemplate src_model_factory =
85 | GST_STATIC_PAD_TEMPLATE ("src_model",
86 | GST_PAD_SRC,
87 | GST_PAD_REQUEST,
88 | GST_STATIC_CAPS (CAPS)
89 | );
90 |
91 | struct _GstInceptionv3
92 | {
93 | GstVideoInference parent;
94 | };
95 |
96 | struct _GstInceptionv3Class
97 | {
98 | GstVideoInferenceClass parent;
99 | };
100 |
101 | /* class initialization */
102 |
103 | G_DEFINE_TYPE_WITH_CODE (GstInceptionv3, gst_inceptionv3,
104 | GST_TYPE_VIDEO_INFERENCE,
105 | GST_DEBUG_CATEGORY_INIT (gst_inceptionv3_debug_category, "inceptionv3", 0,
106 | "debug category for inceptionv3 element"));
107 |
108 | static void
109 | gst_inceptionv3_class_init (GstInceptionv3Class * klass)
110 | {
111 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
112 | GstVideoInferenceClass *vi_class = GST_VIDEO_INFERENCE_CLASS (klass);
113 |
114 | gst_element_class_add_static_pad_template (element_class,
115 | &sink_model_factory);
116 | gst_element_class_add_static_pad_template (element_class, &src_model_factory);
117 |
118 | gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
119 | "inceptionv3", "Filter",
120 | "Infers incoming image frames using a pretrained GoogLeNet (Inception v3 or Inception v4) model",
121 | "Carlos Rodriguez \n\t\t\t"
122 | " Jose Jimenez \n\t\t\t"
123 | " Michael Gruner \n\t\t\t"
124 | " Mauricio Montero ");
125 |
126 | vi_class->start = GST_DEBUG_FUNCPTR (gst_inceptionv3_start);
127 | vi_class->stop = GST_DEBUG_FUNCPTR (gst_inceptionv3_stop);
128 | vi_class->preprocess = GST_DEBUG_FUNCPTR (gst_inceptionv3_preprocess);
129 | vi_class->postprocess = GST_DEBUG_FUNCPTR (gst_inceptionv3_postprocess);
130 | }
131 |
132 | static void
133 | gst_inceptionv3_init (GstInceptionv3 * inceptionv3)
134 | {
135 | }
136 |
137 | static gboolean
138 | gst_inceptionv3_preprocess (GstVideoInference * vi,
139 | GstVideoFrame * inframe, GstVideoFrame * outframe)
140 | {
141 | GST_LOG_OBJECT (vi, "Preprocess");
142 | return gst_normalize (inframe, outframe, MEAN, STD, MODEL_CHANNELS);
143 | }
144 |
145 | static gboolean
146 | gst_inceptionv3_postprocess (GstVideoInference * vi, const gpointer prediction,
147 | gsize predsize, GstMeta * meta_model, GstVideoInfo * info_model,
148 | gboolean * valid_prediction, gchar ** labels_list, gint num_labels)
149 | {
150 | GstInferenceMeta *imeta = NULL;
151 | GstInferenceClassification *c = NULL;
152 | GstInferencePrediction *root = NULL;
153 | gboolean ret = TRUE;
154 |
155 | g_return_val_if_fail (vi != NULL, FALSE);
156 | g_return_val_if_fail (meta_model != NULL, FALSE);
157 | g_return_val_if_fail (info_model != NULL, FALSE);
158 |
159 | GST_LOG_OBJECT (vi, "Postprocess Meta");
160 |
161 | imeta = (GstInferenceMeta *) meta_model;
162 |
163 | root = imeta->prediction;
164 | if (!root) {
165 | GST_ERROR_OBJECT (vi, "Prediction is not part of the Inference Meta");
166 | ret = FALSE;
167 | goto out;
168 | }
169 |
170 | c = gst_create_class_from_prediction (vi, prediction, predsize, labels_list,
171 | num_labels);
172 | gst_inference_prediction_append_classification (root, c);
173 | gst_inference_print_predictions (vi, gst_inceptionv3_debug_category, imeta);
174 |
175 | *valid_prediction = TRUE;
176 |
177 | out:
178 | return ret;
179 | }
180 |
181 | static gboolean
182 | gst_inceptionv3_start (GstVideoInference * vi)
183 | {
184 | GST_INFO_OBJECT (vi, "Starting Inception v3");
185 |
186 | return TRUE;
187 | }
188 |
189 | static gboolean
190 | gst_inceptionv3_stop (GstVideoInference * vi)
191 | {
192 | GST_INFO_OBJECT (vi, "Stopping Inception v3");
193 |
194 | return TRUE;
195 | }
196 |
--------------------------------------------------------------------------------
/ext/r2inference/gstinceptionv3.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_INCEPTIONV3_H_
23 | #define _GST_INCEPTIONV3_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_INCEPTIONV3 gst_inceptionv3_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstInceptionv3, gst_inceptionv3, GST, INCEPTIONV3, GstVideoInference)
31 |
32 | G_END_DECLS
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/ext/r2inference/gstinceptionv4.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | /**
23 | * SECTION:element-gstinceptionv4
24 | *
25 | * The inceptionv4 element allows the user to infer/execute a pretrained model
26 | * based on the GoogLeNet (Inception v3 or Inception v4) architecture on
27 | * incoming image frames.
28 | *
29 | *
30 | * Example launch line
31 | * |[
32 | * gst-launch-1.0 -v videotestsrc ! inceptionv4 ! xvimagesink
33 | * ]|
34 | * Process video frames from the camera using a GoogLeNet (Inception v3 or Inception v4) model.
35 | *
36 | */
37 |
38 | #ifdef HAVE_CONFIG_H
39 | #include "config.h"
40 | #endif
41 |
42 | #include "gstinceptionv4.h"
43 | #include "gst/r2inference/gstinferencemeta.h"
44 | #include
45 | #include "gst/r2inference/gstinferencepreprocess.h"
46 | #include "gst/r2inference/gstinferencepostprocess.h"
47 | #include "gst/r2inference/gstinferencedebug.h"
48 |
49 | GST_DEBUG_CATEGORY_STATIC (gst_inceptionv4_debug_category);
50 | #define GST_CAT_DEFAULT gst_inceptionv4_debug_category
51 |
52 | #define MEAN 128.0
53 | #define STD 1/128.0
54 | #define MODEL_CHANNELS 3
55 |
56 | /* prototypes */
57 | static void gst_inceptionv4_set_property (GObject * object,
58 | guint property_id, const GValue * value, GParamSpec * pspec);
59 | static void gst_inceptionv4_get_property (GObject * object,
60 | guint property_id, GValue * value, GParamSpec * pspec);
61 | static void gst_inceptionv4_dispose (GObject * object);
62 | static void gst_inceptionv4_finalize (GObject * object);
63 | static gboolean gst_inceptionv4_preprocess (GstVideoInference * vi,
64 | GstVideoFrame * inframe, GstVideoFrame * outframe);
65 | static gboolean gst_inceptionv4_postprocess (GstVideoInference * vi,
66 | const gpointer prediction, gsize predsize, GstMeta * meta_model,
67 | GstVideoInfo * info_model, gboolean * valid_prediction,
68 | gchar ** labels_list, gint num_labels);
69 | static gboolean gst_inceptionv4_start (GstVideoInference * vi);
70 | static gboolean gst_inceptionv4_stop (GstVideoInference * vi);
71 |
72 | enum
73 | {
74 | PROP_0
75 | };
76 |
77 | /* pad templates */
78 | #define CAPS \
79 | "video/x-raw, " \
80 | "width=299, " \
81 | "height=299, " \
82 | "format={RGB, RGBx, RGBA, BGR, BGRx, BGRA, xRGB, ARGB, xBGR, ABGR}"
83 |
84 | static GstStaticPadTemplate sink_model_factory =
85 | GST_STATIC_PAD_TEMPLATE ("sink_model",
86 | GST_PAD_SINK,
87 | GST_PAD_REQUEST,
88 | GST_STATIC_CAPS (CAPS)
89 | );
90 |
91 | static GstStaticPadTemplate src_model_factory =
92 | GST_STATIC_PAD_TEMPLATE ("src_model",
93 | GST_PAD_SRC,
94 | GST_PAD_REQUEST,
95 | GST_STATIC_CAPS (CAPS)
96 | );
97 |
98 | struct _GstInceptionv4
99 | {
100 | GstVideoInference parent;
101 | };
102 |
103 | struct _GstInceptionv4Class
104 | {
105 | GstVideoInferenceClass parent;
106 | };
107 |
108 | /* class initialization */
109 |
110 | G_DEFINE_TYPE_WITH_CODE (GstInceptionv4, gst_inceptionv4,
111 | GST_TYPE_VIDEO_INFERENCE,
112 | GST_DEBUG_CATEGORY_INIT (gst_inceptionv4_debug_category, "inceptionv4", 0,
113 | "debug category for inceptionv4 element"));
114 |
115 | static void
116 | gst_inceptionv4_class_init (GstInceptionv4Class * klass)
117 | {
118 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
119 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
120 | GstVideoInferenceClass *vi_class = GST_VIDEO_INFERENCE_CLASS (klass);
121 |
122 | gst_element_class_add_static_pad_template (element_class,
123 | &sink_model_factory);
124 | gst_element_class_add_static_pad_template (element_class, &src_model_factory);
125 |
126 | gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
127 | "inceptionv4", "Filter",
128 | "Infers incoming image frames using a pretrained GoogLeNet (Inception v3 or Inception v4) model",
129 | "Carlos Rodriguez \n\t\t\t"
130 | " Jose Jimenez \n\t\t\t"
131 | " Michael Gruner ");
132 |
133 | gobject_class->set_property = gst_inceptionv4_set_property;
134 | gobject_class->get_property = gst_inceptionv4_get_property;
135 | gobject_class->dispose = gst_inceptionv4_dispose;
136 | gobject_class->finalize = gst_inceptionv4_finalize;
137 |
138 | vi_class->start = GST_DEBUG_FUNCPTR (gst_inceptionv4_start);
139 | vi_class->stop = GST_DEBUG_FUNCPTR (gst_inceptionv4_stop);
140 | vi_class->preprocess = GST_DEBUG_FUNCPTR (gst_inceptionv4_preprocess);
141 | vi_class->postprocess = GST_DEBUG_FUNCPTR (gst_inceptionv4_postprocess);
142 | }
143 |
144 | static void
145 | gst_inceptionv4_init (GstInceptionv4 * inceptionv4)
146 | {
147 | }
148 |
149 | void
150 | gst_inceptionv4_set_property (GObject * object, guint property_id,
151 | const GValue * value, GParamSpec * pspec)
152 | {
153 | GstInceptionv4 *inceptionv4 = GST_INCEPTIONV4 (object);
154 |
155 | GST_DEBUG_OBJECT (inceptionv4, "set_property");
156 |
157 | switch (property_id) {
158 | default:
159 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
160 | break;
161 | }
162 | }
163 |
164 | void
165 | gst_inceptionv4_get_property (GObject * object, guint property_id,
166 | GValue * value, GParamSpec * pspec)
167 | {
168 | GstInceptionv4 *inceptionv4 = GST_INCEPTIONV4 (object);
169 |
170 | GST_DEBUG_OBJECT (inceptionv4, "get_property");
171 |
172 | switch (property_id) {
173 | default:
174 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
175 | break;
176 | }
177 | }
178 |
179 | void
180 | gst_inceptionv4_dispose (GObject * object)
181 | {
182 | GstInceptionv4 *inceptionv4 = GST_INCEPTIONV4 (object);
183 |
184 | GST_DEBUG_OBJECT (inceptionv4, "dispose");
185 |
186 | /* clean up as possible. may be called multiple times */
187 |
188 | G_OBJECT_CLASS (gst_inceptionv4_parent_class)->dispose (object);
189 | }
190 |
191 | void
192 | gst_inceptionv4_finalize (GObject * object)
193 | {
194 | GstInceptionv4 *inceptionv4 = GST_INCEPTIONV4 (object);
195 |
196 | GST_DEBUG_OBJECT (inceptionv4, "finalize");
197 |
198 | /* clean up object here */
199 |
200 | G_OBJECT_CLASS (gst_inceptionv4_parent_class)->finalize (object);
201 | }
202 |
203 | static gboolean
204 | gst_inceptionv4_preprocess (GstVideoInference * vi,
205 | GstVideoFrame * inframe, GstVideoFrame * outframe)
206 | {
207 | GST_LOG_OBJECT (vi, "Preprocess");
208 | return gst_normalize (inframe, outframe, MEAN, STD, MODEL_CHANNELS);
209 | }
210 |
211 | static gboolean
212 | gst_inceptionv4_postprocess (GstVideoInference * vi, const gpointer prediction,
213 | gsize predsize, GstMeta * meta_model, GstVideoInfo * info_model,
214 | gboolean * valid_prediction, gchar ** labels_list, gint num_labels)
215 | {
216 | GstInferenceMeta *imeta = NULL;
217 | GstInferenceClassification *c = NULL;
218 | GstInferencePrediction *root = NULL;
219 | gboolean ret = TRUE;
220 |
221 | g_return_val_if_fail (vi != NULL, FALSE);
222 | g_return_val_if_fail (meta_model != NULL, FALSE);
223 | g_return_val_if_fail (info_model != NULL, FALSE);
224 |
225 | GST_LOG_OBJECT (vi, "Postprocess Meta");
226 |
227 | imeta = (GstInferenceMeta *) meta_model;
228 |
229 | root = imeta->prediction;
230 | if (!root) {
231 | GST_ERROR_OBJECT (vi, "Prediction is not part of the Inference Meta");
232 | ret = FALSE;
233 | goto out;
234 | }
235 |
236 | c = gst_create_class_from_prediction (vi, prediction, predsize, labels_list,
237 | num_labels);
238 | gst_inference_prediction_append_classification (root, c);
239 | gst_inference_print_predictions (vi, gst_inceptionv4_debug_category, imeta);
240 |
241 | *valid_prediction = TRUE;
242 |
243 | out:
244 | return ret;
245 | }
246 |
247 | static gboolean
248 | gst_inceptionv4_start (GstVideoInference * vi)
249 | {
250 | GST_INFO_OBJECT (vi, "Starting Inception v4");
251 |
252 | return TRUE;
253 | }
254 |
255 | static gboolean
256 | gst_inceptionv4_stop (GstVideoInference * vi)
257 | {
258 | GST_INFO_OBJECT (vi, "Stopping Inception v4");
259 |
260 | return TRUE;
261 | }
262 |
--------------------------------------------------------------------------------
/ext/r2inference/gstinceptionv4.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_INCEPTIONV4_H_
23 | #define _GST_INCEPTIONV4_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_INCEPTIONV4 gst_inceptionv4_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstInceptionv4, gst_inceptionv4, GST, INCEPTIONV4, GstVideoInference)
31 |
32 | G_END_DECLS
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/ext/r2inference/gstinference.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifdef HAVE_CONFIG_H
23 | #include "config.h"
24 | #endif
25 |
26 | #include "gstinceptionv1.h"
27 | #include "gstinceptionv2.h"
28 | #include "gstinceptionv3.h"
29 | #include "gstinceptionv4.h"
30 | #include "gsttinyyolov2.h"
31 | #include "gsttinyyolov3.h"
32 | #include "gstresnet50v1.h"
33 | #include "gstmobilenetv2.h"
34 | #include "gstmobilenetv2ssd.h"
35 | #include "gstrosetta.h"
36 |
37 | static gboolean
38 | plugin_init (GstPlugin * plugin)
39 | {
40 |
41 | /* FIXME Remember to set the rank if it's an element that is meant
42 | to be autoplugged by decodebin. */
43 | gboolean ret = TRUE;
44 |
45 | ret = gst_element_register (plugin, "resnet50v1", GST_RANK_NONE,
46 | GST_TYPE_RESNET50V1);
47 | if (!ret) {
48 | goto out;
49 | }
50 |
51 | ret = gst_element_register (plugin, "inceptionv1", GST_RANK_NONE,
52 | GST_TYPE_INCEPTIONV1);
53 | if (!ret) {
54 | goto out;
55 | }
56 |
57 | ret = gst_element_register (plugin, "inceptionv2", GST_RANK_NONE,
58 | GST_TYPE_INCEPTIONV2);
59 | if (!ret) {
60 | goto out;
61 | }
62 |
63 | ret = gst_element_register (plugin, "mobilenetv2", GST_RANK_NONE,
64 | GST_TYPE_MOBILENETV2);
65 | if (!ret) {
66 | goto out;
67 | }
68 |
69 | ret = gst_element_register (plugin, "inceptionv3", GST_RANK_NONE,
70 | GST_TYPE_INCEPTIONV3);
71 | if (!ret) {
72 | goto out;
73 | }
74 |
75 | ret = gst_element_register (plugin, "inceptionv4", GST_RANK_NONE,
76 | GST_TYPE_INCEPTIONV4);
77 | if (!ret) {
78 | goto out;
79 | }
80 |
81 | ret = gst_element_register (plugin, "tinyyolov2", GST_RANK_NONE,
82 | GST_TYPE_TINYYOLOV2);
83 | if (!ret) {
84 | goto out;
85 | }
86 |
87 | ret = gst_element_register (plugin, "tinyyolov3", GST_RANK_NONE,
88 | GST_TYPE_TINYYOLOV3);
89 | if (!ret) {
90 | goto out;
91 | }
92 |
93 | ret = gst_element_register (plugin, "mobilenetv2ssd", GST_RANK_NONE,
94 | GST_TYPE_MOBILENETV2SSD);
95 | if (!ret) {
96 | goto out;
97 | }
98 |
99 | ret = gst_element_register (plugin, "rosetta", GST_RANK_NONE,
100 | GST_TYPE_ROSETTA);
101 | if (!ret) {
102 | goto out;
103 | }
104 |
105 | out:
106 | return ret;
107 | }
108 |
109 | GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
110 | GST_VERSION_MINOR,
111 | inference,
112 | "Infer pre-trained model on incomming image frames on a variety of architectures and different backends",
113 | plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)
114 |
--------------------------------------------------------------------------------
/ext/r2inference/gstmobilenetv2.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | /**
23 | * SECTION:element-gstmobilenetv2
24 | *
25 | * The mobilenetv2 element allows the user to infer/execute a pretrained model
26 | * based on the mobilenetv2 architectures on incoming image frames.
27 | *
28 | *
29 | * Example launch line
30 | * |[
31 | * gst-launch-1.0 -v videotestsrc ! mobilenetv2 ! xvimagesink
32 | * ]|
33 | * Process video frames from the camera using a mobilenetv2 model.
34 | *
35 | */
36 |
37 | #ifdef HAVE_CONFIG_H
38 | #include "config.h"
39 | #endif
40 |
41 | #include "gstmobilenetv2.h"
42 | #include "gst/r2inference/gstinferencemeta.h"
43 | #include
44 | #include "gst/r2inference/gstinferencepreprocess.h"
45 | #include "gst/r2inference/gstinferencepostprocess.h"
46 | #include "gst/r2inference/gstinferencedebug.h"
47 |
48 | GST_DEBUG_CATEGORY_STATIC (gst_mobilenetv2_debug_category);
49 | #define GST_CAT_DEFAULT gst_mobilenetv2_debug_category
50 |
51 | #define MEAN 128.0
52 | #define STD 1/128.0
53 | #define MODEL_CHANNELS 3
54 |
55 | static gboolean gst_mobilenetv2_preprocess (GstVideoInference * vi,
56 | GstVideoFrame * inframe, GstVideoFrame * outframe);
57 | static gboolean gst_mobilenetv2_postprocess (GstVideoInference * vi,
58 | const gpointer prediction, gsize predsize, GstMeta * meta_model,
59 | GstVideoInfo * info_model, gboolean * valid_prediction,
60 | gchar ** labels_list, gint num_labels);
61 | static gboolean gst_mobilenetv2_start (GstVideoInference * vi);
62 | static gboolean gst_mobilenetv2_stop (GstVideoInference * vi);
63 |
64 | enum
65 | {
66 | PROP_0
67 | };
68 |
69 | /* pad templates */
70 | #define CAPS \
71 | "video/x-raw, " \
72 | "width=224, " \
73 | "height=224, " \
74 | "format={RGB, RGBx, RGBA, BGR, BGRx, BGRA, xRGB, ARGB, xBGR, ABGR}"
75 |
76 | static GstStaticPadTemplate sink_model_factory =
77 | GST_STATIC_PAD_TEMPLATE ("sink_model",
78 | GST_PAD_SINK,
79 | GST_PAD_REQUEST,
80 | GST_STATIC_CAPS (CAPS)
81 | );
82 |
83 | static GstStaticPadTemplate src_model_factory =
84 | GST_STATIC_PAD_TEMPLATE ("src_model",
85 | GST_PAD_SRC,
86 | GST_PAD_REQUEST,
87 | GST_STATIC_CAPS (CAPS)
88 | );
89 |
90 | struct _GstMobilenetv2
91 | {
92 | GstVideoInference parent;
93 | };
94 |
95 | struct _GstMobilenetv2Class
96 | {
97 | GstVideoInferenceClass parent;
98 | };
99 |
100 | /* class initialization */
101 |
102 | G_DEFINE_TYPE_WITH_CODE (GstMobilenetv2, gst_mobilenetv2,
103 | GST_TYPE_VIDEO_INFERENCE,
104 | GST_DEBUG_CATEGORY_INIT (gst_mobilenetv2_debug_category, "mobilenetv2", 0,
105 | "debug category for mobilenetv2 element"));
106 |
107 | static void
108 | gst_mobilenetv2_class_init (GstMobilenetv2Class * klass)
109 | {
110 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
111 | GstVideoInferenceClass *vi_class = GST_VIDEO_INFERENCE_CLASS (klass);
112 |
113 | gst_element_class_add_static_pad_template (element_class,
114 | &sink_model_factory);
115 | gst_element_class_add_static_pad_template (element_class, &src_model_factory);
116 |
117 | gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
118 | "mobilenetv2", "Filter",
119 | "Infers incoming image frames using a pretrained GoogLeNet mobilenetv2 model",
120 | "Carlos Rodriguez \n\t\t\t"
121 | " Jose Jimenez \n\t\t\t"
122 | " Michael Gruner \n\t\t\t"
123 | " Mauricio Montero ");
124 |
125 | vi_class->start = GST_DEBUG_FUNCPTR (gst_mobilenetv2_start);
126 | vi_class->stop = GST_DEBUG_FUNCPTR (gst_mobilenetv2_stop);
127 | vi_class->preprocess = GST_DEBUG_FUNCPTR (gst_mobilenetv2_preprocess);
128 | vi_class->postprocess = GST_DEBUG_FUNCPTR (gst_mobilenetv2_postprocess);
129 | }
130 |
131 | static void
132 | gst_mobilenetv2_init (GstMobilenetv2 * mobilenetv2)
133 | {
134 | }
135 |
136 | static gboolean
137 | gst_mobilenetv2_preprocess (GstVideoInference * vi,
138 | GstVideoFrame * inframe, GstVideoFrame * outframe)
139 | {
140 | GST_LOG_OBJECT (vi, "Preprocess");
141 | return gst_normalize (inframe, outframe, MEAN, STD, MODEL_CHANNELS);
142 | }
143 |
144 | static gboolean
145 | gst_mobilenetv2_postprocess (GstVideoInference * vi, const gpointer prediction,
146 | gsize predsize, GstMeta * meta_model, GstVideoInfo * info_model,
147 | gboolean * valid_prediction, gchar ** labels_list, gint num_labels)
148 | {
149 | GstInferenceMeta *imeta = NULL;
150 | GstInferenceClassification *c = NULL;
151 | GstInferencePrediction *root = NULL;
152 | gboolean ret = TRUE;
153 |
154 | g_return_val_if_fail (vi != NULL, FALSE);
155 | g_return_val_if_fail (meta_model != NULL, FALSE);
156 | g_return_val_if_fail (info_model != NULL, FALSE);
157 |
158 | GST_LOG_OBJECT (vi, "Postprocess Meta");
159 |
160 | imeta = (GstInferenceMeta *) meta_model;
161 |
162 | root = imeta->prediction;
163 | if (!root) {
164 | GST_ERROR_OBJECT (vi, "Prediction is not part of the Inference Meta");
165 | ret = FALSE;
166 | goto out;
167 | }
168 |
169 | c = gst_create_class_from_prediction (vi, prediction, predsize, labels_list,
170 | num_labels);
171 | gst_inference_prediction_append_classification (root, c);
172 | gst_inference_print_predictions (vi, gst_mobilenetv2_debug_category, imeta);
173 |
174 | *valid_prediction = TRUE;
175 |
176 | out:
177 | return ret;
178 | }
179 |
180 | static gboolean
181 | gst_mobilenetv2_start (GstVideoInference * vi)
182 | {
183 | GST_INFO_OBJECT (vi, "Starting Mobilenet v2");
184 |
185 | return TRUE;
186 | }
187 |
188 | static gboolean
189 | gst_mobilenetv2_stop (GstVideoInference * vi)
190 | {
191 | GST_INFO_OBJECT (vi, "Stopping Mobilenet v2");
192 |
193 | return TRUE;
194 | }
195 |
--------------------------------------------------------------------------------
/ext/r2inference/gstmobilenetv2.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_MOBILENETV2_H_
23 | #define _GST_MOBILENETV2_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_MOBILENETV2 gst_mobilenetv2_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstMobilenetv2, gst_mobilenetv2, GST, MOBILENETV2, GstVideoInference)
31 |
32 | G_END_DECLS
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/ext/r2inference/gstmobilenetv2ssd.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2021 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_MOBILENETV2SSD_H_
23 | #define _GST_MOBILENETV2SSD_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_MOBILENETV2SSD gst_mobilenetv2ssd_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstMobilenetv2ssd, gst_mobilenetv2ssd, GST, MOBILENETV2SSD, GstVideoInference)
31 |
32 | G_END_DECLS
33 |
34 | #endif /* _GST_MOBILENETV2SSD_H_ */
35 |
--------------------------------------------------------------------------------
/ext/r2inference/gstresnet50v1.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | /**
23 | * SECTION:element-gstresnet50v1
24 | *
25 | * The resnet50v1 element allows the user to infer/execute a pretrained model
26 | * based on the ResNet (ResNet v1 or ResNet v2) architectures on
27 | * incoming image frames.
28 | *
29 | *
30 | * Example launch line
31 | * |[
32 | * gst-launch-1.0 -v videotestsrc ! resnet50v1 ! xvimagesink
33 | * ]|
34 | * Process video frames from the camera using a GoogLeNet (Resnet50 v1 or
35 | * Resnet50 v2) model.
36 | *
37 | */
38 |
39 | #ifdef HAVE_CONFIG_H
40 | #include "config.h"
41 | #endif
42 |
43 | #include "gstresnet50v1.h"
44 | #include "gst/r2inference/gstinferencemeta.h"
45 | #include
46 | #include "gst/r2inference/gstinferencepreprocess.h"
47 | #include "gst/r2inference/gstinferencepostprocess.h"
48 | #include "gst/r2inference/gstinferencedebug.h"
49 |
50 | GST_DEBUG_CATEGORY_STATIC (gst_resnet50v1_debug_category);
51 | #define GST_CAT_DEFAULT gst_resnet50v1_debug_category
52 |
53 | #define MEAN_RED 123.68
54 | #define MEAN_GREEN 116.78
55 | #define MEAN_BLUE 103.94
56 | #define MODEL_CHANNELS 3
57 |
58 | /* prototypes */
59 | static gboolean gst_resnet50v1_preprocess (GstVideoInference * vi,
60 | GstVideoFrame * inframe, GstVideoFrame * outframe);
61 | static gboolean gst_resnet50v1_postprocess (GstVideoInference * vi,
62 | const gpointer prediction, gsize predsize, GstMeta * meta_model,
63 | GstVideoInfo * info_model, gboolean * valid_prediction,
64 | gchar ** labels_list, gint num_labels);
65 | static gboolean gst_resnet50v1_start (GstVideoInference * vi);
66 | static gboolean gst_resnet50v1_stop (GstVideoInference * vi);
67 |
68 | enum
69 | {
70 | PROP_0
71 | };
72 |
73 | /* pad templates */
74 | #define CAPS \
75 | "video/x-raw, " \
76 | "width=224, " \
77 | "height=224, " \
78 | "format={RGB, RGBx, RGBA, BGR, BGRx, BGRA, xRGB, ARGB, xBGR, ABGR}"
79 |
80 | static GstStaticPadTemplate sink_model_factory =
81 | GST_STATIC_PAD_TEMPLATE ("sink_model",
82 | GST_PAD_SINK,
83 | GST_PAD_REQUEST,
84 | GST_STATIC_CAPS (CAPS)
85 | );
86 |
87 | static GstStaticPadTemplate src_model_factory =
88 | GST_STATIC_PAD_TEMPLATE ("src_model",
89 | GST_PAD_SRC,
90 | GST_PAD_REQUEST,
91 | GST_STATIC_CAPS (CAPS)
92 | );
93 |
94 | struct _GstResnet50v1
95 | {
96 | GstVideoInference parent;
97 | };
98 |
99 | struct _GstResnet50v1Class
100 | {
101 | GstVideoInferenceClass parent;
102 | };
103 |
104 | /* class initialization */
105 |
106 | G_DEFINE_TYPE_WITH_CODE (GstResnet50v1, gst_resnet50v1,
107 | GST_TYPE_VIDEO_INFERENCE,
108 | GST_DEBUG_CATEGORY_INIT (gst_resnet50v1_debug_category, "resnet50v1", 0,
109 | "debug category for resnet50v1 element"));
110 |
111 | static void
112 | gst_resnet50v1_class_init (GstResnet50v1Class * klass)
113 | {
114 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
115 | GstVideoInferenceClass *vi_class = GST_VIDEO_INFERENCE_CLASS (klass);
116 |
117 | gst_element_class_add_static_pad_template (element_class,
118 | &sink_model_factory);
119 | gst_element_class_add_static_pad_template (element_class, &src_model_factory);
120 |
121 | gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
122 | "resnet50v1", "Filter",
123 | "Infers incoming image frames using a pretrained ResNet (Resnet50 v1 or Resnet50 v2) model",
124 | "Carlos Rodriguez \n\t\t\t"
125 | " Jose Jimenez \n\t\t\t"
126 | " Michael Gruner \n\t\t\t"
127 | " Greivin Fallas ");
128 |
129 | vi_class->start = GST_DEBUG_FUNCPTR (gst_resnet50v1_start);
130 | vi_class->stop = GST_DEBUG_FUNCPTR (gst_resnet50v1_stop);
131 | vi_class->preprocess = GST_DEBUG_FUNCPTR (gst_resnet50v1_preprocess);
132 | vi_class->postprocess = GST_DEBUG_FUNCPTR (gst_resnet50v1_postprocess);
133 | }
134 |
135 | static void
136 | gst_resnet50v1_init (GstResnet50v1 * resnet50v1)
137 | {
138 | }
139 |
140 | static gboolean
141 | gst_resnet50v1_preprocess (GstVideoInference * vi,
142 | GstVideoFrame * inframe, GstVideoFrame * outframe)
143 | {
144 |
145 | GST_LOG_OBJECT (vi, "Preprocess");
146 | return gst_subtract_mean (inframe, outframe, MEAN_RED, MEAN_GREEN, MEAN_BLUE,
147 | MODEL_CHANNELS);
148 | }
149 |
150 | static gboolean
151 | gst_resnet50v1_postprocess (GstVideoInference * vi, const gpointer prediction,
152 | gsize predsize, GstMeta * meta_model, GstVideoInfo * info_model,
153 | gboolean * valid_prediction, gchar ** labels_list, gint num_labels)
154 | {
155 | GstInferenceMeta *imeta = NULL;
156 | GstInferenceClassification *c = NULL;
157 | GstInferencePrediction *root = NULL;
158 | gboolean ret = TRUE;
159 |
160 | g_return_val_if_fail (vi != NULL, FALSE);
161 | g_return_val_if_fail (meta_model != NULL, FALSE);
162 | g_return_val_if_fail (info_model != NULL, FALSE);
163 |
164 | GST_LOG_OBJECT (vi, "Postprocess Meta");
165 |
166 | imeta = (GstInferenceMeta *) meta_model;
167 |
168 | root = imeta->prediction;
169 | if (!root) {
170 | GST_ERROR_OBJECT (vi, "Prediction is not part of the Inference Meta");
171 | ret = FALSE;
172 | goto out;
173 | }
174 |
175 | c = gst_create_class_from_prediction (vi, prediction, predsize, labels_list,
176 | num_labels);
177 | gst_inference_prediction_append_classification (root, c);
178 | gst_inference_print_predictions (vi, gst_resnet50v1_debug_category, imeta);
179 |
180 | *valid_prediction = TRUE;
181 |
182 | out:
183 | return ret;
184 | }
185 |
186 | static gboolean
187 | gst_resnet50v1_start (GstVideoInference * vi)
188 | {
189 | GST_INFO_OBJECT (vi, "Starting Resnet50 v1");
190 |
191 | return TRUE;
192 | }
193 |
194 | static gboolean
195 | gst_resnet50v1_stop (GstVideoInference * vi)
196 | {
197 | GST_INFO_OBJECT (vi, "Stopping Resnet50 v1");
198 |
199 | return TRUE;
200 | }
201 |
--------------------------------------------------------------------------------
/ext/r2inference/gstresnet50v1.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_RESNET50V1_H_
23 | #define _GST_RESNET50V1_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_RESNET50V1 gst_resnet50v1_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstResnet50v1, gst_resnet50v1, GST, RESNET50V1, GstVideoInference)
31 |
32 | G_END_DECLS
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/ext/r2inference/gstrosetta.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2021 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | /**
23 | * SECTION:element-rosetta
24 | *
25 | * The rosetta element allows the user to infer/execute a pretrained model
26 | * based on the ResNet architecture on incoming image frames and extract
27 | * the characters from it.
28 | *
29 | *
30 | * Source
31 | * This element is based on the TensorFlow Lite Hub Rosetta Google
32 | * Colaboratory script:
33 | * https://tfhub.dev/tulasiram58827/lite-model/rosetta/dr/1
34 | *
35 | */
36 |
37 | #include "gstrosetta.h"
38 |
39 | #include "gst/r2inference/gstinferencedebug.h"
40 | #include "gst/r2inference/gstinferencemeta.h"
41 | #include "gst/r2inference/gstinferencepostprocess.h"
42 | #include "gst/r2inference/gstinferencepreprocess.h"
43 |
44 | GST_DEBUG_CATEGORY_STATIC (gst_rosetta_debug_category);
45 | #define GST_CAT_DEFAULT gst_rosetta_debug_category
46 |
47 | #define BLANK 0
48 | #define DEFAULT_MODEL_CHANNELS 1
49 | #define DEFAULT_DATA_MEAN 127.5
50 | #define DEFAULT_DATA_OFFSET -1
51 | #define MODEL_OUTPUT_ROWS 26
52 | #define MODEL_OUTPUT_COLS 37
53 |
54 | /* prototypes */
55 | static gboolean gst_rosetta_preprocess (GstVideoInference * vi,
56 | GstVideoFrame * inframe, GstVideoFrame * outframe);
57 |
58 | static gboolean
59 | gst_rosetta_postprocess (GstVideoInference * vi,
60 | const gpointer prediction, gsize predsize, GstMeta * meta_model,
61 | GstVideoInfo * info_model, gboolean * valid_prediction,
62 | gchar ** labels_list, gint num_labels);
63 |
64 | gint get_max_indices (gfloat row[MODEL_OUTPUT_COLS]);
65 |
66 | gchar *concatenate_chars (gint max_indices[MODEL_OUTPUT_ROWS]);
67 | static gboolean gst_rosetta_start (GstVideoInference * vi);
68 | static gboolean gst_rosetta_stop (GstVideoInference * vi);
69 |
70 | #define CAPS \
71 | "video/x-raw, " \
72 | "width=100, " \
73 | "height=32, " \
74 | "format={GRAY8}"
75 |
76 | static GstStaticPadTemplate sink_model_factory =
77 | GST_STATIC_PAD_TEMPLATE ("sink_model",
78 | GST_PAD_SINK,
79 | GST_PAD_REQUEST,
80 | GST_STATIC_CAPS (CAPS)
81 | );
82 |
83 | static GstStaticPadTemplate src_model_factory =
84 | GST_STATIC_PAD_TEMPLATE ("src_model",
85 | GST_PAD_SRC,
86 | GST_PAD_REQUEST,
87 | GST_STATIC_CAPS (CAPS)
88 | );
89 |
90 | struct _GstRosetta
91 | {
92 | GstVideoInference parent;
93 | };
94 |
95 | struct _GstRosettaClass
96 | {
97 | GstVideoInferenceClass parent;
98 | };
99 |
100 | /* class initialization */
101 |
102 | G_DEFINE_TYPE_WITH_CODE (GstRosetta, gst_rosetta,
103 | GST_TYPE_VIDEO_INFERENCE,
104 | GST_DEBUG_CATEGORY_INIT (gst_rosetta_debug_category,
105 | "rosetta", 0, "debug category for rosetta element"));
106 |
107 | static void
108 | gst_rosetta_class_init (GstRosettaClass * klass)
109 | {
110 | GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
111 | GstVideoInferenceClass *vi_class = GST_VIDEO_INFERENCE_CLASS (klass);
112 | gst_element_class_add_static_pad_template (element_class,
113 | &sink_model_factory);
114 | gst_element_class_add_static_pad_template (element_class, &src_model_factory);
115 |
116 | gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
117 | "Rosetta", "Filter",
118 | "Infers characters from an incoming image",
119 | "Edgar Chaves \n\t\t\t"
120 | " Luis Leon ");
121 |
122 | vi_class->preprocess = GST_DEBUG_FUNCPTR (gst_rosetta_preprocess);
123 | vi_class->postprocess = GST_DEBUG_FUNCPTR (gst_rosetta_postprocess);
124 | vi_class->start = GST_DEBUG_FUNCPTR (gst_rosetta_start);
125 | vi_class->stop = GST_DEBUG_FUNCPTR (gst_rosetta_stop);
126 | }
127 |
128 |
129 | static void
130 | gst_rosetta_init (GstRosetta * rosetta)
131 | {
132 | }
133 |
134 | static gboolean
135 | gst_rosetta_preprocess (GstVideoInference * vi,
136 | GstVideoFrame * inframe, GstVideoFrame * outframe)
137 | {
138 | GstRosetta *rosetta = NULL;
139 | gint width = 0, height = 0;
140 | g_return_val_if_fail (vi, FALSE);
141 | g_return_val_if_fail (inframe, FALSE);
142 | g_return_val_if_fail (outframe, FALSE);
143 |
144 | rosetta = GST_ROSETTA (vi);
145 |
146 | GST_LOG_OBJECT (rosetta, "Rosetta Preprocess");
147 |
148 | width = GST_VIDEO_FRAME_WIDTH (inframe);
149 | height = GST_VIDEO_FRAME_HEIGHT (inframe);
150 |
151 | GST_LOG_OBJECT (rosetta, "Input frame dimensions w = %i , h = %i", width,
152 | height);
153 | return gst_normalize_gray_image (inframe, outframe, DEFAULT_DATA_MEAN,
154 | DEFAULT_DATA_OFFSET, DEFAULT_MODEL_CHANNELS);
155 | }
156 |
157 | gint
158 | get_max_indices (gfloat row[MODEL_OUTPUT_COLS])
159 | {
160 | gfloat largest_probability = row[0];
161 | gint temp_max_index = 0;
162 | for (int i = 0; i < MODEL_OUTPUT_COLS; ++i) {
163 | if (largest_probability < row[i]) {
164 | largest_probability = row[i];
165 | temp_max_index = i;
166 | }
167 | }
168 | return temp_max_index;
169 | }
170 |
171 | /**
172 | * NOTE: After using this function, please free the returned
173 | * gchar with g_free(), due to this function is transfering
174 | * the ownership of the allocated memory.
175 | **/
176 | gchar *
177 | concatenate_chars (int max_indices[MODEL_OUTPUT_ROWS])
178 | {
179 | gint i = 0;
180 | gint counter = 0;
181 | gchar *final_phrase = NULL;
182 | const gchar chars[MODEL_OUTPUT_COLS] =
183 | { '_', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c',
184 | 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
185 | 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
186 | };
187 | /* Instead of using g_malloc() & memset g_strnfill(), will create
188 | * the memory allocation and fill the string with empty spaces.
189 | */
190 | final_phrase = g_strnfill (MODEL_OUTPUT_ROWS + 1, ' ');
191 |
192 | for (i = 0; i < MODEL_OUTPUT_ROWS; ++i) {
193 |
194 | /* Checking if the actual max index value is different from '_' character
195 | * and also, checking if i is greater than 0, and finally, checking
196 | * if the actual max index is equal from the previous one.
197 | */
198 | if (BLANK != max_indices[i] && !(0 < i
199 | && (max_indices[i - 1] == max_indices[i]))) {
200 | final_phrase[counter] = chars[max_indices[i]];
201 | ++counter;
202 | }
203 | }
204 |
205 | final_phrase[MODEL_OUTPUT_ROWS] = '\0';
206 |
207 | return final_phrase;
208 | }
209 |
210 | static gboolean
211 | gst_rosetta_postprocess (GstVideoInference * vi,
212 | const gpointer prediction, gsize predsize, GstMeta * meta_model,
213 | GstVideoInfo * info_model, gboolean * valid_prediction,
214 | gchar ** labels_list, gint num_labels)
215 | {
216 | GstRosetta *rosetta = NULL;
217 |
218 | gint max_indices[MODEL_OUTPUT_ROWS];
219 | gfloat row[MODEL_OUTPUT_COLS];
220 | gint index = 0;
221 | const gfloat *pred = NULL;
222 | gchar *output = NULL;
223 | GstInferenceMeta *imeta = NULL;
224 | GstInferencePrediction *root = NULL;
225 |
226 | g_return_val_if_fail (vi, FALSE);
227 | g_return_val_if_fail (prediction, FALSE);
228 | g_return_val_if_fail (meta_model, FALSE);
229 | g_return_val_if_fail (info_model, FALSE);
230 |
231 | GST_LOG_OBJECT (rosetta, "Rosetta Postprocess");
232 |
233 | imeta = (GstInferenceMeta *) meta_model;
234 | rosetta = GST_ROSETTA (vi);
235 | root = imeta->prediction;
236 | if (!root) {
237 | GST_ERROR_OBJECT (vi, "Prediction is not part of the Inference Meta");
238 | return FALSE;
239 | }
240 | pred = (const gfloat *) prediction;
241 | GST_LOG_OBJECT (vi, "Predicting...");
242 |
243 | for (int j = 0; j < MODEL_OUTPUT_ROWS; ++j) {
244 | for (int i = 0; i < MODEL_OUTPUT_COLS; ++i) {
245 | row[i] = pred[index];
246 | ++index;
247 | }
248 | max_indices[j] = get_max_indices (row);
249 | }
250 | GST_LOG_OBJECT (vi, "Rosetta prediction is done");
251 |
252 | output = concatenate_chars (max_indices);
253 |
254 | GST_LOG_OBJECT (vi, "The phrase is %s", output);
255 |
256 | g_free (output);
257 | return TRUE;
258 | }
259 |
260 | static gboolean
261 | gst_rosetta_start (GstVideoInference * vi)
262 | {
263 | GST_INFO_OBJECT (vi, "Starting Rosetta");
264 |
265 | return TRUE;
266 | }
267 |
268 | static gboolean
269 | gst_rosetta_stop (GstVideoInference * vi)
270 | {
271 | GST_INFO_OBJECT (vi, "Stopping Rosetta");
272 |
273 | return TRUE;
274 | }
275 |
--------------------------------------------------------------------------------
/ext/r2inference/gstrosetta.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2021 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_ROSETTA_H_
23 | #define _GST_ROSETTA_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 | #define GST_TYPE_ROSETTA gst_rosetta_get_type()
29 | G_DECLARE_FINAL_TYPE (GstRosetta, gst_rosetta, GST, ROSETTA, GstVideoInference)
30 |
31 | G_END_DECLS
32 | #endif /* _GST_ROSETTA_H_ */
33 |
--------------------------------------------------------------------------------
/ext/r2inference/gsttinyyolov2.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_TINYYOLOV2_H_
23 | #define _GST_TINYYOLOV2_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_TINYYOLOV2 gst_tinyyolov2_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstTinyyolov2, gst_tinyyolov2, GST, TINYYOLOV2, GstVideoInference)
31 |
32 | G_END_DECLS
33 |
34 | #endif /* _GST_TINYYOLOV2_H_ */
35 |
--------------------------------------------------------------------------------
/ext/r2inference/gsttinyyolov3.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_TINYYOLOV3_H_
23 | #define _GST_TINYYOLOV3_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_TINYYOLOV3 gst_tinyyolov3_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstTinyyolov3, gst_tinyyolov3, GST, TINYYOLOV3, GstVideoInference)
31 |
32 | G_END_DECLS
33 |
34 | #endif /* _GST_TINYYOLOV3_H_ */
35 |
--------------------------------------------------------------------------------
/ext/r2inference/meson.build:
--------------------------------------------------------------------------------
1 | gstinference_sources = [
2 | 'gstinceptionv1.c',
3 | 'gstinceptionv2.c',
4 | 'gstinceptionv3.c',
5 | 'gstinceptionv4.c',
6 | 'gstinference.c',
7 | 'gstmobilenetv2.c',
8 | 'gstmobilenetv2ssd.c',
9 | 'gstresnet50v1.c',
10 | 'gsttinyyolov2.c',
11 | 'gsttinyyolov3.c',
12 | 'gstrosetta.c'
13 | ]
14 |
15 | gstinference = library('gstinference',
16 | gstinference_sources,
17 | c_args : c_args,
18 | include_directories : [configinc, inference_inc_dir],
19 | dependencies : [gst_base_dep, gst_video_dep, gstinference_dep],
20 | install : true,
21 | install_dir : plugins_install_dir,
22 | )
23 | plugins += [gstinference]
24 |
--------------------------------------------------------------------------------
/gst-libs/gst/meson.build:
--------------------------------------------------------------------------------
1 | subdir('r2inference')
2 | subdir('opencv')
3 |
--------------------------------------------------------------------------------
/gst-libs/gst/opencv/gstinferencebaseoverlay.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __GST_INFERENCE_BASE_OVERLAY_H__
23 | #define __GST_INFERENCE_BASE_OVERLAY_H__
24 |
25 | #ifdef HAVE_CONFIG_H
26 | #include "config.h"
27 | #endif
28 |
29 | #include
30 | #include
31 |
32 | #ifdef OCV_VERSION_4_0
33 | #include "opencv4/opencv2/highgui.hpp"
34 | #include "opencv4/opencv2/imgproc.hpp"
35 | #elif OCV_VERSION_LT_3_2
36 | #include "opencv2/highgui/highgui.hpp"
37 | #else
38 | #include "opencv2/imgproc.hpp"
39 | #include "opencv2/highgui.hpp"
40 | #endif
41 |
42 | G_BEGIN_DECLS
43 |
44 | #define LINE_STYLE_BOUNDING_BOX (line_style_bounding_box_get_type ())
45 | /**
46 | * LineStyleBoundingBox:
47 | * @CLASSIC : Draw lines without any style
48 | * @DOTTED : Draw lines with dots
49 | * @DASHED : Draw lines with dashed lines
50 | *
51 | **/
52 | typedef enum
53 | {
54 | CLASSIC,
55 | DOTTED,
56 | DASHED,
57 | } LineStyleBoundingBox;
58 |
59 | GType line_style_bounding_box_get_type (void) G_GNUC_CONST;
60 | #define GST_TYPE_INFERENCE_BASE_OVERLAY gst_inference_base_overlay_get_type ()
61 | G_DECLARE_DERIVABLE_TYPE (GstInferenceBaseOverlay, gst_inference_base_overlay, GST,
62 | INFERENCE_BASE_OVERLAY, GstVideoFilter);
63 |
64 | struct _GstInferenceBaseOverlayClass
65 | {
66 | GstVideoFilterClass parent_class;
67 |
68 | GstFlowReturn (* process_meta) (GstInferenceBaseOverlay * inference_base_overlay,
69 | cv::Mat &mat, GstVideoFrame * frame, GstMeta* meta, gdouble font_scale,
70 | gint thickness, gchar **labels_list, gint num_labels, LineStyleBoundingBox style,
71 | gdouble alpha_overlay);
72 |
73 | GType meta_type;
74 | };
75 |
76 | G_END_DECLS
77 |
78 | #endif //__GST_INFERENCE_OVERLAY_H__
79 |
--------------------------------------------------------------------------------
/gst-libs/gst/opencv/meson.build:
--------------------------------------------------------------------------------
1 | opencv_sources = [
2 | 'gstinferencebaseoverlay.cc'
3 | ]
4 |
5 | opencv_headers = [
6 | 'gstinferencebaseoverlay.h'
7 | ]
8 |
9 | if opencv_dep.found()
10 | opencv_all_dependencies = [gst_base_dep, gst_video_dep, opencv_dep]
11 |
12 | inferencebaseoverlay = library('gstinferencebaseoverlay-@0@'.format(api_version),
13 | opencv_sources,
14 | c_args : c_args + ['-DBUILDING_GST_INFERENCE'],
15 | cpp_args: cpp_args + ['-DBUILDING_GST_INFERENCE'],
16 | include_directories : [configinc, inference_inc_dir],
17 | version : version_arr[0],
18 | install : true,
19 | dependencies : opencv_all_dependencies,
20 | )
21 |
22 | inferencebaseoverlay_dep = declare_dependency(link_with: inferencebaseoverlay,
23 | include_directories : [inference_inc_dir],
24 | dependencies : opencv_all_dependencies)
25 |
26 | install_headers(opencv_headers, subdir : 'gstreamer-1.0/gst/opencv')
27 | else
28 | warning('OpenCV was not found in this system. Base overlay utils will not be built.')
29 | endif
30 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstbasebackend.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __GST_BASE_BACKEND_H__
23 | #define __GST_BASE_BACKEND_H__
24 |
25 | #include
26 | #include
27 |
28 | G_BEGIN_DECLS
29 | #define GST_TYPE_BASE_BACKEND gst_base_backend_get_type ()
30 | G_DECLARE_DERIVABLE_TYPE (GstBaseBackend, gst_base_backend, GST, BASE_BACKEND, GObject);
31 |
32 | struct _GstBaseBackendClass
33 | {
34 | GObjectClass parent_class;
35 |
36 | };
37 |
38 | GQuark gst_base_backend_error_quark (void);
39 | gboolean gst_base_backend_start (GstBaseBackend *, const gchar *, GError **);
40 | gboolean gst_base_backend_stop (GstBaseBackend *, GError **);
41 | guint gst_base_backend_get_framework_code (GstBaseBackend *);
42 | gboolean gst_base_backend_process_frame (GstBaseBackend *, GstVideoFrame *,
43 | gpointer *, gsize *, GError **);
44 |
45 | G_END_DECLS
46 | #endif //__GST_BASE_BACKEND_H__
47 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstbasebackendsubclass.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __GST_BASE_BACKEND_SUBCLASS_H__
23 | #define __GST_BASE_BACKEND_SUBCLASS_H__
24 |
25 | #include "gstbasebackend.h"
26 |
27 | #include
28 |
29 | G_BEGIN_DECLS
30 |
31 | void gst_base_backend_get_property (GObject * object, guint property_id,
32 | GValue * value, GParamSpec * pspec);
33 | void gst_base_backend_set_property (GObject * object, guint property_id,
34 | const GValue * value, GParamSpec * pspec);
35 | void gst_base_backend_install_properties (GstBaseBackendClass * klass,
36 | r2i::FrameworkCode code);
37 | gboolean gst_base_backend_set_framework_code (GstBaseBackend * backend,
38 | r2i::FrameworkCode code);
39 |
40 | gboolean gst_inference_backend_register (const gchar* type_name, r2i::FrameworkCode code);
41 |
42 | G_END_DECLS
43 | #endif //__GST_BASE_BACKEND_SUBCLASS_H__
44 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstchildinspector.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "gstchildinspector.h"
23 |
24 | typedef struct _GstChildInspectorFlag GstChildInspectorFlag;
25 | typedef struct _GstChildInspectorType GstChildInspectorType;
26 |
27 | typedef gchar *(*GstChildInspectorTypeToString) (GParamSpec * pspec,
28 | GValue * value);
29 |
30 | static gchar *gst_child_inspector_type_int_to_string (GParamSpec * pspec,
31 | GValue * value);
32 | static gchar *gst_child_inspector_type_string_to_string (GParamSpec * pspec,
33 | GValue * value);
34 | static gchar *gst_child_inspector_type_double_to_string (GParamSpec * pspec,
35 | GValue * value);
36 |
37 | struct _GstChildInspectorFlag
38 | {
39 | gint value;
40 | const gchar *to_string;
41 | };
42 |
43 | struct _GstChildInspectorType
44 | {
45 | GType value;
46 | GstChildInspectorTypeToString to_string;
47 | };
48 |
49 | static GstChildInspectorFlag flags[] = {
50 | {G_PARAM_READABLE, "readable"},
51 | {G_PARAM_WRITABLE, "writable"},
52 | {}
53 | };
54 |
55 | static GstChildInspectorType types[] = {
56 | {G_TYPE_INT, gst_child_inspector_type_int_to_string},
57 | {G_TYPE_STRING, gst_child_inspector_type_string_to_string},
58 | {G_TYPE_DOUBLE, gst_child_inspector_type_double_to_string},
59 | {}
60 | };
61 |
62 | static gchar *
63 | gst_child_inspector_type_string_to_string (GParamSpec * pspec, GValue * value)
64 | {
65 | GParamSpecString *pstring = G_PARAM_SPEC_STRING (pspec);
66 | return g_strdup_printf ("String. Default: \"%s\"", pstring->default_value);
67 | }
68 |
69 | static gchar *
70 | gst_child_inspector_type_int_to_string (GParamSpec * pspec, GValue * value)
71 | {
72 | GParamSpecInt *pint = G_PARAM_SPEC_INT (pspec);
73 |
74 | return g_strdup_printf ("Integer. Range: %d - %d Default: %d",
75 | pint->minimum, pint->maximum, pint->default_value);
76 | }
77 |
78 | static gchar *
79 | gst_child_inspector_type_double_to_string (GParamSpec * pspec, GValue * value)
80 | {
81 | GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE (pspec);
82 |
83 | return g_strdup_printf ("Double. Range: %03.03e - %03.03e Default: %03.03e",
84 | pdouble->minimum, pdouble->maximum, pdouble->default_value);
85 | }
86 |
87 | static const gchar *
88 | gst_child_inspector_flag_to_string (GParamFlags flag)
89 | {
90 | GstChildInspectorFlag *current_flag;
91 | const gchar *to_string = NULL;
92 |
93 | for (current_flag = flags; current_flag->to_string; ++current_flag) {
94 | if (current_flag->value == flag) {
95 | to_string = current_flag->to_string;
96 | break;
97 | }
98 | }
99 |
100 | return to_string;
101 | }
102 |
103 | static gchar *
104 | gst_child_inspector_flags_to_string (GParamFlags flags)
105 | {
106 | guint32 bitflags;
107 | gint i;
108 | gchar *sflags = NULL;
109 |
110 | /* Walk through all the bits in the flags */
111 | bitflags = flags;
112 | for (i = 31; i >= 0; --i) {
113 | const gchar *sflag = NULL;
114 | guint32 bitflag = 0;
115 |
116 | /* Filter the desired bit */
117 | bitflag = bitflags & (1 << i);
118 | sflag = gst_child_inspector_flag_to_string (bitflag);
119 |
120 | /* Is this a flag we want to serialize? */
121 | if (sflag) {
122 | /* No trailing comma needed on the first case */
123 | if (!sflags) {
124 | sflags = g_strdup (sflag);
125 | } else {
126 | sflags = g_strdup_printf ("%s, %s", sflag, sflags);
127 | }
128 | }
129 | }
130 |
131 | return sflags;
132 | }
133 |
134 | static gchar *
135 | gst_child_inspector_type_to_string (GParamSpec * pspec, GValue * value)
136 | {
137 | GstChildInspectorType *current_type;
138 | const GType value_type = G_VALUE_TYPE (value);
139 | gchar *to_string = NULL;
140 |
141 | for (current_type = types; current_type->to_string; ++current_type) {
142 | if (current_type->value == value_type) {
143 | to_string = current_type->to_string (pspec, value);
144 | break;
145 | }
146 | }
147 |
148 | return to_string;
149 | }
150 |
151 | gchar *
152 | gst_child_inspector_property_to_string (GObject * object, GParamSpec * param,
153 | guint alignment)
154 | {
155 | GValue value = { 0, };
156 | const gchar *name;
157 | const gchar *blurb;
158 | gchar *flags = NULL;
159 | gchar *type;
160 | gchar *prop;
161 |
162 | g_return_val_if_fail (param, NULL);
163 | g_return_val_if_fail (G_IS_OBJECT (object), NULL);
164 |
165 | name = g_param_spec_get_name (param);
166 | blurb = g_param_spec_get_blurb (param);
167 |
168 | flags = gst_child_inspector_flags_to_string (param->flags);
169 |
170 | g_value_init (&value, param->value_type);
171 | if (param->flags & G_PARAM_READABLE) {
172 | g_object_get_property (object, param->name, &value);
173 | } else {
174 | g_param_value_set_default (param, &value);
175 | }
176 |
177 | type = gst_child_inspector_type_to_string (param, &value);
178 | g_value_unset (&value);
179 |
180 | prop = g_strdup_printf ("%*s%-20s: %s\n"
181 | "%*s%-21.21s flags: %s\n"
182 | "%*s%-21.21s %s",
183 | alignment, "", name, blurb,
184 | alignment, "", "", flags, alignment, "", "", type);
185 |
186 | g_free (type);
187 | g_free (flags);
188 |
189 | return prop;
190 | }
191 |
192 |
193 | gchar *
194 | gst_child_inspector_properties_to_string (GObject * object, guint alignment,
195 | gchar * title)
196 | {
197 | GParamSpec **property_specs;
198 | guint num_properties, i;
199 | gchar *prop, *props = NULL;
200 |
201 | g_return_val_if_fail (G_IS_OBJECT (object), NULL);
202 |
203 | property_specs = g_object_class_list_properties
204 | (G_OBJECT_GET_CLASS (object), &num_properties);
205 |
206 | if (title)
207 | props = title;
208 |
209 | for (i = 0; i < num_properties; i++) {
210 | prop =
211 | gst_child_inspector_property_to_string (object, property_specs[i],
212 | alignment);
213 | if (props) {
214 | gchar *tmp;
215 | tmp = g_strdup_printf ("%s\n%s", props, prop);
216 | g_free (prop);
217 | g_free (props);
218 | props = tmp;
219 | } else {
220 | props = prop;
221 | }
222 | }
223 |
224 | g_free (property_specs);
225 |
226 | return props;
227 | }
228 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstchildinspector.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __GST_CHILD_INSPECTOR_H__
23 | #define __GST_CHILD_INSPECTOR_H__
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | gchar * gst_child_inspector_property_to_string (GObject * object,
30 | GParamSpec * param, guint alignment);
31 | gchar * gst_child_inspector_properties_to_string (GObject * object,
32 | guint alignment, gchar * title);
33 |
34 | G_END_DECLS
35 |
36 | #endif /* __GST_CHILD_INSPECTOR_H__ */
37 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferencebackend.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "gstbasebackend.h"
23 | #include "gstbasebackendsubclass.h"
24 |
25 | #include
26 | #include
27 |
28 | typedef struct _GstInferenceBackend GstInferenceBackend;
29 | struct _GstInferenceBackend
30 | {
31 | GstBaseBackend parent;
32 | };
33 |
34 | typedef struct _GstInferenceBackendClass GstInferenceBackendClass;
35 | struct _GstInferenceBackendClass
36 | {
37 | GstBaseBackendClass parent_class;
38 | /* *INDENT-OFF* */
39 | r2i::FrameworkCode code;
40 | /* *INDENT-ON* */
41 | };
42 |
43 | #define GST_BACKEND_CODE_QDATA g_quark_from_static_string("backend-code")
44 |
45 | static GstBaseBackendClass *parent_class = NULL;
46 |
47 | static void
48 | gst_inference_backend_class_init (GstInferenceBackendClass * klass)
49 | {
50 | GstBaseBackendClass *bclass = GST_BASE_BACKEND_CLASS (klass);
51 | GObjectClass *oclass = G_OBJECT_CLASS (klass);
52 |
53 | guint code;
54 | parent_class = GST_BASE_BACKEND_CLASS (g_type_class_peek_parent (klass));
55 |
56 | code =
57 | GPOINTER_TO_UINT (g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass),
58 | GST_BACKEND_CODE_QDATA));
59 |
60 | klass->code = (r2i::FrameworkCode) code;
61 | oclass->set_property = gst_base_backend_set_property;
62 | oclass->get_property = gst_base_backend_get_property;
63 | gst_base_backend_install_properties (bclass, klass->code);
64 | }
65 |
66 | static void
67 | gst_inference_backend_init (GstInferenceBackend * self)
68 | {
69 | GstInferenceBackendClass *klass =
70 | (GstInferenceBackendClass *) G_OBJECT_GET_CLASS (self);
71 | gst_base_backend_set_framework_code (GST_BASE_BACKEND (self), klass->code);
72 | }
73 |
74 | gboolean
75 | gst_inference_backend_register (const gchar * type_name,
76 | r2i::FrameworkCode code)
77 | {
78 | GTypeInfo typeinfo = {
79 | sizeof (GstInferenceBackendClass),
80 | NULL,
81 | NULL,
82 | (GClassInitFunc) gst_inference_backend_class_init,
83 | NULL,
84 | NULL,
85 | sizeof (GstInferenceBackend),
86 | 0,
87 | (GInstanceInitFunc) gst_inference_backend_init,
88 | };
89 | GType type;
90 |
91 | type = g_type_from_name (type_name);
92 | if (!type) {
93 | type = g_type_register_static (GST_TYPE_BASE_BACKEND,
94 | type_name, &typeinfo, (GTypeFlags) 0);
95 |
96 | g_type_set_qdata (type, GST_BACKEND_CODE_QDATA, GUINT_TO_POINTER (code));
97 | }
98 |
99 | return TRUE;
100 | }
101 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferencebackends.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "gstbasebackend.h"
23 | #include "gstbasebackendsubclass.h"
24 | #include "gstchildinspector.h"
25 | #include "gstinferencebackends.h"
26 |
27 | #include
28 | #include
29 | #include
30 |
31 | #define DEFAULT_ALIGNMENT 32
32 |
33 | static void
34 | gst_inference_backends_add_frameworkmeta (r2i::FrameworkMeta meta,
35 | gchar ** backends_parameters, r2i::RuntimeError error, guint alignment);
36 |
37 | static void
38 | gst_inference_backends_enum_register_item (const guint id,
39 | const gchar * desc, const gchar * shortname);
40 |
41 | static gchar *gst_inference_backends_get_type_name (const gchar * framework);
42 |
43 | static GEnumValue *backend_enum_desc = NULL;
44 |
45 | GType
46 | gst_inference_backends_get_type (void)
47 | {
48 | static GType backend_type = 0;
49 | if (!backend_type) {
50 | backend_type =
51 | g_enum_register_static ("GstInferenceBackends",
52 | (GEnumValue *) backend_enum_desc);
53 | }
54 | return backend_type;
55 | }
56 |
57 | static void
58 | gst_inference_backends_enum_register_item (const guint id,
59 | const gchar * desc, const gchar * shortname)
60 | {
61 | static guint backend_enum_count = 0;
62 | GEnumValue *backend_desc;
63 |
64 | backend_enum_desc =
65 | (GEnumValue *) g_realloc_n (backend_enum_desc, backend_enum_count + 2,
66 | sizeof (GEnumValue));
67 |
68 | backend_desc = &backend_enum_desc[backend_enum_count];
69 | backend_desc->value = id;
70 | backend_desc->value_name = g_strdup (desc);
71 | backend_desc->value_nick = g_strdup (shortname);
72 |
73 | backend_enum_count++;
74 |
75 | /* Sentinel */
76 | backend_desc = &backend_enum_desc[backend_enum_count];
77 | backend_desc->value = 0;
78 | backend_desc->value_name = NULL;
79 | backend_desc->value_nick = NULL;
80 | }
81 |
82 | static gchar *
83 | gst_inference_backends_get_type_name (const gchar * framework)
84 | {
85 | return g_strdup_printf ("Gst%s", framework);
86 | }
87 |
88 |
89 | GType
90 | gst_inference_backends_search_type (guint id)
91 | {
92 | const gchar *framework = NULL;
93 | gchar *backend_type_name = NULL;
94 | GType backend_type = G_TYPE_INVALID;
95 | GEnumClass *enum_class = NULL;
96 | GEnumValue *enum_value = NULL;
97 |
98 | enum_class = (GEnumClass *) g_type_class_ref (GST_TYPE_INFERENCE_BACKENDS);
99 | enum_value = g_enum_get_value (enum_class, id);
100 |
101 | if (enum_value) {
102 | framework = enum_value->value_name;
103 | backend_type_name = gst_inference_backends_get_type_name (framework);
104 | backend_type = g_type_from_name (backend_type_name);
105 | g_free (backend_type_name);
106 | }
107 |
108 | g_type_class_unref (enum_class);
109 |
110 | return backend_type;
111 | }
112 |
113 | static void
114 | gst_inference_backends_add_frameworkmeta (r2i::FrameworkMeta meta,
115 | gchar ** backends_parameters, r2i::RuntimeError error, guint alignment)
116 | {
117 | GstBaseBackend *backend = NULL;
118 | gchar *parameters, *backend_name;
119 | gchar *backend_type_name;
120 | GType backend_type;
121 |
122 | gst_inference_backends_enum_register_item (meta.code,
123 | meta.name.c_str (), meta.label.c_str ());
124 |
125 | backend_type_name = gst_inference_backends_get_type_name (meta.name.c_str ());
126 | if (NULL == backend_type_name) {
127 | GST_ERROR_OBJECT (backend, "Failed to find Backend type: %s",
128 | meta.name.c_str ());
129 | return;
130 | }
131 | gst_inference_backend_register (backend_type_name, meta.code);
132 | backend_type = g_type_from_name (backend_type_name);
133 | backend = (GstBaseBackend *) g_object_new (backend_type, NULL);
134 | g_free (backend_type_name);
135 |
136 | backend_name =
137 | g_strdup_printf ("%*s: %s. Version: %s\n", alignment, meta.name.c_str (),
138 | meta.description.c_str (), meta.version.c_str ());
139 |
140 | parameters =
141 | gst_child_inspector_properties_to_string (G_OBJECT (backend), alignment,
142 | backend_name);
143 |
144 | if (NULL == *backends_parameters)
145 | *backends_parameters = parameters;
146 | else
147 | *backends_parameters =
148 | g_strconcat (*backends_parameters, "\n", parameters, NULL);
149 |
150 | g_object_unref (backend);
151 | }
152 |
153 | gchar *
154 | gst_inference_backends_get_string_properties (void)
155 | {
156 | gchar * backends_parameters = NULL;
157 | r2i::RuntimeError error;
158 |
159 | for (auto & meta:r2i::IFrameworkFactory::List (error)) {
160 | gst_inference_backends_add_frameworkmeta (meta, &backends_parameters, error,
161 | DEFAULT_ALIGNMENT);
162 | }
163 |
164 | return backends_parameters;
165 | }
166 |
167 | guint16
168 | gst_inference_backends_get_default_backend (void)
169 | {
170 | std::vector backends;
171 | r2i::FrameworkCode code;
172 | r2i::RuntimeError error;
173 |
174 | backends = r2i::IFrameworkFactory::List (error);
175 | code = backends.front().code;
176 |
177 | return code;
178 | }
179 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferencebackends.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __GST_INFERENCE_BACKENDS_H__
23 | #define __GST_INFERENCE_BACKENDS_H__
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_INFERENCE_BACKENDS (gst_inference_backends_get_type())
30 |
31 | GType gst_inference_backends_get_type (void);
32 | gchar * gst_inference_backends_get_string_properties (void);
33 | guint16 gst_inference_backends_get_default_backend (void);
34 | GType gst_inference_backends_search_type (guint);
35 |
36 | G_END_DECLS
37 | #endif //__GST_INFERENCE_BACKENDS_H__
38 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferenceclassification.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "gstinferenceclassification.h"
23 |
24 | #include
25 |
26 | #define DEFAULT_CLASS_ID -1
27 | #define DEFAULT_CLASS_PROB 0.0f
28 | #define DEFAULT_CLASS_LABEL NULL
29 | #define DEFAULT_NUM_CLASSES 0
30 | #define DEFAULT_PROBABILITIES NULL
31 | #define DEFAULT_LABELS NULL
32 |
33 | static GType gst_inference_classification_get_type (void);
34 | GST_DEFINE_MINI_OBJECT_TYPE (GstInferenceClassification,
35 | gst_inference_classification);
36 |
37 | static void classification_free (GstInferenceClassification * self);
38 | static void classification_reset (GstInferenceClassification * self);
39 |
40 | static gdouble *probabilities_copy (const gdouble * from, gint num_classes);
41 |
42 | static guint64 get_new_id (void);
43 |
44 | static guint64
45 | get_new_id (void)
46 | {
47 | static guint64 _id = G_GUINT64_CONSTANT (0);
48 | static GMutex _id_mutex;
49 | static guint64 ret = 0;
50 |
51 | g_mutex_lock (&_id_mutex);
52 | ret = _id++;
53 | g_mutex_unlock (&_id_mutex);
54 |
55 | return ret;
56 | }
57 |
58 | static void
59 | classification_reset (GstInferenceClassification * self)
60 | {
61 | g_return_if_fail (self);
62 |
63 | self->classification_id = get_new_id ();
64 | self->class_id = DEFAULT_CLASS_ID;
65 | self->class_prob = DEFAULT_CLASS_PROB;
66 | self->num_classes = DEFAULT_NUM_CLASSES;
67 |
68 | if (self->class_label) {
69 | g_free (self->class_label);
70 | }
71 | self->class_label = DEFAULT_CLASS_LABEL;
72 |
73 | if (self->probabilities) {
74 | g_free (self->probabilities);
75 | }
76 | self->probabilities = DEFAULT_PROBABILITIES;
77 |
78 | if (self->labels) {
79 | g_strfreev (self->labels);
80 | }
81 | self->labels = DEFAULT_LABELS;
82 | }
83 |
84 | GstInferenceClassification *
85 | gst_inference_classification_new (void)
86 | {
87 | GstInferenceClassification *self = g_slice_new (GstInferenceClassification);
88 |
89 | gst_mini_object_init (GST_MINI_OBJECT_CAST (self), 0,
90 | gst_inference_classification_get_type (),
91 | (GstMiniObjectCopyFunction) gst_inference_classification_copy, NULL,
92 | (GstMiniObjectFreeFunction) classification_free);
93 |
94 | g_mutex_init (&self->mutex);
95 |
96 | self->class_label = NULL;
97 | self->probabilities = NULL;
98 | self->labels = NULL;
99 |
100 | classification_reset (self);
101 |
102 | return self;
103 | }
104 |
105 | static gdouble *
106 | probabilities_copy (const gdouble * from, gint num_classes)
107 | {
108 | gsize size = 0;
109 | gdouble *to = NULL;
110 |
111 | g_return_val_if_fail (from, NULL);
112 | g_return_val_if_fail (num_classes > 0, NULL);
113 |
114 | size = num_classes * sizeof (double);
115 | to = g_malloc0 (size);
116 |
117 | memcpy (to, from, size);
118 |
119 | return to;
120 | }
121 |
122 | GstInferenceClassification *
123 | gst_inference_classification_new_full (gint class_id, gdouble class_prob,
124 | const gchar * class_label, gint num_classes, const gdouble * probabilities,
125 | gchar ** labels)
126 | {
127 | GstInferenceClassification *self = gst_inference_classification_new ();
128 |
129 | GST_INFERENCE_CLASSIFICATION_LOCK (self);
130 |
131 | self->class_id = class_id;
132 | self->class_prob = class_prob;
133 | self->num_classes = num_classes;
134 |
135 | if (class_label) {
136 | self->class_label = g_strdup (class_label);
137 | }
138 |
139 | if (probabilities && num_classes > 0) {
140 | self->probabilities = probabilities_copy (probabilities, num_classes);
141 | }
142 |
143 | if (labels) {
144 | self->labels = g_strdupv (labels);
145 | }
146 |
147 | GST_INFERENCE_CLASSIFICATION_UNLOCK (self);
148 |
149 | return self;
150 | }
151 |
152 | GstInferenceClassification *
153 | gst_inference_classification_ref (GstInferenceClassification * self)
154 | {
155 | g_return_val_if_fail (self, NULL);
156 |
157 | return (GstInferenceClassification *)
158 | gst_mini_object_ref (GST_MINI_OBJECT_CAST (self));
159 | }
160 |
161 | void
162 | gst_inference_classification_unref (GstInferenceClassification * self)
163 | {
164 | g_return_if_fail (self);
165 |
166 | gst_mini_object_unref (GST_MINI_OBJECT_CAST (self));
167 | }
168 |
169 | GstInferenceClassification *
170 | gst_inference_classification_copy (const GstInferenceClassification * self)
171 | {
172 | GstInferenceClassification *other = NULL;
173 |
174 | g_return_val_if_fail (self, NULL);
175 |
176 | other = gst_inference_classification_new ();
177 |
178 | GST_INFERENCE_CLASSIFICATION_LOCK ((GstInferenceClassification *) self);
179 |
180 | other->classification_id = self->classification_id;
181 | other->class_id = self->class_id;
182 | other->class_prob = self->class_prob;
183 | other->num_classes = self->num_classes;
184 |
185 | if (self->class_label) {
186 | other->class_label = g_strdup (self->class_label);
187 | }
188 |
189 | if (self->probabilities) {
190 | other->probabilities =
191 | probabilities_copy (self->probabilities, self->num_classes);
192 | }
193 |
194 | if (self->labels) {
195 | other->labels = g_strdupv (self->labels);
196 | }
197 |
198 | GST_INFERENCE_CLASSIFICATION_UNLOCK ((GstInferenceClassification *) self);
199 |
200 | return other;
201 | }
202 |
203 | gchar *
204 | gst_inference_classification_to_string (GstInferenceClassification * self,
205 | gint level)
206 | {
207 | gint indent = level * 2;
208 | gchar *serial = NULL;
209 |
210 | g_return_val_if_fail (self, NULL);
211 |
212 | GST_INFERENCE_CLASSIFICATION_LOCK (self);
213 |
214 | serial = g_strdup_printf ("{\n"
215 | "%*s \"Id\" : %" G_GUINT64_FORMAT ",\n"
216 | "%*s \"Class\" : %d,\n"
217 | "%*s \"Label\" : \"%s\",\n"
218 | "%*s \"Probability\" : \"%f\",\n"
219 | "%*s \"Classes\" : %d\n"
220 | "%*s}",
221 | indent, "", self->classification_id,
222 | indent, "", self->class_id,
223 | indent, "", self->class_label,
224 | indent, "", self->class_prob, indent, "", self->num_classes, indent, "");
225 |
226 | GST_INFERENCE_CLASSIFICATION_UNLOCK (self);
227 |
228 | return serial;
229 | }
230 |
231 | static void
232 | classification_free (GstInferenceClassification * self)
233 | {
234 | classification_reset (self);
235 |
236 | g_mutex_clear (&self->mutex);
237 | }
238 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferenceclassification.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __GST_INFERENCE_CLASSIFICATION__
23 | #define __GST_INFERENCE_CLASSIFICATION__
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | /**
30 | * GstInferenceClassification:
31 | * @classification_id: a unique id associated to this classification
32 | * @class_id: the numerical id associated to the assigned class
33 | * @class_prob: the resulting probability of the assigned
34 | * class. Typically between 0 and 1
35 | * @class_label: the label associated to this class or NULL if not
36 | * available
37 | * @num_classes: the amount of classes of the entire prediction
38 | * @probabilities: the entire array of probabilities of the prediction
39 | * @labels: the entire array of labels of the prediction or NULL if
40 | * not available
41 | */
42 | typedef struct _GstInferenceClassification GstInferenceClassification;
43 | struct _GstInferenceClassification
44 | {
45 | /**/
46 | GstMiniObject base;
47 | GMutex mutex;
48 |
49 | /**/
50 | guint64 classification_id;
51 | gint class_id;
52 | gdouble class_prob;
53 | gchar *class_label;
54 | gint num_classes;
55 | gdouble *probabilities;
56 | gchar **labels;
57 | };
58 |
59 | /**
60 | * gst_inference_classification_new:
61 | *
62 | * Creates a new GstInferenceClassification.
63 | *
64 | * Returns: A newly allocated and initialized GstInferenceClassification.
65 | */
66 | GstInferenceClassification * gst_inference_classification_new (void);
67 |
68 | /**
69 | * gst_inference_classification_new_full:
70 | * @class_id: the numerical id associated to the assigned class
71 | * @class_prob: the resulting probability of the assigned
72 | * class. Typically between 0 and 1
73 | * @class_label: the label associated to this class or NULL if not
74 | * available. A copy of the label is made if available.
75 | * @num_classes: the amount of classes of the entire prediction
76 | * @probabilities: the entire array of probabilities of the
77 | * prediction. A copy of the array is made.
78 | * @labels: the entire array of labels of the prediction or NULL if
79 | * not available. A copy is made, if available.
80 | *
81 | * Creates a new GstInferenceClassification and assigns its members.
82 | *
83 | * Returns: A newly allocated and initialized GstInferenceClassification.
84 | */
85 | GstInferenceClassification * gst_inference_classification_new_full (gint class_id, gdouble class_prob,
86 | const gchar * class_label, gint num_classes, const gdouble * probabilities,
87 | gchar ** labels);
88 |
89 | /**
90 | * gst_inference_classification_reset:
91 | * @self: the classification to reset
92 | *
93 | * Clears a classification, effectively freeing all associated memory.
94 | */
95 | void gst_inference_classification_reset (GstInferenceClassification * self);
96 |
97 | /**
98 | * gst_inference_classification_copy:
99 | * @self: the classification to copy
100 | *
101 | * Copies a classification into a newly allocated one. This is a deep
102 | * copy, meaning that all arrays are copied as well. No pointers are
103 | * shared.
104 | *
105 | * Returns: a newly allocated copy of the original classification
106 | */
107 | GstInferenceClassification * gst_inference_classification_copy (const GstInferenceClassification * self);
108 |
109 | /**
110 | * gst_inference_classification_ref:
111 | * @self: the classification to ref
112 | *
113 | * Increase the reference counter of the classification.
114 | *
115 | * Returns: the same classification, for convenience purposes.
116 | */
117 | GstInferenceClassification * gst_inference_classification_ref (GstInferenceClassification * self);
118 |
119 | /**
120 | * gst_inference_classification_unref:
121 | * @self: the classification to unref
122 | *
123 | * Decreases the reference counter of the classification. When the
124 | * reference counter hits zero, the classification is freed.
125 | */
126 | void gst_inference_classification_unref (GstInferenceClassification * self);
127 |
128 | /**
129 | * gst_inference_classification_to_string:
130 | * @self: the classification to serialize
131 | *
132 | * Serializes the classification into a JSON-like string. The full
133 | * arrays are not included. Free this string after usage using
134 | * g_free()
135 | *
136 | * Returns: a string representing the classification.
137 | */
138 | gchar * gst_inference_classification_to_string (GstInferenceClassification * self, gint level);
139 |
140 | /**
141 | * GST_INFERENCE_CLASSIFICATION_LOCK:
142 | * @c: The GstInferenceClassification to lock
143 | *
144 | * Locks the classification to avoid concurrent access from different
145 | * threads.
146 | */
147 | #define GST_INFERENCE_CLASSIFICATION_LOCK(c) g_mutex_lock (&((c)->mutex))
148 |
149 | /**
150 | * GST_INFERENCE_CLASSIFICATION_UNLOCK:
151 | * @c: The GstInferenceClassification to unlock
152 | *
153 | * Unlocks the prediction to yield the access to other threads.
154 | */
155 | #define GST_INFERENCE_CLASSIFICATION_UNLOCK(c) g_mutex_unlock (&((c)->mutex))
156 |
157 | G_END_DECLS
158 |
159 | #endif // __GST_INFERENCE_CLASSIFICATION__
160 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferencedebug.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "gstinferencedebug.h"
23 |
24 | void
25 | gst_inference_print_predictions (GstVideoInference * vi,
26 | GstDebugCategory * category, GstInferenceMeta * inference_meta)
27 | {
28 | GstInferencePrediction *pred = NULL;
29 | gchar *spred = NULL;
30 |
31 | g_return_if_fail (vi != NULL);
32 | g_return_if_fail (category != NULL);
33 | g_return_if_fail (inference_meta != NULL);
34 |
35 | pred = inference_meta->prediction;
36 | spred = gst_inference_prediction_to_string (pred);
37 |
38 | GST_CAT_LOG (category, "\n%s", spred);
39 |
40 | g_free (spred);
41 | }
42 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferencedebug.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef GST_INFERENCE_DEBUG_H
23 | #define GST_INFERENCE_DEBUG_H
24 |
25 | #include
26 | #include
27 |
28 | G_BEGIN_DECLS
29 | /**
30 | * \brief Display the predictions in the inference meta
31 | *
32 | * \param vi Father object of every architecture
33 | * \param category The debug category
34 | * \param inference_meta Inference Meta
35 | */
36 |
37 | void gst_inference_print_predictions (GstVideoInference * vi,
38 | GstDebugCategory * category, GstInferenceMeta * inference_meta);
39 |
40 | G_END_DECLS
41 | #endif // GST_INFERENCE_DEBUG_H
42 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferencemeta.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "gstinferencemeta.h"
23 |
24 | #include
25 | #include
26 |
27 | static gboolean gst_inference_meta_init (GstMeta * meta,
28 | gpointer params, GstBuffer * buffer);
29 | static void gst_inference_meta_free (GstMeta * meta, GstBuffer * buffer);
30 | static gboolean gst_inference_meta_transform (GstBuffer * transbuf,
31 | GstMeta * meta, GstBuffer * buffer, GQuark type, gpointer data);
32 |
33 | GType
34 | gst_inference_meta_api_get_type (void)
35 | {
36 | static volatile GType type = 0;
37 | static const gchar *tags[] = { GST_META_TAG_VIDEO_STR, NULL
38 | };
39 |
40 | if (g_once_init_enter (&type)) {
41 | GType _type = gst_meta_api_type_register ("GstInferenceMetaAPI", tags);
42 | g_once_init_leave (&type, _type);
43 | }
44 | return type;
45 | }
46 |
47 | /* inference metadata */
48 | const GstMetaInfo *
49 | gst_inference_meta_get_info (void)
50 | {
51 | static const GstMetaInfo *inference_meta_info = NULL;
52 |
53 | if (g_once_init_enter (&inference_meta_info)) {
54 | const GstMetaInfo *meta = gst_meta_register (GST_INFERENCE_META_API_TYPE,
55 | "GstInferenceMeta", sizeof (GstInferenceMeta),
56 | gst_inference_meta_init, gst_inference_meta_free,
57 | gst_inference_meta_transform);
58 | g_once_init_leave (&inference_meta_info, meta);
59 | }
60 | return inference_meta_info;
61 | }
62 |
63 | static gboolean
64 | gst_inference_meta_transform_existing_meta (GstBuffer * dest, GstMeta * meta,
65 | GstBuffer * buffer, GQuark type, gpointer data)
66 | {
67 | GstInferenceMeta *dmeta, *smeta;
68 | GstInferencePrediction *pred = NULL;
69 | gboolean ret = TRUE;
70 | gboolean needs_scale = FALSE;
71 |
72 | g_return_val_if_fail (dest, FALSE);
73 | g_return_val_if_fail (meta, FALSE);
74 | g_return_val_if_fail (buffer, FALSE);
75 |
76 | smeta = (GstInferenceMeta *) meta;
77 | dmeta =
78 | (GstInferenceMeta *) gst_buffer_get_meta (dest,
79 | gst_inference_meta_api_get_type ());
80 |
81 | g_return_val_if_fail (dmeta, FALSE);
82 |
83 | pred =
84 | gst_inference_prediction_find (dmeta->prediction,
85 | smeta->prediction->prediction_id);
86 |
87 | if (!pred) {
88 | GST_ERROR
89 | ("Predictions between metas do not match. Something really wrong happened");
90 | g_return_val_if_reached (FALSE);
91 | }
92 |
93 | needs_scale = gst_inference_prediction_merge (smeta->prediction, pred);
94 |
95 | /* Transfer Stream ID */
96 | g_free (dmeta->stream_id);
97 | dmeta->stream_id = g_strdup (smeta->stream_id);
98 |
99 | if (GST_META_TRANSFORM_IS_COPY (type)) {
100 | GST_LOG ("Copy inference metadata");
101 |
102 | /* The merge already handled the copy */
103 | goto out;
104 | }
105 |
106 | if (GST_VIDEO_META_TRANSFORM_IS_SCALE (type)) {
107 | if (needs_scale) {
108 | GstVideoMetaTransform *trans = (GstVideoMetaTransform *) data;
109 | gst_inference_prediction_scale_ip (pred, trans->out_info, trans->in_info);
110 |
111 | }
112 | goto out;
113 | }
114 |
115 | /* Invalid transformation */
116 | gst_buffer_remove_meta (dest, (GstMeta *) dmeta);
117 | ret = FALSE;
118 |
119 | out:
120 | gst_inference_prediction_unref (pred);
121 | return ret;
122 | }
123 |
124 | static gboolean
125 | gst_inference_meta_transform_new_meta (GstBuffer * dest, GstMeta * meta,
126 | GstBuffer * buffer, GQuark type, gpointer data)
127 | {
128 | GstInferenceMeta *dmeta, *smeta;
129 |
130 | g_return_val_if_fail (dest, FALSE);
131 | g_return_val_if_fail (meta, FALSE);
132 | g_return_val_if_fail (buffer, FALSE);
133 |
134 | smeta = (GstInferenceMeta *) meta;
135 | dmeta =
136 | (GstInferenceMeta *) gst_buffer_add_meta (dest, GST_INFERENCE_META_INFO,
137 | NULL);
138 | if (!dmeta) {
139 | GST_ERROR ("Unable to add meta to buffer");
140 | return FALSE;
141 | }
142 |
143 | gst_inference_prediction_unref (dmeta->prediction);
144 |
145 | /* Transfer Stream ID */
146 | g_free (dmeta->stream_id);
147 | dmeta->stream_id = g_strdup (smeta->stream_id);
148 |
149 | if (GST_META_TRANSFORM_IS_COPY (type)) {
150 | GST_LOG ("Copy inference metadata");
151 |
152 | dmeta->prediction = gst_inference_prediction_copy (smeta->prediction);
153 | return TRUE;
154 | }
155 |
156 | if (GST_VIDEO_META_TRANSFORM_IS_SCALE (type)) {
157 | GstVideoMetaTransform *trans = (GstVideoMetaTransform *) data;
158 |
159 | dmeta->prediction =
160 | gst_inference_prediction_scale (smeta->prediction, trans->out_info,
161 | trans->in_info);
162 | return TRUE;
163 | }
164 |
165 | /* Invalid transformation */
166 | gst_buffer_remove_meta (dest, (GstMeta *) dmeta);
167 | return FALSE;
168 | }
169 |
170 | static gboolean
171 | gst_inference_meta_transform (GstBuffer * dest, GstMeta * meta,
172 | GstBuffer * buffer, GQuark type, gpointer data)
173 | {
174 | GstMeta *dmeta;
175 |
176 | g_return_val_if_fail (dest, FALSE);
177 | g_return_val_if_fail (meta, FALSE);
178 | g_return_val_if_fail (buffer, FALSE);
179 |
180 | GST_LOG ("Transforming inference metadata");
181 |
182 | dmeta = gst_buffer_get_meta (dest, gst_inference_meta_api_get_type ());
183 | if (!dmeta) {
184 | return gst_inference_meta_transform_new_meta (dest, meta, buffer, type,
185 | data);
186 | } else {
187 | return gst_inference_meta_transform_existing_meta (dest, meta, buffer, type,
188 | data);
189 | }
190 | }
191 |
192 | static gboolean
193 | gst_inference_meta_init (GstMeta * meta, gpointer params, GstBuffer * buffer)
194 | {
195 | GstInferenceMeta *imeta = (GstInferenceMeta *) meta;
196 | GstInferencePrediction *root;
197 |
198 | /* Create root Prediction */
199 | root = gst_inference_prediction_new ();
200 |
201 | imeta->prediction = root;
202 | imeta->stream_id = NULL;
203 |
204 | return TRUE;
205 | }
206 |
207 | static void
208 | gst_inference_meta_free (GstMeta * meta, GstBuffer * buffer)
209 | {
210 | GstInferenceMeta *imeta = NULL;
211 |
212 | g_return_if_fail (meta != NULL);
213 | g_return_if_fail (buffer != NULL);
214 |
215 | imeta = (GstInferenceMeta *) meta;
216 | gst_inference_prediction_unref (imeta->prediction);
217 | g_free (imeta->stream_id);
218 | }
219 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferencemeta.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef GST_INFERENCE_META_H
23 | #define GST_INFERENCE_META_H
24 |
25 | #include
26 |
27 | #include
28 |
29 | G_BEGIN_DECLS
30 | #define GST_INFERENCE_META_API_TYPE (gst_inference_meta_api_get_type())
31 | #define GST_INFERENCE_META_INFO (gst_inference_meta_get_info())
32 |
33 | /**
34 | * Basic bounding box structure for detection
35 | */
36 | typedef struct _BBox BBox;
37 | struct _BBox
38 | {
39 | gint label;
40 | gdouble prob;
41 | gdouble x;
42 | gdouble y;
43 | gdouble width;
44 | gdouble height;
45 | };
46 |
47 | /**
48 | * Implements the placeholder for inference information.
49 | */
50 | typedef struct _GstInferenceMeta GstInferenceMeta;
51 | struct _GstInferenceMeta
52 | {
53 | GstMeta meta;
54 |
55 | GstInferencePrediction *prediction;
56 |
57 | gchar *stream_id;
58 | };
59 |
60 |
61 | GType gst_inference_meta_api_get_type (void);
62 | const GstMetaInfo *gst_inference_meta_get_info (void);
63 |
64 | G_END_DECLS
65 | #endif // GST_INFERENCE_META_H
66 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferencepostprocess.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include
23 | #include
24 |
25 | #ifndef __GST_INFERENCE_POSTPROCESS_H__
26 | #define __GST_INFERENCE_POSTPROCESS_H__
27 |
28 | G_BEGIN_DECLS
29 | /**
30 | * \brief Fill all the data for the boxes
31 | *
32 | * \param vi Father object of every architecture
33 | * \param prediction Value of the prediction
34 | * \param valid_prediction Check if the prediction is valid
35 | * \param resulting_boxes The output boxes of the prediction
36 | * \param elements The number of objects
37 | * \param obj_thresh Objectness threshold
38 | * \param prob_thresh Class probability threshold
39 | * \param iou_thresh Intersection over union threshold
40 | * \param probabilities Probabilities of each classes
41 | * \param num_classes The number of classes
42 | */
43 | gboolean gst_create_boxes (GstVideoInference * vi, const gpointer prediction,
44 | gboolean * valid_prediction, BBox ** resulting_boxes,
45 | gint * elements, gfloat obj_thresh, gfloat prob_thresh, gfloat iou_thresh,
46 | gdouble ** probabilities, gint num_classes);
47 |
48 | /**
49 | * \brief Fill all the data for the boxes
50 | *
51 | * \param vi Father object of every architecture
52 | * \param prediction Value of the prediction
53 | * \param valid_prediction Check if the prediction is valid
54 | * \param resulting_boxes The output boxes of the prediction
55 | * \param elements The number of objects
56 | * \param obj_thresh Objectness threshold
57 | * \param prob_thresh Class probability threshold
58 | * \param iou_thresh Intersection over union threshold
59 | * \param probabilities Probabilities of each classes
60 | * \param num_classes The number of classes
61 | */
62 | gboolean gst_create_boxes_float (GstVideoInference * vi,
63 | const gpointer prediction, gboolean * valid_prediction,
64 | BBox ** resulting_boxes, gint * elements, gdouble obj_thresh,
65 | gdouble prob_thresh, gdouble iou_thresh, gdouble ** probabilities,
66 | gint num_classes);
67 |
68 | /**
69 | * \brief Create Prediction from box
70 | *
71 | * \param vi Father object of every architecture
72 | * \param box Box used to fill Prediction
73 | * \param labels_list List with all possible lables
74 | * \param num_labels The number of posibble labels
75 | * \param probabilities Probabilities of each classes
76 | */
77 | GstInferencePrediction *gst_create_prediction_from_box (GstVideoInference * vi,
78 | BBox * box, gchar **labels_list, gint num_labels, const gdouble * probabilities);
79 |
80 | /**
81 | * \brief Create Classification from prediction data
82 | *
83 | * \param vi Father object of every architecture
84 | * \param prediction Value of the prediction
85 | * \param predsize Size of the prediction
86 | * \param labels_list List with all possible lables
87 | * \param num_labels The number of posibble labels
88 | */
89 | GstInferenceClassification *gst_create_class_from_prediction (GstVideoInference * vi,
90 | const gpointer prediction, gsize predsize, gchar **labels_list, gint num_labels);
91 | /**
92 | * \brief Remove duplicated boxes
93 | * \param iou_thresh Threshold of iou to consider that a box is duplicated
94 | * \param boxes Array of bounding boxes
95 | * \param num_boxes Amount of boxes in the array
96 | */
97 | void gst_remove_duplicated_boxes (gdouble iou_thresh, BBox * boxes,
98 | gint * num_boxes);
99 |
100 | G_END_DECLS
101 | #endif
102 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferenceprediction.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __GST_INFERENCE_PREDICTION__
23 | #define __GST_INFERENCE_PREDICTION__
24 |
25 | #include
26 | #include
27 |
28 | G_BEGIN_DECLS
29 |
30 | typedef struct _BoundingBox BoundingBox;
31 | typedef struct _GstInferencePrediction GstInferencePrediction;
32 |
33 | /**
34 | * BoundingBox:
35 | * @x: horizontal coordinate of the upper left position of the
36 | * bounding box in pixels
37 | * @y: vertical coordinate of the upper left position of the bounding
38 | * box in pixels
39 | * @width: width of the bounding box in pixels
40 | * @height: height of the bounding box in pixels
41 | *
42 | * Size and coordinates of a prediction region
43 | */
44 | struct _BoundingBox
45 | {
46 | gint x;
47 | gint y;
48 | guint width;
49 | guint height;
50 | };
51 |
52 | /**
53 | * GstInferencePrediction:
54 | * @prediction_id: unique id for this specific prediction
55 | * @enabled: flag indicating wether or not this prediction should be
56 | * used for further inference
57 | * @bbox: the BoundingBox for this specific prediction
58 | * @classifications: a linked list of GstInfereferenceClassification
59 | * associated to this prediction
60 | * @predictions: a n-ary tree of child predictions within this
61 | * specific prediction. It is recommended to to access the tree
62 | * directly, but to use this module's API to interact with the
63 | * children.
64 | *
65 | * Abstraction that represents a prediction
66 | */
67 | struct _GstInferencePrediction
68 | {
69 | /**/
70 | GstMiniObject base;
71 | GMutex mutex;
72 |
73 | /**/
74 | guint64 prediction_id;
75 | gboolean enabled;
76 | BoundingBox bbox;
77 | GList * classifications;
78 | GNode * predictions;
79 | };
80 |
81 | /**
82 | * gst_inference_prediction_new:
83 | *
84 | * Creates a new GstInferencePrediction. Values can be later assigned
85 | * manually, however these assignments should be done with the
86 | * GST_INFERENCE_PREDICTION_LOCK held. See
87 | * gst_inference_prediction_new_full for a thread safe version.
88 | *
89 | * Returns: A newly allocated and initialized GstInferencePrediction.
90 | */
91 | GstInferencePrediction * gst_inference_prediction_new (void);
92 |
93 | /**
94 | * gst_inference_prediction_new_full:
95 | * @bbox: The bounding box of this prediction.
96 | *
97 | * Creates a new GstInferencePrediction and initializes its internal
98 | * values.
99 | *
100 | * Returns: A newly allocated and initialized GstInferencePrediction.
101 | */
102 | GstInferencePrediction * gst_inference_prediction_new_full (BoundingBox *bbox);
103 |
104 | /**
105 | * gst_inference_prediction_reset:
106 | * @self: the prediction to reset
107 | *
108 | * Clears a prediction, effectively removing al children and resetting
109 | * all members.
110 | */
111 | void gst_inference_prediction_reset (GstInferencePrediction * self);
112 |
113 | /**
114 | * gst_inference_prediction_copy:
115 | * @self: the prediction to copy
116 | *
117 | * Copies a prediction into a newly allocated one. This is a deep
118 | * copy, meaning that all children and classifications are copied as
119 | * well. No references are shared.
120 | *
121 | * Returns: a newly allocated copy of the original prediction
122 | */
123 | GstInferencePrediction * gst_inference_prediction_copy (const GstInferencePrediction * self);
124 |
125 | /**
126 | * gst_inference_prediction_ref:
127 | * @self: the prediction to ref
128 | *
129 | * Increase the reference counter of the prediction.
130 | *
131 | * Returns: the same prediction, for convenience purposes.
132 | */
133 | GstInferencePrediction * gst_inference_prediction_ref (GstInferencePrediction * self);
134 |
135 | /**
136 | * gst_inference_prediction_unref:
137 | * @self: the prediction to unref
138 | *
139 | * Decreases the reference counter of the prediction. When the
140 | * reference counter hits zero, the prediction is freed.
141 | */
142 | void gst_inference_prediction_unref (GstInferencePrediction * self);
143 |
144 | /**
145 | * gst_inference_prediction_to_string:
146 | * @self: the prediction to serialize
147 | *
148 | * Serializes the prediction along with it's classifications and
149 | * children into a JSON-like string. Free this string after usage
150 | * using g_free()
151 | *
152 | * Returns: a string representing the prediction.
153 | */
154 | gchar * gst_inference_prediction_to_string (GstInferencePrediction * self);
155 |
156 | /**
157 | * gst_inference_prediction_append:
158 | * @self: the parent prediction
159 | * @child: the prediction to append as a child
160 | *
161 | * Append a new prediction as part of the parent prediction
162 | * children. The parent takes ownership, use
163 | * gst_inference_prediction_ref() if you wish to keep a reference.
164 | */
165 | void gst_inference_prediction_append (GstInferencePrediction * self, GstInferencePrediction * child);
166 |
167 | /**
168 | * gst_inference_prediction_get_children:
169 | * @self: the parent prediction
170 | *
171 | * Gets a list of the immediate children of the current prediction. In
172 | * other words, the children of these childrens are not returned. The
173 | * references of these children are still owned by the parent.
174 | *
175 | * Returns: A linked list of the child predictions.
176 | */
177 | GSList * gst_inference_prediction_get_children (GstInferencePrediction * self);
178 |
179 | /**
180 | * gst_inference_prediction_append_classification:
181 | * @self: the parent prediction
182 | * @c: the classification to append to the prediction
183 | *
184 | * A new GstInferenceClassification to associate with this
185 | * prediction. The prediction takes ownership of the classification
186 | */
187 | void gst_inference_prediction_append_classification (GstInferencePrediction * self,
188 | GstInferenceClassification * c);
189 |
190 | /**
191 | * gst_inference_prediction_scale:
192 | * @self: the prediction to scale
193 | * @to: the resulting image size
194 | * @from: the original image size
195 | *
196 | * Modifies the BoundingBox associated with this prediction (and all
197 | * its children) to scale to the new image size. This is typically
198 | * used by the GstMeta subsystem automatically and not for public
199 | * usage.
200 | *
201 | * Returns: a newly allocated and scaled prediction.
202 | */
203 | GstInferencePrediction * gst_inference_prediction_scale (GstInferencePrediction * self,
204 | GstVideoInfo * to, GstVideoInfo * from);
205 |
206 | /**
207 | * gst_inference_prediction_scale_ip:
208 | * @self: the prediction to scale in place
209 | * @to: the resulting image size
210 | * @from: the original image size
211 | *
212 | * Modifies the BoundingBox associated with this prediction (and all
213 | * its children) to scale to the new image size. This is typically
214 | * used by the GstMeta subsystem automatically and not for public
215 | * usage.
216 | */
217 | void gst_inference_prediction_scale_ip (GstInferencePrediction * self,
218 | GstVideoInfo * to, GstVideoInfo * from);
219 |
220 | /**
221 | * gst_inference_prediction_find:
222 | * @self: the root prediction
223 | * @id: the prediction_id of the prediction to return
224 | *
225 | * Traverses the prediction tree looking for a child with the given
226 | * id.
227 | *
228 | * Returns: a reference to the prediction with id or NULL if not
229 | * found. Unref after usage.
230 | */
231 | GstInferencePrediction * gst_inference_prediction_find (GstInferencePrediction * self,
232 | guint64 id);
233 |
234 | /**
235 | * gst_inference_prediction_get_enabled:
236 | * @self: the root prediction
237 | *
238 | * Traverse the prediction three saving the predictions that are enabled.
239 | *
240 | * Returns: a GList of predictions that are enabled.
241 | */
242 | GList * gst_inference_prediction_get_enabled (GstInferencePrediction * self);
243 |
244 | /**
245 | * gst_inference_prediction_merge:
246 | * @src: the source prediction
247 | * @dst: the destination prediction
248 | *
249 | * Copies the extra information from src to dst.
250 | *
251 | * Returns: TRUE if new sub-predictions were added, FALSE otherwise.
252 | */
253 | gboolean gst_inference_prediction_merge (GstInferencePrediction * src, GstInferencePrediction * dst);
254 |
255 | /**
256 | * GST_INFERENCE_PREDICTION_LOCK:
257 | * @p: The GstInferencePrediction to lock
258 | *
259 | * Locks the prediction to avoid concurrent access from different
260 | * threads.
261 | */
262 | #define GST_INFERENCE_PREDICTION_LOCK(p) g_mutex_lock (&((p)->mutex))
263 |
264 | /**
265 | * GST_INFERENCE_PREDICTION_UNLOCK:
266 | * @p: The GstInferencePrediction to unlock
267 | *
268 | * Unlocks the prediction to yield the access to other threads.
269 | */
270 | #define GST_INFERENCE_PREDICTION_UNLOCK(p) g_mutex_unlock (&((p)->mutex))
271 |
272 | G_END_DECLS
273 |
274 | #endif // __GST_INFERENCE_PREDICTION__
275 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferencepreprocess.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "gstinferencepreprocess.h"
23 | #include
24 |
25 | static gboolean gst_configure_format_values (GstVideoFrame * inframe,
26 | gint * first_index, gint * last_index, gint * offset, gint * channels);
27 | static void gst_apply_means_std (GstVideoFrame * inframe,
28 | GstVideoFrame * outframe, gint first_index, gint last_index,
29 | gint offset, gint channels, const gdouble mean_red,
30 | const gdouble mean_green, const gdouble mean_blue,
31 | const gdouble std_r, const gdouble std_g, const gdouble std_b,
32 | const gint model_channels);
33 |
34 | static void gst_apply_gray_normalization (GstVideoFrame * inframe,
35 | GstVideoFrame * outframe, gdouble std, gdouble offset);
36 |
37 | static void
38 | gst_apply_means_std (GstVideoFrame * inframe, GstVideoFrame * outframe,
39 | gint first_index, gint last_index, gint offset, gint channels,
40 | const gdouble mean_red, const gdouble mean_green,
41 | const gdouble mean_blue, const gdouble std_r, const gdouble std_g,
42 | const gdouble std_b, const gint model_channels)
43 | {
44 | gint i, j, pixel_stride, width, height;
45 |
46 | g_return_if_fail (inframe != NULL);
47 | g_return_if_fail (outframe != NULL);
48 |
49 | pixel_stride = GST_VIDEO_FRAME_COMP_STRIDE (inframe, 0) / channels;
50 | width = GST_VIDEO_FRAME_WIDTH (inframe);
51 | height = GST_VIDEO_FRAME_HEIGHT (inframe);
52 |
53 | for (i = 0; i < height; ++i) {
54 | for (j = 0; j < width; ++j) {
55 | ((gfloat *) outframe->data[0])[(i * width + j) * model_channels +
56 | first_index] =
57 | (((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels +
58 | 0 + offset] - mean_red) * std_r;
59 | ((gfloat *) outframe->data[0])[(i * width + j) * model_channels + 1] =
60 | (((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels +
61 | 1 + offset] - mean_green) * std_g;
62 | ((gfloat *) outframe->data[0])[(i * width + j) * model_channels +
63 | last_index] =
64 | (((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels +
65 | 2 + offset] - mean_blue) * std_b;
66 | }
67 | }
68 | }
69 |
70 | static gboolean
71 | gst_configure_format_values (GstVideoFrame * inframe, gint * first_index,
72 | gint * last_index, gint * offset, gint * channels)
73 | {
74 | g_return_val_if_fail (inframe != NULL, FALSE);
75 | g_return_val_if_fail (first_index != NULL, FALSE);
76 | g_return_val_if_fail (last_index != NULL, FALSE);
77 | g_return_val_if_fail (offset != NULL, FALSE);
78 | g_return_val_if_fail (channels != NULL, FALSE);
79 |
80 | *channels = GST_VIDEO_FRAME_COMP_PSTRIDE (inframe, 0);
81 | switch (GST_VIDEO_FRAME_FORMAT (inframe)) {
82 | case GST_VIDEO_FORMAT_RGB:
83 | case GST_VIDEO_FORMAT_RGBx:
84 | case GST_VIDEO_FORMAT_RGBA:
85 | *first_index = 0;
86 | *last_index = 2;
87 | *offset = 0;
88 | break;
89 | case GST_VIDEO_FORMAT_BGR:
90 | case GST_VIDEO_FORMAT_BGRx:
91 | case GST_VIDEO_FORMAT_BGRA:
92 | *first_index = 2;
93 | *last_index = 0;
94 | *offset = 0;
95 | break;
96 | case GST_VIDEO_FORMAT_xRGB:
97 | case GST_VIDEO_FORMAT_ARGB:
98 | *first_index = 0;
99 | *last_index = 2;
100 | *offset = 1;
101 | break;
102 | case GST_VIDEO_FORMAT_xBGR:
103 | case GST_VIDEO_FORMAT_ABGR:
104 | *first_index = 2;
105 | *last_index = 0;
106 | *offset = 1;
107 | break;
108 | case GST_VIDEO_FORMAT_GRAY8:
109 | *first_index = 0;
110 | *last_index = 0;
111 | *offset = 0;
112 | break;
113 | default:
114 | return FALSE;
115 | break;
116 | }
117 | return TRUE;
118 | }
119 |
120 | gboolean
121 | gst_normalize (GstVideoFrame * inframe, GstVideoFrame * outframe, gdouble mean,
122 | gdouble std, gint model_channels)
123 | {
124 | gint first_index = 0, last_index = 0, offset = 0, channels = 0;
125 | g_return_val_if_fail (inframe != NULL, FALSE);
126 | g_return_val_if_fail (outframe != NULL, FALSE);
127 | if (gst_configure_format_values (inframe, &first_index, &last_index, &offset,
128 | &channels) == FALSE) {
129 | return FALSE;
130 | }
131 |
132 | gst_apply_means_std (inframe, outframe, first_index, last_index, offset,
133 | channels, mean, mean, mean, std, std, std, model_channels);
134 |
135 | return TRUE;
136 | }
137 |
138 | gboolean
139 | gst_subtract_mean (GstVideoFrame * inframe, GstVideoFrame * outframe,
140 | gdouble mean_red, gdouble mean_green, gdouble mean_blue,
141 | gint model_channels)
142 | {
143 | gint first_index = 0, last_index = 0, offset = 0, channels = 0;
144 | const gdouble std = 1;
145 | g_return_val_if_fail (inframe != NULL, FALSE);
146 | g_return_val_if_fail (outframe != NULL, FALSE);
147 | if (gst_configure_format_values (inframe, &first_index, &last_index, &offset,
148 | &channels) == FALSE) {
149 | return FALSE;
150 | }
151 |
152 | gst_apply_means_std (inframe, outframe, first_index, last_index, offset,
153 | channels, mean_red, mean_green, mean_blue, std, std, std, model_channels);
154 | return TRUE;
155 | }
156 |
157 | gboolean
158 | gst_pixel_to_float (GstVideoFrame * inframe, GstVideoFrame * outframe,
159 | gint model_channels)
160 | {
161 | gint first_index = 0, last_index = 0, offset = 0, channels = 0;
162 | const gdouble std = 1, mean = 0;
163 | g_return_val_if_fail (inframe != NULL, FALSE);
164 | g_return_val_if_fail (outframe != NULL, FALSE);
165 | if (gst_configure_format_values (inframe, &first_index, &last_index, &offset,
166 | &channels) == FALSE) {
167 | return FALSE;
168 | }
169 |
170 | gst_apply_means_std (inframe, outframe, first_index, last_index, offset,
171 | channels, mean, mean, mean, std, std, std, model_channels);
172 | return TRUE;
173 | }
174 |
175 | gboolean
176 | gst_normalize_gray_image (GstVideoFrame * inframe, GstVideoFrame * outframe,
177 | gdouble mean, gint offset, gint model_channels)
178 | {
179 | gint first_index = 0, last_index = 0;
180 | g_return_val_if_fail (inframe != NULL, FALSE);
181 | g_return_val_if_fail (outframe != NULL, FALSE);
182 | if (gst_configure_format_values (inframe, &first_index, &last_index, &offset,
183 | &model_channels) == FALSE) {
184 | return FALSE;
185 | }
186 |
187 | gst_apply_gray_normalization (inframe, outframe, mean, offset);
188 |
189 | return TRUE;
190 | }
191 |
192 | static void
193 | gst_apply_gray_normalization (GstVideoFrame * inframe, GstVideoFrame * outframe,
194 | gdouble mean, gdouble offset)
195 | {
196 | gint i = 0, j = 0, pixel_stride = 0, width = 0, height = 0;
197 | const gdouble rcp_mean = 1. / mean;
198 |
199 | g_return_if_fail (inframe != NULL);
200 | g_return_if_fail (outframe != NULL);
201 |
202 | pixel_stride = GST_VIDEO_FRAME_COMP_STRIDE (inframe, 0);
203 | width = GST_VIDEO_FRAME_WIDTH (inframe);
204 | height = GST_VIDEO_FRAME_HEIGHT (inframe);
205 |
206 | for (i = 0; i < height; ++i) {
207 | for (j = 0; j < width; ++j) {
208 | ((gfloat *) outframe->data[0])[(i * width + j)] =
209 | (((guchar *) inframe->data[0])[(i * pixel_stride +
210 | j)] * rcp_mean - offset);
211 | }
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstinferencepreprocess.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __GST_INFERENCE_PREPROCESS_H__
23 | #define __GST_INFERENCE_PREPROCESS_H__
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | /**
30 | * \brief Normalization with values between 0 and 1
31 | *
32 | * \param inframe The input frame
33 | * \param outframe The output frame after preprocess
34 | * \param mean The mean value of the channel
35 | * \param std The standart deviation of the channel
36 | * \param model_channels The number of channels of the model
37 | */
38 |
39 | gboolean gst_normalize(GstVideoFrame * inframe, GstVideoFrame * outframe, gdouble mean, gdouble std, gint model_channels);
40 |
41 | /**
42 | * \brief Substract the mean value to every pixel
43 | *
44 | * \param inframe The input frame
45 | * \param outframe The output frame after preprocess
46 | * \param mean_red The mean value of the channel red
47 | * \param mean_green The mean value of the channel green
48 | * \param mean_blue The mean value of the channel blue
49 | * \param model_channels The number of channels of the model
50 | */
51 |
52 | gboolean gst_subtract_mean(GstVideoFrame * inframe, GstVideoFrame * outframe, gdouble mean_red, gdouble mean_green, gdouble mean_blue, gint model_channels);
53 |
54 | /**
55 | * \brief Change every pixel value to float
56 | *
57 | * \param inframe The input frame
58 | * \param outframe The output frame after preprocess
59 | * \param model_channels The number of channels of the model
60 | */
61 |
62 | gboolean gst_pixel_to_float(GstVideoFrame * inframe, GstVideoFrame * outframe, gint model_channels);
63 |
64 | /**
65 | * \brief Normalize grayscale image the image within a given mean and offset
66 | *
67 | * \param inframe The input frame
68 | * \param outframe The output frame after preprocess
69 | * \param mean The mean value of the image
70 | * \param offset The value that will be substracted to every pixel
71 | * \param model_channels The number of channels of the model
72 | */
73 | gboolean
74 | gst_normalize_gray_image (GstVideoFrame * inframe, GstVideoFrame * outframe,
75 | gdouble mean, gint offset, gint model_channels);
76 | G_END_DECLS
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/gstvideoinference.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __GST_VIDEO_INFERENCE_H__
23 | #define __GST_VIDEO_INFERENCE_H__
24 |
25 | #include
26 | #include
27 |
28 | G_BEGIN_DECLS
29 | #define GST_TYPE_VIDEO_INFERENCE gst_video_inference_get_type ()
30 | G_DECLARE_DERIVABLE_TYPE (GstVideoInference, gst_video_inference, GST,
31 | VIDEO_INFERENCE, GstElement);
32 |
33 | struct _GstVideoInferenceClass
34 | {
35 | GstElementClass parent_class;
36 |
37 | gboolean (*start) (GstVideoInference * self);
38 | gboolean (*stop) (GstVideoInference * self);
39 | gboolean (*preprocess) (GstVideoInference * self, GstVideoFrame * inframe,
40 | GstVideoFrame * outframe);
41 | gboolean (*postprocess) (GstVideoInference * self,
42 | const gpointer prediction, gsize size, GstMeta * meta_model,
43 | GstVideoInfo * info_model, gboolean * valid_prediction, gchar **labels_list, gint num_labels);
44 | };
45 |
46 | G_END_DECLS
47 | #endif //__GST_VIDEO_INFERENCE_H__
48 |
--------------------------------------------------------------------------------
/gst-libs/gst/r2inference/meson.build:
--------------------------------------------------------------------------------
1 | gstinference_sources = [
2 | 'gstbasebackend.cc',
3 | 'gstchildinspector.c',
4 | 'gstinferencebackend.cc',
5 | 'gstinferencebackends.cc',
6 | 'gstinferencedebug.c',
7 | 'gstinferenceclassification.c',
8 | 'gstinferencemeta.c',
9 | 'gstinferenceprediction.c',
10 | 'gstinferencepostprocess.c',
11 | 'gstinferencepreprocess.c',
12 | 'gstvideoinference.c'
13 | ]
14 |
15 | gstinference_headers = [
16 | 'gstbasebackend.h',
17 | 'gstbasebackendsubclass.h',
18 | 'gstchildinspector.h',
19 | 'gstinferencebackends.h',
20 | 'gstinferencedebug.h',
21 | 'gstinferencemeta.h',
22 | 'gstinferencepostprocess.h',
23 | 'gstinferencepreprocess.h',
24 | 'gstinferenceclassification.h',
25 | 'gstinferenceprediction.h',
26 | 'gstvideoinference.h'
27 | ]
28 |
29 | if r2inference_dep.found()
30 | gstinference = library('gstinference-1.0',
31 | gstinference_sources,
32 | c_args : c_args,
33 | include_directories : [configinc, inference_inc_dir],
34 | version : version_arr[0],
35 | install : true,
36 | dependencies : [gst_base_dep, gst_video_dep, r2inference_dep],
37 | )
38 |
39 | gstinference_dep = declare_dependency(link_with: gstinference,
40 | include_directories : [inference_inc_dir],
41 | dependencies : [gst_video_dep, r2inference_dep])
42 |
43 | install_headers(gstinference_headers, subdir : 'gstreamer-1.0/gst/r2inference')
44 | pkgconfig.generate(gstinference, install_dir : plugins_pkgconfig_install_dir)
45 | else
46 | error('r2inference not found. Please install before proceeding with the installation.')
47 | endif
48 |
--------------------------------------------------------------------------------
/gst-libs/meson.build:
--------------------------------------------------------------------------------
1 | subdir('gst')
2 |
--------------------------------------------------------------------------------
/gst/inferenceutils/cropelement.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "cropelement.h"
23 |
24 | CropElement::CropElement () {
25 | this->element = nullptr;
26 | this->top = 0;
27 | this->bottom = 0;
28 | this->right = 0;
29 | this->left = 0;
30 | }
31 |
32 | bool
33 | CropElement::Validate () {
34 | GstElement *element;
35 |
36 | this->mutex.lock ();
37 | if (nullptr == this->element) {
38 | const std::string factory = this->GetFactory ();
39 | this->element = gst_element_factory_make (factory.c_str (), nullptr);
40 | }
41 | element = this->element;
42 | this->mutex.unlock ();
43 |
44 | return element != nullptr;
45 | }
46 |
47 | GstElement *
48 | CropElement::GetElement () {
49 | GstElement *element;
50 | element = nullptr;
51 | bool validated = Validate();
52 | this->mutex.lock ();
53 | if (validated) {
54 | element = this->element;
55 | }else{
56 | const std::string factory = this->GetFactory ();
57 | GST_ERROR_OBJECT (this->element, "Unable to initialize the element %s", factory.c_str ());
58 | }
59 |
60 | this->mutex.unlock ();
61 |
62 | return element;
63 | }
64 |
65 | void
66 | CropElement::Reset () {
67 | this->SetCroppingSize(0, 0, 0, 0);
68 | }
69 |
70 | void
71 | CropElement::SetCroppingSize (gint top, gint bottom, gint right, gint left) {
72 | this->mutex.lock ();
73 | this->top = top;
74 | this->bottom = bottom;
75 | this->right = right;
76 | this->left = left;
77 |
78 | this->UpdateElement (this->element,
79 | this->top,
80 | this->bottom,
81 | this->right,
82 | this->left);
83 | this->mutex.unlock ();
84 | }
85 |
86 | CropElement::~CropElement () {
87 | if (nullptr != this->element) {
88 | gst_object_unref (this->element);
89 | this->element = nullptr;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/gst/inferenceutils/cropelement.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __CROP_ELEMENT_H__
23 | #define __CROP_ELEMENT_H__
24 |
25 | #include
26 | #include
27 | #include
28 |
29 |
30 | class CropElement {
31 | public:
32 | CropElement ();
33 | bool Validate ();
34 | GstElement *GetElement ();
35 | void SetCroppingSize (gint top, gint bottom, gint right, gint left);
36 | virtual ~ CropElement ();
37 | virtual const std::string& GetFactory () const = 0;
38 | virtual GstPad *GetSinkPad () = 0;
39 | virtual GstPad *GetSrcPad () = 0;
40 | void Reset ();
41 |
42 | protected:
43 | virtual void UpdateElement (GstElement *element,
44 | gint top,
45 | gint bottom,
46 | gint right,
47 | gint left) = 0;
48 |
49 | private:
50 | GstElement *element;
51 | gint top;
52 | gint bottom;
53 | gint right;
54 | gint left;
55 | std::mutex mutex;
56 | };
57 |
58 | #endif //__CROP_ELEMENT_H__
59 |
--------------------------------------------------------------------------------
/gst/inferenceutils/gstinferencebin.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __GST_INFERENCE_BIN_H__
23 | #define __GST_INFERENCE_BIN_H__
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_INFERENCE_BIN gst_inference_bin_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstInferenceBin, gst_inference_bin, GST, INFERENCE_BIN,
31 | GstBin)
32 |
33 | G_END_DECLS
34 |
35 | #endif //__GST_INFERENCE_BIN_H__
36 |
--------------------------------------------------------------------------------
/gst/inferenceutils/gstinferencecrop.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_INFERENCECROP_H_
23 | #define _GST_INFERENCECROP_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | #define GST_TYPE_INFERENCE_CROP gst_inference_crop_get_type ()
30 | G_DECLARE_FINAL_TYPE (GstInferenceCrop, gst_inference_crop, GST, INFERENCE_CROP,
31 | GstBin)
32 |
33 | G_END_DECLS
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/gst/inferenceutils/gstinferencedebug.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | /**
23 | * SECTION:element-gstinferencedebug
24 | *
25 | * The inferencedebug element prints the inferencemeta predictions tree
26 | *
27 | *
28 | * Example launch line
29 | * |[
30 | * gst-launch-1.0 v4l2src device=$CAMERA ! "video/x-raw, width=1280, height=720" ! videoconvert ! tee name=t \
31 | t. ! videoscale ! queue ! net.sink_model t. ! queue ! net.sink_bypass \
32 | tinyyolov2 name=net model-location=$MODEL_LOCATION backend=tensorflow backend::input-layer=$INPUT_LAYER \
33 | backend::output-layer=$OUTPUT_LAYER net.src_model ! inferencedebug ! fakesink
34 | * ]|
35 | *
36 | */
37 |
38 | #ifdef HAVE_CONFIG_H
39 | #include "config.h"
40 | #endif
41 |
42 | #include "gstinferencedebug.h"
43 |
44 | #include
45 |
46 | GST_DEBUG_CATEGORY_STATIC (gst_inference_debug_debug_category);
47 | #define GST_CAT_DEFAULT gst_inference_debug_debug_category
48 |
49 | /* prototypes */
50 |
51 | static void gst_inference_debug_print_predictions (GstInferenceDebug *
52 | inferencedebug, GstInferencePrediction * root);
53 | static GstFlowReturn gst_inference_debug_transform_ip (GstBaseTransform * trans,
54 | GstBuffer * buf);
55 |
56 | struct _GstInferenceDebug
57 | {
58 | GstBaseTransform base_inference_debug;
59 | };
60 |
61 | /* pad templates */
62 |
63 | static GstStaticPadTemplate gst_inference_debug_src_template =
64 | GST_STATIC_PAD_TEMPLATE ("src",
65 | GST_PAD_SRC,
66 | GST_PAD_ALWAYS,
67 | GST_STATIC_CAPS_ANY);
68 |
69 | static GstStaticPadTemplate gst_inference_debug_sink_template =
70 | GST_STATIC_PAD_TEMPLATE ("sink",
71 | GST_PAD_SINK,
72 | GST_PAD_ALWAYS,
73 | GST_STATIC_CAPS_ANY);
74 |
75 | /* class initialization */
76 |
77 | G_DEFINE_TYPE_WITH_CODE (GstInferenceDebug, gst_inference_debug,
78 | GST_TYPE_BASE_TRANSFORM,
79 | GST_DEBUG_CATEGORY_INIT (gst_inference_debug_debug_category,
80 | "inferencedebug", 0, "debug category for inferencedebug element"));
81 |
82 | static void
83 | gst_inference_debug_class_init (GstInferenceDebugClass * klass)
84 | {
85 | GstBaseTransformClass *base_transform_class =
86 | GST_BASE_TRANSFORM_CLASS (klass);
87 |
88 | /* Setting up pads and setting metadata should be moved to
89 | base_class_init if you intend to subclass this class. */
90 | gst_element_class_add_static_pad_template (GST_ELEMENT_CLASS (klass),
91 | &gst_inference_debug_src_template);
92 | gst_element_class_add_static_pad_template (GST_ELEMENT_CLASS (klass),
93 | &gst_inference_debug_sink_template);
94 |
95 | gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
96 | "Inference Debug", "Generic",
97 | "Prints InferenceMeta Predictions Tree",
98 | "");
99 |
100 | base_transform_class->transform_ip =
101 | GST_DEBUG_FUNCPTR (gst_inference_debug_transform_ip);
102 | }
103 |
104 | static void
105 | gst_inference_debug_init (GstInferenceDebug * inferencedebug)
106 | {
107 | }
108 |
109 | static void
110 | gst_inference_debug_print_predictions (GstInferenceDebug * inferencedebug,
111 | GstInferencePrediction * root)
112 | {
113 | gchar *prediction_tree = NULL;
114 |
115 | g_return_if_fail (inferencedebug);
116 | g_return_if_fail (root);
117 |
118 | prediction_tree = gst_inference_prediction_to_string (root);
119 |
120 | GST_DEBUG_OBJECT (inferencedebug, "Prediction Tree: \n %s", prediction_tree);
121 |
122 | g_free (prediction_tree);
123 | }
124 |
125 | static GstFlowReturn
126 | gst_inference_debug_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
127 | {
128 | GstInferenceDebug *inferencedebug = GST_INFERENCE_DEBUG (trans);
129 | GstInferenceMeta *meta;
130 |
131 | GST_DEBUG_OBJECT (inferencedebug, "transform_ip");
132 |
133 | meta = (GstInferenceMeta *) gst_buffer_get_meta (buf,
134 | GST_INFERENCE_META_API_TYPE);
135 |
136 | if (NULL == meta) {
137 | GST_LOG_OBJECT (inferencedebug,
138 | "No inference meta found. Buffer passthrough.");
139 | return GST_FLOW_OK;
140 | }
141 |
142 | g_return_val_if_fail (meta->prediction, GST_FLOW_ERROR);
143 |
144 | gst_inference_debug_print_predictions (inferencedebug, meta->prediction);
145 |
146 | return GST_FLOW_OK;
147 | }
148 |
--------------------------------------------------------------------------------
/gst/inferenceutils/gstinferencedebug.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_INFERENCE_DEBUG_H_
23 | #define _GST_INFERENCE_DEBUG_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 | #define GST_TYPE_INFERENCE_DEBUG (gst_inference_debug_get_type())
29 | G_DECLARE_FINAL_TYPE (GstInferenceDebug, gst_inference_debug, GST,
30 | INFERENCE_DEBUG, GstBaseTransform)
31 |
32 | G_END_DECLS
33 | #endif
34 |
--------------------------------------------------------------------------------
/gst/inferenceutils/gstinferencefilter.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef _GST_INFERENCE_FILTER_H_
23 | #define _GST_INFERENCE_FILTER_H_
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 | #define GST_TYPE_INFERENCE_FILTER (gst_inference_filter_get_type())
29 | G_DECLARE_FINAL_TYPE (GstInferenceFilter, gst_inference_filter, GST,
30 | INFERENCE_FILTER, GstBaseTransform)
31 |
32 | G_END_DECLS
33 | #endif
34 |
--------------------------------------------------------------------------------
/gst/inferenceutils/gstinferenceutils.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifdef HAVE_CONFIG_H
23 | #include "config.h"
24 | #endif
25 |
26 | #include "gstinferencebin.h"
27 | #include "gstinferencecrop.h"
28 | #include "gstinferencedebug.h"
29 | #include "gstinferencefilter.h"
30 |
31 | static gboolean
32 | plugin_init (GstPlugin * plugin)
33 | {
34 | gboolean ret = TRUE;
35 |
36 | ret =
37 | gst_element_register (plugin, "inferencebin", GST_RANK_NONE,
38 | GST_TYPE_INFERENCE_BIN);
39 | if (!ret) {
40 | goto out;
41 | }
42 |
43 | ret =
44 | gst_element_register (plugin, "inferencecrop", GST_RANK_NONE,
45 | GST_TYPE_INFERENCE_CROP);
46 | if (!ret) {
47 | goto out;
48 | }
49 |
50 | ret =
51 | gst_element_register (plugin, "inferencedebug", GST_RANK_NONE,
52 | GST_TYPE_INFERENCE_DEBUG);
53 | if (!ret) {
54 | goto out;
55 | }
56 |
57 | ret =
58 | gst_element_register (plugin, "inferencefilter", GST_RANK_NONE,
59 | GST_TYPE_INFERENCE_FILTER);
60 | if (!ret) {
61 | goto out;
62 | }
63 |
64 | out:
65 | return ret;
66 | }
67 |
68 | GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
69 | GST_VERSION_MINOR,
70 | inferenceutils,
71 | "Utils to process inferencemeta information",
72 | plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)
73 |
--------------------------------------------------------------------------------
/gst/inferenceutils/meson.build:
--------------------------------------------------------------------------------
1 | inferenceutils_sources = [
2 | 'cropelement.cc',
3 | 'gstinferencebin.c',
4 | 'gstinferencecrop.cc',
5 | 'gstinferencedebug.c',
6 | 'gstinferencefilter.c',
7 | 'videocrop.cc',
8 | 'gstinferenceutils.c'
9 | ]
10 |
11 | inferenceutils_headers = [
12 | 'cropelement.h',
13 | 'gstinferencebin.h',
14 | 'gstinferencecrop.h',
15 | 'gstinferencedebug.h',
16 | 'gstinferencefilter.h',
17 | 'videocrop.h',
18 | ]
19 |
20 | gstinferenceutils = library('gstinferenceutils',
21 | inferenceutils_sources,
22 | c_args : c_args,
23 | cpp_args : cpp_args,
24 | include_directories : [configinc, inference_inc_dir],
25 | dependencies : [gst_base_dep, gst_video_dep, gstinference_dep],
26 | install : true,
27 | install_dir : plugins_install_dir,
28 | )
29 | plugins += [gstinferenceutils]
30 |
--------------------------------------------------------------------------------
/gst/inferenceutils/videocrop.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "videocrop.h"
23 |
24 | #include
25 | #include
26 |
27 | const std::string&
28 | VideoCrop::GetFactory () const {
29 | return this->factory;
30 | }
31 |
32 | void
33 | VideoCrop::UpdateElement (GstElement *element,
34 | gint top,
35 | gint bottom,
36 | gint right,
37 | gint left) {
38 |
39 | g_return_if_fail (element);
40 |
41 | g_object_set (element,
42 | "top", top,
43 | "bottom", bottom,
44 | "left", left,
45 | "right", right,
46 | "qos",FALSE, NULL);
47 | }
48 |
49 | GstPad *
50 | VideoCrop::GetSinkPad () {
51 | return this->GetPad ("sink");
52 | }
53 |
54 | GstPad *
55 | VideoCrop::GetSrcPad () {
56 | return this->GetPad ("src");
57 | }
58 |
59 | GstPad *
60 | VideoCrop::GetPad (const std::string &name) {
61 | GstElement *element = this->GetElement ();
62 | GstPad *pad = gst_element_get_static_pad (element, name.c_str());
63 |
64 | return pad;
65 | }
66 |
--------------------------------------------------------------------------------
/gst/inferenceutils/videocrop.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __VIDEO_CROP_H__
23 | #define __VIDEO_CROP_H__
24 |
25 | #include "cropelement.h"
26 |
27 | #include
28 |
29 | class VideoCrop: public CropElement {
30 | public:
31 | const std::string& GetFactory () const override;
32 | GstPad *GetSrcPad () override;
33 | GstPad *GetSinkPad () override;
34 |
35 | protected:
36 | void UpdateElement (GstElement *element,
37 | gint top,
38 | gint bottom,
39 | gint right,
40 | gint left) override;
41 | private:
42 | GstPad *GetPad (const std::string &name);
43 | const std::string factory = "videocrop";
44 | };
45 |
46 | #endif //__VIDEO_CROP_H__
47 |
--------------------------------------------------------------------------------
/gst/meson.build:
--------------------------------------------------------------------------------
1 | subdir('inferenceutils')
2 |
--------------------------------------------------------------------------------
/hooks/pre-commit.hook:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Check that the code follows a consistent code style
4 | #
5 |
6 | # Check for existence of indent, and error out if not present.
7 | # On some *bsd systems the binary seems to be called gnunindent,
8 | # so check for that first.
9 |
10 | version=`gnuindent --version 2>/dev/null`
11 | if test "x$version" = "x"; then
12 | version=`gindent --version 2>/dev/null`
13 | if test "x$version" = "x"; then
14 | version=`indent --version 2>/dev/null`
15 | if test "x$version" = "x"; then
16 | echo "GStreamer git pre-commit hook:"
17 | echo "Did not find GNU indent, please install it before continuing."
18 | exit 1
19 | else
20 | INDENT=indent
21 | fi
22 | else
23 | INDENT=gindent
24 | fi
25 | else
26 | INDENT=gnuindent
27 | fi
28 |
29 | case `$INDENT --version` in
30 | GNU*)
31 | ;;
32 | default)
33 | echo "GStreamer git pre-commit hook:"
34 | echo "Did not find GNU indent, please install it before continuing."
35 | echo "(Found $INDENT, but it doesn't seem to be GNU indent)"
36 | exit 1
37 | ;;
38 | esac
39 |
40 | INDENT_PARAMETERS="--braces-on-if-line \
41 | --case-brace-indentation0 \
42 | --case-indentation2 \
43 | --braces-after-struct-decl-line \
44 | --line-length80 \
45 | --no-tabs \
46 | --cuddle-else \
47 | --dont-line-up-parentheses \
48 | --continuation-indentation4 \
49 | --honour-newlines \
50 | --tab-size8 \
51 | --indent-level2 \
52 | --leave-preprocessor-space"
53 |
54 | echo "--Checking style--"
55 | for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.c$"` ; do
56 | # nf is the temporary checkout. This makes sure we check against the
57 | # revision in the index (and not the checked out version).
58 | nf=`git checkout-index --temp ${file} | cut -f 1`
59 | newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1
60 | $INDENT ${INDENT_PARAMETERS} \
61 | $nf -o $newfile 2>> /dev/null
62 | # FIXME: Call indent twice as it tends to do line-breaks
63 | # different for every second call.
64 | $INDENT ${INDENT_PARAMETERS} \
65 | $newfile 2>> /dev/null
66 | diff -u -p "${nf}" "${newfile}"
67 | r=$?
68 | rm "${newfile}"
69 | rm "${nf}"
70 | if [ $r != 0 ] ; then
71 | echo "================================================================================================="
72 | echo " Code style error in: $file "
73 | echo " "
74 | echo " Please fix before committing. Don't forget to run git add before trying to commit again. "
75 | echo " If the whole file is to be committed, this should work (run from the top-level directory): "
76 | echo " "
77 | echo " gst-indent $file; git add $file; git commit"
78 | echo " "
79 | echo "================================================================================================="
80 | exit 1
81 | fi
82 | done
83 | echo "--Checking style pass--"
84 |
--------------------------------------------------------------------------------
/meson.build:
--------------------------------------------------------------------------------
1 | project('GStreamer Inference', ['c', 'cpp'], default_options : ['cpp_std=c++11'],
2 | version : '0.12.1.1',
3 | meson_version : '>= 0.50',)
4 |
5 | project_name = meson.project_name()
6 | # Create an empty configuration object to set config.h information
7 | cdata = configuration_data()
8 | gst_inference_version = meson.project_version()
9 | version_arr = gst_inference_version.split('.')
10 | gst_inference_version_major = version_arr[0].to_int()
11 | gst_inference_version_minor = version_arr[1].to_int()
12 | gst_inference_version_micro = version_arr[2].to_int()
13 | if version_arr.length() == 4
14 | gst_inference_version_nano = version_arr[3].to_int()
15 | else
16 | gst_inference_version_nano = 0
17 | endif
18 | gst_inference_version_is_dev = gst_inference_version_minor % 2 == 1 and gst_inference_version_micro < 90
19 | # Define gstreamer API version
20 | api_version = '1.0'
21 |
22 | # Required versions
23 | gst_req = '>= 1.8.0.1'
24 | r2i_req = '>= 0.12.0'
25 |
26 | # Find external dependencies
27 | gst_dep = dependency('gstreamer-1.0', version : gst_req)
28 | gst_base_dep = dependency('gstreamer-base-1.0', version : gst_req)
29 | gst_check_dep = dependency('gstreamer-check-1.0',version : gst_req)
30 | gst_video_dep = dependency('gstreamer-video-1.0', version : gst_req)
31 | r2inference_dep = dependency('r2inference-0.0', version : r2i_req, required : true)
32 |
33 | opencv_dep = dependency('opencv', version : ['>= 2.3.1', '< 2.4.13'], required : false)
34 | if opencv_dep.found()
35 | cdata.set('OCV_VERSION_LT_3_2', 1)
36 | endif
37 |
38 | if not opencv_dep.found()
39 | opencv_dep = dependency('opencv', version : ['>= 3.2.0', '< 3.5.0'], required : false)
40 |
41 | if not opencv_dep.found()
42 | opencv_dep = dependency('opencv4', version : ['>= 4.0.0'], required : false)
43 | if opencv_dep.found()
44 | cdata.set('OCV_VERSION_4_0', 1)
45 | endif
46 | endif
47 | endif
48 |
49 | ## Dependencies
50 | # Define plugin dependencies
51 | plugin_deps = [gst_dep, gst_base_dep]
52 | # Examples dependencies
53 | example_deps = [gst_dep, gst_base_dep]
54 | # Define test dependencies
55 | test_deps=[gst_dep, gst_base_dep, gst_video_dep, gst_check_dep]
56 |
57 | # Verify if profiling was enabled
58 | if get_option('enable-profiling').enabled()
59 | profiler_dep = dependency('libprofiler')
60 | if(profiler_dep.found())
61 | message('Profiling enabled: Building examples with profiling support.')
62 | link_flags += ['-lprofiler']
63 | c_flags += ['-DPROFILING']
64 | # Update test test_deps to include profiler dependency
65 | test_deps += [profiler_dep]
66 | else
67 | message('MESON_FAIL gperftools profiling library not found.')
68 | endif
69 | endif
70 |
71 | # Define header directories
72 | inference_inc_dir = include_directories('gst-libs/')
73 | configinc = include_directories('.')
74 |
75 | # Define compiler args and include directories
76 | c_args = ['-DHAVE_CONFIG_H']
77 | cpp_args = ['-DHAVE_CONFIG_H']
78 |
79 | # Define installation directories
80 | plugins = []
81 | lib_install_dir = get_option('libdir')
82 | plugins_install_dir = join_paths(get_option('libdir'), 'gstreamer-1.0')
83 | plugins_pkgconfig_install_dir = join_paths(get_option('libdir'), 'pkgconfig')
84 |
85 | # Internal installation directory
86 | plugin_dir = []
87 |
88 | # Get an object returns describing a compiler
89 | cc = meson.get_compiler('c')
90 | cxx = meson.get_compiler('cpp')
91 |
92 | # Verify if the warning flags are available in the compiler
93 | # If the flags is availale for the compiler it wiil be used in all compiler
94 | # invocations with the exception of compile tests.
95 | warning_flags = [
96 | '-Werror',
97 | '-Wmissing-declarations',
98 | '-Wmissing-prototypes',
99 | '-Wredundant-decls',
100 | '-Wundef',
101 | '-Wwrite-strings',
102 | '-Wformat',
103 | '-Wformat-nonliteral',
104 | '-Wformat-security',
105 | '-Wold-style-definition',
106 | '-Winit-self',
107 | '-Wmissing-include-dirs',
108 | '-Waddress',
109 | '-Waggregate-return',
110 | '-Wno-multichar',
111 | '-Wdeclaration-after-statement',
112 | '-Wvla',
113 | '-Wpointer-arith',
114 | ]
115 | foreach extra_arg : warning_flags
116 | if cc.has_argument (extra_arg)
117 | # Add flag to the compiler command line
118 | add_project_arguments([extra_arg], language: 'c')
119 | endif
120 | endforeach
121 |
122 | plugin_url='http://developer.ridgerun.com/wiki/index.php?title=GstInference'
123 | # Set config.h information
124 | cdata.set_quoted('GST_API_VERSION', api_version)
125 | cdata.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
126 | cdata.set_quoted('LIBDIR', join_paths(get_option('prefix'), get_option('libdir')))
127 | cdata.set_quoted('GST_API_VERSION', '1.0')
128 | cdata.set_quoted('GST_LICENSE', 'LGPL')
129 | cdata.set_quoted('PACKAGE', 'gst-inference')
130 | cdata.set_quoted('PACKAGE_NAME', 'GstInference')
131 | cdata.set_quoted('PACKAGE_STRING', 'GstInference @0@'.format(gst_inference_version))
132 | cdata.set_quoted('PACKAGE_TARNAME', 'gst-inference')
133 | cdata.set_quoted('PACKAGE_BUGREPORT', 'https://github.com/RidgeRun/gst-inference')
134 | cdata.set_quoted('PACKAGE_URL', plugin_url)
135 | cdata.set_quoted('PACKAGE_VERSION', gst_inference_version)
136 | cdata.set_quoted('PLUGINDIR', plugin_url)
137 | cdata.set_quoted('VERSION', gst_inference_version)
138 |
139 | if gst_inference_version_nano > 0
140 | # Have GST_ERROR message printed when running from git
141 | cdata.set('GST_LEVEL_DEFAULT', 'GST_LEVEL_ERROR')
142 | else
143 | cdata.set('GST_LEVEL_DEFAULT', 'GST_LEVEL_NONE')
144 | endif
145 |
146 | # GStreamer package name and origin url
147 | gst_package_name = get_option('package-name')
148 | if gst_package_name == ''
149 | if gst_inference_version_nano == 0
150 | gst_package_name = '@0@ source release'.format(project_name)
151 | elif gst_inference_version_nano == 1
152 | gst_package_name = 'GStreamer git'
153 | else
154 | gst_package_name = 'GStreamer prerelease'
155 | endif
156 | endif
157 | cdata.set_quoted('GST_PACKAGE_NAME', gst_package_name)
158 | cdata.set_quoted('GST_PACKAGE_ORIGIN', get_option('package-origin'))
159 |
160 | # These are only needed/used by the ABI tests
161 | host_defines = [
162 | [ 'x86', 'HAVE_CPU_I386' ],
163 | [ 'x86_64', 'HAVE_CPU_X86_64' ],
164 | [ 'arm', 'HAVE_CPU_ARM' ],
165 | [ 'aarch64', 'HAVE_CPU_AARCH64' ],
166 | [ 'mips', 'HAVE_CPU_MIPS' ],
167 | [ 'powerpc', 'HAVE_CPU_PPC' ],
168 | [ 'powerpc64', 'HAVE_CPU_PPC64' ],
169 | [ 'alpha', 'HAVE_CPU_ALPHA' ],
170 | [ 'sparc', 'HAVE_CPU_SPARC' ],
171 | [ 'ia64', 'HAVE_CPU_IA64' ],
172 | [ 'hppa', 'HAVE_CPU_HPPA' ],
173 | [ 'm68k', 'HAVE_CPU_M68K' ],
174 | [ 's390', 'HAVE_CPU_S390' ],
175 | ]
176 | foreach h : host_defines
177 | if h.get(0) == host_machine.cpu()
178 | cdata.set(h.get(1), 1)
179 | else
180 | cdata.set(h.get(1), false)
181 | endif
182 | endforeach
183 |
184 | cdata.set_quoted('HOST_CPU', host_machine.cpu())
185 |
186 | # Verify if the specified header exists
187 | check_headers = [
188 | 'dlfcn.h',
189 | 'inttypes.h',
190 | 'memory.h',
191 | 'poll.h',
192 | 'stdint.h',
193 | 'stdlib.h',
194 | 'stdio_ext.h',
195 | 'strings.h',
196 | 'string.h',
197 | 'sys/param.h',
198 | 'sys/poll.h',
199 | 'sys/prctl.h',
200 | 'sys/socket.h',
201 | 'sys/stat.h',
202 | 'sys/times.h',
203 | 'sys/time.h',
204 | 'sys/types.h',
205 | 'sys/utsname.h',
206 | 'sys/wait.h',
207 | 'ucontext.h',
208 | 'unistd.h',
209 | 'valgrind/valgrind.h',
210 | 'sys/resource.h',
211 | ]
212 |
213 | foreach h : check_headers
214 | if cc.has_header(h)
215 | define = 'HAVE_' + h.underscorify().to_upper()
216 | cdata.set(define, 1)
217 | endif
218 | endforeach
219 |
220 | # Gtk documentation
221 | gnome = import('gnome')
222 |
223 | # Imports pkgconfig module
224 | pkgconfig = import('pkgconfig')
225 |
226 | # Install git hooks
227 | python3 = import('python').find_installation()
228 | run_command(python3, '-c', 'import shutil; shutil.copy("hooks/pre-commit.hook", ".git/hooks/pre-commit")')
229 |
230 | # Meson will generate a header file all the entries in the configuration data object
231 | configure_file(output : 'config.h', configuration : cdata)
232 |
233 | # Enter to each subdirectory and execute the meson.build
234 | subdir('gst-libs')
235 | subdir('gst')
236 | subdir('ext')
237 | subdir('tests')
238 | subdir('docs')
239 |
--------------------------------------------------------------------------------
/meson_options.txt:
--------------------------------------------------------------------------------
1 | # Feature options
2 | option('enable-tests', type : 'feature', value : 'auto', yield : true, description : 'Build tests')
3 | option('enable-examples', type : 'feature', value : 'auto', yield : true, description : 'Build examples')
4 | option('enable-gtk-doc', type : 'boolean', value : true, description : 'Use gtk-doc to build documentation')
5 | option('enable-profiling', type : 'feature', value : 'disabled', yield : true, description: 'Enable profiling building')
6 |
7 | # Common options
8 | option('package-name', type : 'string', yield : true,
9 | description : 'Package name to use in plugins')
10 | option('package-origin', type : 'string', value : 'Unknown package origin', yield : true,
11 | description : 'Package origin URL to use in plugins')
12 |
--------------------------------------------------------------------------------
/tests/check/meson.build:
--------------------------------------------------------------------------------
1 | subdir('process')
2 |
--------------------------------------------------------------------------------
/tests/check/process/meson.build:
--------------------------------------------------------------------------------
1 | # name, condition when to skip the test, extra dependencies and extra files
2 | gst_tests = [
3 | ['test_gst_normalize_function', false, [gstinference_dep, test_deps], [] ],
4 | ['test_gst_pixel_to_float_function', false, [gstinference_dep, test_deps], [] ],
5 | ['test_gst_subtract_mean_function', false, [gstinference_dep, test_deps], [] ],
6 | ]
7 |
8 | # Add C Definitions for tests
9 | test_defines = [
10 | '-DTESTFILE="' + meson.current_source_dir() + '/meson.build"',
11 | ]
12 |
13 | # Define plugins path
14 | plugins_dir = gst_dep.get_pkgconfig_variable('pluginsdir')
15 |
16 | # Create environment object to stores information about the environment
17 | # variables set during tests.
18 | # Define constant enviroment variable
19 | env = environment()
20 | env.set('GST_PLUGIN_SYSTEM_PATH_1_0', '')
21 | env.set('CK_DEFAULT_TIMEOUT', '120')
22 |
23 | # Build and run tests
24 | foreach t : gst_tests
25 | fname = '@0@.c'.format(t.get(0))
26 | test_name = t.get(0).underscorify()
27 | extra_sources = t.get(3, [ ])
28 | extra_deps = t.get(2, [ ])
29 | skip_test = t.get(1, false)
30 | if not skip_test
31 | exe = executable(test_name, fname, extra_sources,
32 | include_directories : [configinc],
33 | c_args : ['-DHAVE_CONFIG_H=1' ] + test_defines,
34 | dependencies : test_deps + extra_deps,
35 | )
36 |
37 | # Define enviroment variable
38 | env.set('GST_REGISTRY', '@0@/@1@.registry'.format(meson.current_build_dir(), test_name))
39 |
40 | # Run tests
41 | test(test_name, exe, env: env, timeout : 60)
42 | endif
43 | endforeach
44 |
--------------------------------------------------------------------------------
/tests/check/process/preprocess_functions_utils.c:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "preprocess_functions_utils.h"
23 |
24 | void
25 | gst_check_output_pixels (GstVideoFrame * outframe, gfloat expected_value_red,
26 | gfloat expected_value_green, gfloat expected_value_blue, gint first_index,
27 | gint last_index, gint model_channels)
28 | {
29 | gfloat out_value;
30 | gint frame_width;
31 | gint frame_height;
32 |
33 | frame_width = GST_VIDEO_FRAME_WIDTH (outframe);
34 | frame_height = GST_VIDEO_FRAME_HEIGHT (outframe);
35 |
36 | fail_if (outframe == NULL);
37 | fail_if (frame_width == 0);
38 | fail_if (frame_height == 0);
39 |
40 | for (gint i = 0; i < frame_height; ++i) {
41 | for (gint j = 0; j < frame_width; ++j) {
42 | out_value =
43 | ((gfloat *) outframe->data[0])[(i * frame_width +
44 | j) * model_channels + first_index];
45 | if (out_value != expected_value_red)
46 | GST_LOG ("Value in index: %d is different to expected value red",
47 | (i * frame_width + j) * model_channels + first_index);
48 | fail_if (out_value != expected_value_red);
49 |
50 | out_value =
51 | ((gfloat *) outframe->data[0])[(i * frame_width +
52 | j) * model_channels + 1];
53 | if (out_value != expected_value_green)
54 | GST_LOG ("Value in index: %d is different to expected value green",
55 | (i * frame_width + j) * model_channels + first_index);
56 | fail_if (out_value != expected_value_green);
57 |
58 | out_value =
59 | ((gfloat *) outframe->data[0])[(i * frame_width +
60 | j) * model_channels + last_index];
61 | if (out_value != expected_value_blue)
62 | GST_LOG ("Value in index: %d is different to expected value blue",
63 | (i * frame_width + j) * model_channels + first_index);
64 | fail_if (out_value != expected_value_blue);
65 | }
66 | }
67 | }
68 |
69 | void
70 | gst_create_test_frames (GstVideoFrame * inframe, GstVideoFrame * outframe,
71 | guchar value_red, guchar value_green, guchar value_blue, gint buffer_size,
72 | gint width, gint height, gint offset, GstVideoFormat format)
73 | {
74 | gboolean ret = FALSE;
75 | GstAllocationParams params;
76 | GstMapFlags flags;
77 | guint pixel_stride;
78 | guint channels;
79 | gint frame_width;
80 | gint frame_height;
81 |
82 | GstVideoInfo *info = gst_video_info_new ();
83 | GstBuffer *buffer = gst_buffer_new ();
84 | GstBuffer *buffer_out = gst_buffer_new ();
85 |
86 | fail_if (inframe == NULL);
87 | fail_if (outframe == NULL);
88 |
89 | gst_video_info_init (info);
90 | gst_video_info_set_format (info, format, width, height);
91 |
92 | fail_if (info == NULL);
93 |
94 | /* Allocate an output buffer for the pre-processed data */
95 | gst_allocation_params_init (¶ms);
96 | buffer =
97 | gst_buffer_new_allocate (NULL, buffer_size * sizeof (guchar), ¶ms);
98 | buffer_out =
99 | gst_buffer_new_allocate (NULL, buffer_size * sizeof (float), ¶ms);
100 |
101 | fail_if (buffer == NULL);
102 | fail_if (buffer_out == NULL);
103 |
104 | flags = (GstMapFlags) (GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF);
105 |
106 | ret = gst_video_frame_map (inframe, info, buffer, flags);
107 |
108 | fail_if (ret == FALSE);
109 |
110 | ret = gst_video_frame_map (outframe, info, buffer_out, flags);
111 |
112 | fail_if (ret == FALSE);
113 |
114 | channels = GST_VIDEO_FRAME_COMP_PSTRIDE (inframe, 0);
115 | pixel_stride = GST_VIDEO_FRAME_COMP_STRIDE (inframe, 0) / channels;
116 | frame_width = GST_VIDEO_FRAME_WIDTH (inframe);
117 | frame_height = GST_VIDEO_FRAME_HEIGHT (inframe);
118 |
119 | fail_if (frame_width == 0);
120 | fail_if (frame_height == 0);
121 |
122 | for (gint i = 0; i < frame_height; ++i) {
123 | for (gint j = 0; j < frame_width; ++j) {
124 | ((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels + 0 +
125 | offset] = value_red;
126 | ((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels + 1 +
127 | offset] = value_green;
128 | ((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels + 2 +
129 | offset] = value_blue;
130 | }
131 | }
132 | gst_video_info_free (info);
133 | gst_video_frame_unmap (inframe);
134 | gst_video_frame_unmap (outframe);
135 | }
136 |
--------------------------------------------------------------------------------
/tests/check/process/preprocess_functions_utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __PREPROCESS_FUNCTIONS_UTILS_H__
23 | #define __PREPROCESS_FUNCTIONS_UTILS_H__
24 |
25 | #include
26 |
27 | G_BEGIN_DECLS
28 |
29 | void gst_create_test_frames (GstVideoFrame * inframe,
30 | GstVideoFrame * outframe, guchar value_red, guchar value_green, guchar value_blue, gint buffer_size, gint width,
31 | gint height, gint offset, GstVideoFormat format);
32 |
33 | void gst_check_output_pixels (GstVideoFrame * outframe,
34 | gfloat expected_value_red, gfloat expected_value_green,
35 | gfloat expected_value_blue, gint first_index, gint last_index,
36 | gint model_channels);
37 |
38 | G_END_DECLS
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/tests/examples/classification/README.md:
--------------------------------------------------------------------------------
1 | # Classification Example
2 | This example receives a video file or camera stream to classify each frame into one of 1000 possible classes. For each classified frame the application captures the signal emitted by GstInference, forwarding the prediction to a placeholder for external logic. Simultaneously, the pipeline displays the captured frames with the associated label in a window.
3 |
4 | # Parameters
5 | * -m|--model
6 | Mandatory. Path to the InceptionV4 trained model
7 | * -f|--file
8 | Optional. Path to the video file to be used.
9 | If it is not set, a camera stream will be used.
10 | * -b|--backend
11 | Mandatory. Name of the backed to be used. See Supported Backends for a list of possible options.
12 | * -v
13 | Optional. Run verbosely.
14 | * -h|--help
15 | Displays usage and parameters description
16 |
17 | # Usage
18 | ```
19 | ./classification -m -f -b [-v]
20 | ```
21 |
22 | # More information
23 | Please check our [developers](https://developer.ridgerun.com/wiki/index.php?title=GstInference/Example_Applications/Classification) page for this example.
24 |
--------------------------------------------------------------------------------
/tests/examples/classification/customlogic.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "customlogic.h"
23 |
24 | #include
25 |
26 | void
27 | handle_prediction (unsigned char *image,
28 | int width,
29 | int height, unsigned int size, double *probabilities, int num_probabilities)
30 | {
31 | /* FILLME:
32 | * Put here your custom logic, you may use C++ here.
33 | */
34 |
35 | double max = 0;
36 | double imax = 0;
37 |
38 | for (int i = 0; i < num_probabilities; ++i) {
39 | double current = probabilities[i];
40 |
41 | if (current > max) {
42 | max = current;
43 | imax = i;
44 | }
45 | }
46 |
47 | std::cout << "Highest probability is label " << imax
48 | << ": (" << max << ")" << std::endl;
49 | }
50 |
--------------------------------------------------------------------------------
/tests/examples/classification/customlogic.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __CLASSIFICATION_CUSTOM_LOGIC__
23 | #define __CLASSIFICATION_CUSTOM_LOGIC__
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | void
30 | handle_prediction (unsigned char *image,
31 | int width,
32 | int height,
33 | unsigned int size,
34 | double *probabilities,
35 | int num_probabilities);
36 |
37 | #ifdef __cplusplus
38 | }
39 | #endif
40 |
41 | #endif //__CLASSIFICATION_CUSTOM_LOGIC__
42 |
--------------------------------------------------------------------------------
/tests/examples/classification/meson.build:
--------------------------------------------------------------------------------
1 | # Compile examples
2 | example_source = [
3 | 'customlogic.cc',
4 | 'gstclassification.c'
5 | ]
6 |
7 | executable('classification', example_source,
8 | include_directories: [configinc, inference_inc_dir],
9 | dependencies : [example_deps, gstinference_dep],
10 | install: false)
11 |
--------------------------------------------------------------------------------
/tests/examples/detection/README.md:
--------------------------------------------------------------------------------
1 | # Detection Example
2 | This example receives a video file or camera stream to detect objects in each buffer and detects objects of different classes, and their position and size within the frame. For each frame the application captures the signal emitted by GstInference, forwarding the prediction to a placeholder for external logic. Simultaneously, the pipeline displays the captured frames with every detected object marked with a label and a square.
3 |
4 | # Parameters
5 | * -m|--model
6 | Mandatory. Path to the InceptionV4 trained model
7 | * -f|--file
8 | Optional. Path to the video file to be used.
9 | If it is not set, a camera stream will be used.
10 | * -b|--backend
11 | Mandatory. Name of the backed to be used. See Supported Backends for a list of possible options.
12 | * -v
13 | Optional. Run verbosely.
14 | * -h|--help
15 | Displays usage and parameters description
16 |
17 | # Usage
18 | ```
19 | ./detection -m -f -b [-v]
20 | ```
21 | # More information
22 | Please check our [developers](https://developer.ridgerun.com/wiki/index.php?title=GstInference/Example_Applications/Detection) page for this example.
23 |
--------------------------------------------------------------------------------
/tests/examples/detection/customlogic.cc:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #include "customlogic.h"
23 |
24 | #include
25 |
26 | void
27 | handle_prediction (unsigned char *image,
28 | int width, int height, unsigned int size, PredictionBox * boxes,
29 | int num_boxes)
30 | {
31 | /* FILLME:
32 | * Put here your custom logic, you may use C++ here.
33 | */
34 |
35 | for (int i = 0; i < num_boxes; ++i) {
36 | std::cout << "BBox: [class:" << boxes->category <<
37 | ", x:" << boxes->x << ", y:" << boxes->y <<
38 | ", width:" << boxes->width << ", height:" << boxes->height <<
39 | ", prob:" << boxes->probability << "]" << std::endl;
40 | boxes++;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/examples/detection/customlogic.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GStreamer
3 | * Copyright (C) 2018-2020 RidgeRun
4 | *
5 | * This library is free software; you can redistribute it and/or
6 | * modify it under the terms of the GNU Library General Public
7 | * License as published by the Free Software Foundation; either
8 | * version 2 of the License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | * Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this library; if not, write to the
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 | * Boston, MA 02111-1307, USA.
19 | *
20 | */
21 |
22 | #ifndef __DETECTION_CUSTOM_LOGIC__
23 | #define __DETECTION_CUSTOM_LOGIC__
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | typedef struct _PredictionBox PredictionBox;
30 | struct _PredictionBox {
31 | int category;
32 | double probability;
33 | int x;
34 | int y;
35 | int width;
36 | int height;
37 | };
38 |
39 | void
40 | handle_prediction (unsigned char *image,
41 | int width,
42 | int height,
43 | unsigned int size,
44 | PredictionBox *boxes,
45 | int num_boxes);
46 |
47 | #ifdef __cplusplus
48 | }
49 | #endif
50 |
51 | #endif //__DETECTION_CUSTOM_LOGIC__
52 |
--------------------------------------------------------------------------------
/tests/examples/detection/meson.build:
--------------------------------------------------------------------------------
1 | # Compile examples
2 | example_source = [
3 | 'customlogic.cc',
4 | 'gstdetection.c'
5 | ]
6 |
7 | executable('detection', example_source,
8 | include_directories: [configinc, inference_inc_dir],
9 | dependencies : [example_deps, gstinference_dep],
10 | install: false)
11 |
--------------------------------------------------------------------------------
/tests/examples/meson.build:
--------------------------------------------------------------------------------
1 | subdir('classification')
2 | subdir('detection')
3 |
--------------------------------------------------------------------------------
/tests/meson.build:
--------------------------------------------------------------------------------
1 | if not get_option('enable-tests').disabled() and gst_check_dep.found()
2 | subdir('check')
3 | endif
4 |
5 | if not get_option('enable-examples').disabled()
6 | subdir('examples')
7 | endif
8 |
--------------------------------------------------------------------------------