GstInference/Metadatas/Signals: Difference between revisions

From RidgeRun Developer Wiki
No edit summary
Line 1: Line 1:
<noinclude>
<noinclude>
{{GstInference/Head|previous=Metadatas/GstInferenceMeta|next=Overlay Elements|keywords=GstInference Signals|title=Signals}}
{{GstInference/Head|previous=Metadatas/GstInferenceMeta|next=Overlay Elements|keywords=GstInference Signals|title=GstInference Signals}}
</noinclude>
</noinclude>


Line 13: Line 13:
Metadata from GstInference is available to be obtained through GSignals and therefore can be used in other programs or processes such as using Python or C++.
Metadata from GstInference is available to be obtained through GSignals and therefore can be used in other programs or processes such as using Python or C++.


=== Inference String Signal ===
== Available Signals ==
Signals are created and listed in ''gst-libs/gst/r2inference/gstvideoinference.c''
 
<html>
<style type="text/css">
.tg  {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
  font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-uqo3{background-color:#efefef;text-align:center;vertical-align:top}
.tg .tg-cmwg{background-color:#ffccc9;text-align:center;vertical-align:top}
.tg .tg-jghb{background-color:#8fe8b8;text-align:center;vertical-align:top}
.tg .tg-0lax{text-align:left;vertical-align:top}
</style>
<table class="tg">
<thead>
  <tr>
    <th class="tg-uqo3">Signal Name</th>
    <th class="tg-uqo3">To be used by</th>
    <th class="tg-uqo3">Details</th>
    <th class="tg-uqo3">Status</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td class="tg-0lax">new-prediction</td>
    <td class="tg-0lax">C/C++ </td>
    <td class="tg-0lax">Format can be casted to<br>struct that defines metadata<br>and dereference pointers.</td>
    <td class="tg-cmwg">Deprecated</td>
  </tr>
  <tr>
    <td class="tg-0lax">new-inference</td>
    <td class="tg-0lax">C/C++</td>
    <td class="tg-0lax"><span style="font-weight:400;font-style:normal">Format can be casted to</span><br><span style="font-weight:400;font-style:normal">struct that defines metadata</span><br><span style="font-weight:400;font-style:normal">and dereference pointers.</span></td>
    <td class="tg-jghb">Active</td>
  </tr>
  <tr>
    <td class="tg-0lax">new-inference-string</td>
    <td class="tg-0lax">Python, Javascript, Other<br></td>
    <td class="tg-0lax"><span style="font-weight:400;font-style:normal">String format </span>needs to be used<br>because pointer dereference<br>from other memory space is<br>not available.</td>
    <td class="tg-jghb">Active</td>
  </tr>
</tbody>
</table>
</html>
 
== Inference String Signal ==


The following code show a simple capture of the signal in GStreamer using Python. It installs the function handler to the signal called "new-inference-string" from GstInference element. The signal sends a string formatted as json which can be parsed in python using json.loads function.
The following code show a simple capture of the signal in GStreamer using Python. It installs the function handler to the signal called "new-inference-string" from GstInference element. The signal sends a string formatted as json which can be parsed in python using json.loads function.

Revision as of 22:44, 25 March 2021




Previous: Metadatas/GstInferenceMeta Index Next: Overlay Elements





Overview

Metadata from GstInference is available to be obtained through GSignals and therefore can be used in other programs or processes such as using Python or C++.

Available Signals

Signals are created and listed in gst-libs/gst/r2inference/gstvideoinference.c

Signal Name To be used by Details Status
new-prediction C/C++ Format can be casted to
struct that defines metadata
and dereference pointers.
Deprecated
new-inference C/C++ Format can be casted to
struct that defines metadata
and dereference pointers.
Active
new-inference-string Python, Javascript, Other
String format needs to be used
because pointer dereference
from other memory space is
not available.
Active

Inference String Signal

The following code show a simple capture of the signal in GStreamer using Python. It installs the function handler to the signal called "new-inference-string" from GstInference element. The signal sends a string formatted as json which can be parsed in python using json.loads function.

For details about what elements can be accessed in the serialized json string, check this section.

import gi
gi.require_version("Gst", "1.0")
gi.require_version("GstVideo", "1.0")
from gi.repository import Gst, GObject, GstVideo
import json

GObject.threads_init()
Gst.init(None)

def newPrediction(element, meta):
    # Parse data from string to json object
    data = json.loads(meta)
    print(data)

# Settings
video_dev = "/dev/video0"
arch = "mobilenetv2ssd"
backend = "coral"
model = "/home/coral/models/ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite"
input_layer = "" # Needed by other backends such as Tensorflow
output_layer = "" # Needed by other backends such as Tensorflow

# Pipeline
inf_pipe_str = "v4l2src device=%s ! videoscale ! videoconvert ! \
                video/x-raw,width=640,height=480,format=I420 ! \
                videoconvert ! inferencebin arch=%s backend=%s \
                model-location=%s input-layer=%s output-layer=%s \
                overlay=true name=net ! \
                videoconvert ! autovideosink name=videosink sync=false" % \
                (video_dev,arch,backend,model,input_layer,output_layer)

# Load pipeline from string
inference_pipe = Gst.parse_launch(inf_pipe_str)
# Start pipeline
inference_pipe.set_state(Gst.State.PLAYING)

if (not inference_pipe):
    print("Unable to create pipeline")
    exit(1)

# Search for arch element from inferencebin
net = inference_pipe.get_by_name("arch")

# Connect to inference string signal
net.connect("new-inference-string", newPrediction)

# Launch loop
loop = GObject.MainLoop() 
loop.run()


Previous: Metadatas/GstInferenceMeta Index Next: Overlay Elements