Through this sample code, you can learn:
This sample shows how to set the adlink metadata inside the element. The target created pipeline command is:
$ gst-launch-1.0 videotestsrc ! video/x-raw, width=640, height=480 ! detection_sample ! admetadrawer ! videoconvert ! ximagesink
This command is used to display the simulated detection results and the element(this sample code), detection_sample, set the simulated detection data into admetadata.
This sample is constructed based on the python video filter and put the simulated detection results into admetadata. Here is the simulated function:
BOX_NUM = 5
DUMMY_BOXS = [[rand(), rand(), rand(), rand()] for i in range(BOX_NUM)]
def parse_inference_data_to_boxs(*data):
# Generate dummy box here, please implement your own parse algorithm with input data
boxs = []
for b in DUMMY_BOXS:
for j in range(len(b)):
b[j] += 0.01 if rint(0, 1) == 0 else -0.01
b[j] = max(0, b[j])
b[j] = min(1, b[j])
boxs.append((max(0, min(b[0], b[1])),
max(0, min(b[2], b[3])),
min(1, max(b[0], b[1])),
min(1, max(b[2], b[3]))))
return boxs
Parameter, data, is the raw data you might obtained in the stream. In this sample we just simply assume that you get the buffer already and without passing the data, only randomly generating the boxes. (If you want to retrieve the inferenced raw data, please reference to the Python Translator or contact us for advanced.)
After generated, the results will append as arr array:
for i, box in enumerate(self.boxes):
arr.append(admeta._DetectionBox(i, i, i, i,
box[0],
box[1],
box[2],
box[3],
rand()))
Then, the arr array will set into admetadata with buffer by wrapper function:
# Set data into admetadata
admeta.set_detection_box(buff, pad, arr)
Same with the last process with video-filter.py, required to install into the EVA package. Install process please refer to vido filter in Python.
After installing the Python plugin detection_sample.py file to the plugin folder, run the GStreamer tool to inspect it to see the metadata and the object information.
$ gst-inspect-1.0 detection_sample
and you will see all of the information listed:
Factory Details:
Rank none (0)
Long-name Metadata addition
Klass GstElement
Description Python based example for adding detection results
Author Lyan Hung <lyan.hung@adlinktech.com>, Dr. Paul Lin <paul.lin@adlinktech.com>
Plugin Details:
Name python
Description loader for plugins written in python
Filename /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstpython.so
Version 1.14.5
License LGPL
Source module gst-python
Binary package GStreamer Python
Origin URL http://gstreamer.freedesktop.org
// more information omitted
Then run the pipeline command for testing:
$ gst-launch-1.0 videotestsrc ! video/x-raw, width=640, height=480 ! detection_sample ! admetadrawer ! videoconvert ! ximagesink
and you will see the inference result displayed frame by frame in the window:
