YACWC
This commit is contained in:
235
deepstream_obj_det.py
Executable file → Normal file
235
deepstream_obj_det.py
Executable file → Normal file
@@ -16,19 +16,14 @@ import argparse
|
|||||||
pfm = LogColorize.watch_and_fix_permissions
|
pfm = LogColorize.watch_and_fix_permissions
|
||||||
|
|
||||||
logger = get_logger(__name__,'/var/log/ml_vision_logs/00_watch_and_fix_permissions', stdout=True, systemd=False)
|
logger = get_logger(__name__,'/var/log/ml_vision_logs/00_watch_and_fix_permissions', stdout=True, systemd=False)
|
||||||
Gst.debug_set_default_threshold(Gst.DebugLevel.INFO)
|
|
||||||
os.environ.pop("DISPLAY",':0')
|
|
||||||
target_width_detect = 1280
|
|
||||||
target_height_detect = 720
|
|
||||||
|
|
||||||
|
|
||||||
target_width_embed = 512
|
target_width = 1280
|
||||||
target_height_embed = 512
|
target_height = 720
|
||||||
|
os.environ.pop("DISPLAY",None)
|
||||||
MUXER_BATCH_TIMEOUT_USEC = 1000000
|
MUXER_BATCH_TIMEOUT_USEC = 1000000
|
||||||
def embed_results_probe(pad,info,u_data, list_add, frame_num = 0):
|
def embedder_results_probe(pad,info,u_data, list_add, frame_num = 0):
|
||||||
gst_buffer = info.get_buffer()
|
gst_buffer = info.get_buffer()
|
||||||
print("HEY I AM PROBING EMBEDDINGS")
|
|
||||||
if not gst_buffer:
|
if not gst_buffer:
|
||||||
print("Unable to get GstBuffer ")
|
print("Unable to get GstBuffer ")
|
||||||
return
|
return
|
||||||
@@ -109,7 +104,7 @@ def detector_results_probe(pad,info,u_data, list_add, frame_num = 0):
|
|||||||
frame_number=0
|
frame_number=0
|
||||||
num_rects=0
|
num_rects=0
|
||||||
got_fps = False
|
got_fps = False
|
||||||
print("HEY I AM PROBING DETECTIONS")
|
|
||||||
gst_buffer = info.get_buffer()
|
gst_buffer = info.get_buffer()
|
||||||
if not gst_buffer:
|
if not gst_buffer:
|
||||||
print("Unable to get GstBuffer ")
|
print("Unable to get GstBuffer ")
|
||||||
@@ -183,6 +178,7 @@ def detector_results_probe(pad,info,u_data, list_add, frame_num = 0):
|
|||||||
|
|
||||||
|
|
||||||
def cb_newpad(decodebin, decoder_src_pad,data):
|
def cb_newpad(decodebin, decoder_src_pad,data):
|
||||||
|
print("In cb_newpad\n")
|
||||||
caps=decoder_src_pad.get_current_caps()
|
caps=decoder_src_pad.get_current_caps()
|
||||||
if not caps:
|
if not caps:
|
||||||
caps = decoder_src_pad.query_caps()
|
caps = decoder_src_pad.query_caps()
|
||||||
@@ -219,22 +215,34 @@ def decodebin_child_added(child_proxy,Object,name,user_data):
|
|||||||
|
|
||||||
|
|
||||||
def create_source_bin(uri):
|
def create_source_bin(uri):
|
||||||
|
print("Creating source bin")
|
||||||
|
|
||||||
|
# Create a source GstBin to abstract this bin's content from the rest of the
|
||||||
|
# pipeline
|
||||||
bin_name="source-bin-any-format"
|
bin_name="source-bin-any-format"
|
||||||
|
print(bin_name)
|
||||||
nbin=Gst.Bin.new(bin_name)
|
nbin=Gst.Bin.new(bin_name)
|
||||||
if not nbin:
|
if not nbin:
|
||||||
sys.stderr.write(" Unable to create source bin \n")
|
sys.stderr.write(" Unable to create source bin \n")
|
||||||
|
|
||||||
|
# Source element for reading from the uri.
|
||||||
|
# We will use decodebin and let it figure out the container format of the
|
||||||
|
# stream and the codec and plug the appropriate demux and decode plugins.
|
||||||
uri_decode_bin=Gst.ElementFactory.make("uridecodebin", "uri-decode-bin")
|
uri_decode_bin=Gst.ElementFactory.make("uridecodebin", "uri-decode-bin")
|
||||||
if not uri_decode_bin:
|
if not uri_decode_bin:
|
||||||
sys.stderr.write(" Unable to create uri decode bin \n")
|
sys.stderr.write(" Unable to create uri decode bin \n")
|
||||||
|
# We set the input uri to the source element
|
||||||
uri_decode_bin.set_property("uri",uri)
|
uri_decode_bin.set_property("uri",uri)
|
||||||
|
# Connect to the "pad-added" signal of the decodebin which generates a
|
||||||
|
# callback once a new pad for raw data has beed created by the decodebin
|
||||||
uri_decode_bin.connect("pad-added",cb_newpad,nbin)
|
uri_decode_bin.connect("pad-added",cb_newpad,nbin)
|
||||||
uri_decode_bin.connect("child-added",decodebin_child_added,nbin)
|
uri_decode_bin.connect("child-added",decodebin_child_added,nbin)
|
||||||
|
|
||||||
|
# We need to create a ghost pad for the source bin which will act as a proxy
|
||||||
|
# for the video decoder src pad. The ghost pad will not have a target right
|
||||||
|
# now. Once the decode bin creates the video decoder and generates the
|
||||||
|
# cb_newpad callback, we will set the ghost pad target to the video decoder
|
||||||
|
# src pad.
|
||||||
Gst.Bin.add(nbin,uri_decode_bin)
|
Gst.Bin.add(nbin,uri_decode_bin)
|
||||||
bin_pad=nbin.add_pad(Gst.GhostPad.new_no_target("src",Gst.PadDirection.SRC))
|
bin_pad=nbin.add_pad(Gst.GhostPad.new_no_target("src",Gst.PadDirection.SRC))
|
||||||
if not bin_pad:
|
if not bin_pad:
|
||||||
@@ -253,116 +261,86 @@ def run_inference(file_path):
|
|||||||
|
|
||||||
pipeline = Gst.Pipeline()
|
pipeline = Gst.Pipeline()
|
||||||
|
|
||||||
source_file=create_source_bin(file_path)
|
streammux = Gst.ElementFactory.make("nvstreammux", "Stream-muxer")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tee=Gst.ElementFactory.make("tee", "nvsink-tee")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# DETECT
|
|
||||||
queue_detect=Gst.ElementFactory.make("queue", "nvtee-detect")
|
|
||||||
|
|
||||||
|
|
||||||
streammux_detect = Gst.ElementFactory.make("nvstreammux", "Stream-muxer-detector")
|
|
||||||
streammux_detect.set_property('width', target_width_detect)
|
|
||||||
streammux_detect.set_property('height', target_height_detect)
|
|
||||||
streammux_detect.set_property('batched-push-timeout', MUXER_BATCH_TIMEOUT_USEC)
|
|
||||||
streammux_detect.set_property('enable-padding',1)
|
|
||||||
streammux_detect.set_property('batch-size', 4)
|
|
||||||
|
|
||||||
nugget_detector = Gst.ElementFactory.make("nvinfer", "primary-inference")
|
nugget_detector = Gst.ElementFactory.make("nvinfer", "primary-inference")
|
||||||
|
nugget_embedder = Gst.ElementFactory.make("nvinfer", "secondary-inference")
|
||||||
|
|
||||||
|
streammux.set_property('width', target_width)
|
||||||
|
streammux.set_property('height', target_height)
|
||||||
|
streammux.set_property('batched-push-timeout', MUXER_BATCH_TIMEOUT_USEC)
|
||||||
|
streammux.set_property('enable-padding',1)
|
||||||
|
streammux.set_property('batch-size', 4)
|
||||||
|
|
||||||
|
|
||||||
|
# nugget_detector.set_property('config-file-path', "/home/thebears/DeepStream-Yolo/detector.txt")
|
||||||
nugget_detector.set_property('config-file-path', "/home/thebears/DeepStream-Yolo/config_infer_primary_yoloV7.txt")
|
nugget_detector.set_property('config-file-path', "/home/thebears/DeepStream-Yolo/config_infer_primary_yoloV7.txt")
|
||||||
|
nugget_embedder.set_property('config-file-path', "/home/thebears/DeepStream-Yolo/embedder.txt")
|
||||||
|
|
||||||
fakesink_detect = Gst.ElementFactory.make("fakesink","fakesink")
|
fakesink1 = Gst.ElementFactory.make("fakesink","fakesink")
|
||||||
fakesink_detect.set_property('enable-last-sample', 0)
|
fakesink1.set_property('enable-last-sample', 0)
|
||||||
fakesink_detect.set_property('sync', 0)
|
fakesink1.set_property('sync', 0)
|
||||||
|
pipeline.add(fakesink1)
|
||||||
|
|
||||||
|
fakesink2 = Gst.ElementFactory.make("fakesink","fakesink2")
|
||||||
|
fakesink2.set_property('enable-last-sample', 0)
|
||||||
|
fakesink2.set_property('sync', 0)
|
||||||
|
pipeline.add(fakesink2)
|
||||||
|
|
||||||
|
pipeline.add(streammux)
|
||||||
|
pipeline.add(nugget_detector)
|
||||||
|
pipeline.add(nugget_embedder)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# EMBED
|
# uri_name = 'file:///home/thebears/railing.mp4'
|
||||||
|
# uri_name = 'file:///home/thebears/railing_00_20250213094806.mp4'
|
||||||
queue_embed=Gst.ElementFactory.make("queue", "nvtee-que-embed")
|
source_file=create_source_bin(file_path)
|
||||||
|
|
||||||
streammux_embed = Gst.ElementFactory.make("nvstreammux", "Stream-muxer-embed")
|
|
||||||
streammux_embed.set_property('width', target_width_embed)
|
|
||||||
streammux_embed.set_property('height', target_height_embed)
|
|
||||||
streammux_embed.set_property('batched-push-timeout', MUXER_BATCH_TIMEOUT_USEC)
|
|
||||||
streammux_embed.set_property('enable-padding',1)
|
|
||||||
streammux_embed.set_property('batch-size', 4)
|
|
||||||
|
|
||||||
|
|
||||||
nugget_embed = Gst.ElementFactory.make("nvinfer", "primary-inference")
|
|
||||||
nugget_embed.set_property('config-file-path', "/home/thebears/DeepStream-Yolo/embedder.txt")
|
|
||||||
# nugget_embed.set_property('config-file-path', "/home/thebears/DeepStream-Yolo/config_infer_primary_yoloV7.txt")
|
|
||||||
|
|
||||||
fakesink_embed = Gst.ElementFactory.make("fakesink","fakesink2")
|
|
||||||
fakesink_embed.set_property('enable-last-sample', 0)
|
|
||||||
fakesink_embed.set_property('sync', 0)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# LINKING
|
|
||||||
|
|
||||||
# Ensure NVMM caps with a capsfilter
|
|
||||||
# capsfilter = Gst.ElementFactory.make("capsfilter", "capsfilter")
|
|
||||||
# capsfilter.set_property("caps", Gst.Caps.from_string("video/x-raw(memory:NVMM), format=NV12"))
|
|
||||||
# pipeline.add(capsfilter)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pipeline.add(source_file)
|
pipeline.add(source_file)
|
||||||
|
|
||||||
|
stream_pad = streammux.request_pad_simple("sink_0")
|
||||||
|
source_pad = source_file.get_static_pad("src")
|
||||||
|
source_pad.link(stream_pad)
|
||||||
|
|
||||||
|
tee=Gst.ElementFactory.make("tee", "nvsink-tee")
|
||||||
pipeline.add(tee)
|
pipeline.add(tee)
|
||||||
|
|
||||||
nvvidconv = Gst.ElementFactory.make("nvvidconv", "nvvidconv")
|
queue1=Gst.ElementFactory.make("queue", "nvtee-que1")
|
||||||
pipeline.add(nvvidconv)
|
queue2=Gst.ElementFactory.make("queue", "nvtee-que2")
|
||||||
|
pipeline.add(queue1)
|
||||||
|
pipeline.add(queue2)
|
||||||
|
|
||||||
source_file.link(nvvidconv)
|
streammux.link(tee)
|
||||||
# nvvidconv.link(capsfilter)
|
|
||||||
# capsfilter.link(tee)
|
|
||||||
nvvidconv.link(tee)
|
|
||||||
|
|
||||||
|
|
||||||
|
tee.link(queue1)
|
||||||
if True:
|
tee.link(queue2)
|
||||||
pipeline.add(queue_detect)
|
|
||||||
pipeline.add(streammux_detect)
|
|
||||||
pipeline.add(nugget_detector)
|
|
||||||
pipeline.add(fakesink_detect)
|
|
||||||
|
|
||||||
|
|
||||||
|
# preprocess_detector = Gst.ElementFactory.make("nvdspreprocess","preprocess_detector")
|
||||||
tee.get_request_pad("src_%u").link(queue_detect.get_static_pad("sink"))
|
# preprocess_detector.set_property('config-file', "/home/thebears/DeepStream-Yolo/detector_preprocess.txt")
|
||||||
queue_detect.get_static_pad("src").link(streammux_detect.get_request_pad("sink_0"))
|
# preprocess_detector.set_property('config-file',pre_file)
|
||||||
streammux_detect.link(nugget_detector)
|
|
||||||
nugget_detector.link(fakesink_detect)
|
|
||||||
|
|
||||||
|
|
||||||
|
# preprocess_embedder = Gst.ElementFactory.make("nvdspreprocess","preprocess_embedder")
|
||||||
|
# preprocess_embedder.set_property('config-file', "/home/thebears/DeepStream-Yolo/embedder_preprocess.txt")
|
||||||
|
# preprocess_embedder.set_property('config-file',pre_file)
|
||||||
|
|
||||||
|
# pipeline.add(preprocess_detector)
|
||||||
|
# pipeline.add(preprocess_embedder)
|
||||||
|
|
||||||
|
# queue1.link(preprocess_detector)
|
||||||
|
# preprocess_detector.link(nugget_detector)
|
||||||
|
|
||||||
|
# queue2.link(preprocess_embedder)
|
||||||
|
# preprocess_embedder.link(nugget_embedder)
|
||||||
|
|
||||||
|
|
||||||
if False:
|
queue1.link(nugget_detector)
|
||||||
pipeline.add(queue_embed)
|
queue2.link(nugget_embedder)
|
||||||
pipeline.add(streammux_embed)
|
|
||||||
pipeline.add(nugget_embed)
|
|
||||||
pipeline.add(fakesink_embed)
|
|
||||||
|
|
||||||
tee.get_request_pad("src_%u").link(queue_embed.get_static_pad("sink"))
|
|
||||||
queue_embed.get_static_pad("src").link(streammux_embed.get_request_pad("sink_0"))
|
|
||||||
streammux_embed.link(nugget_embed)
|
|
||||||
nugget_embed.link(fakesink_embed)
|
|
||||||
|
|
||||||
print_pipeline_structure(pipeline)
|
|
||||||
cmd = f'/usr/bin/ffprobe -v error -select_streams v:0 -count_packets -show_entries stream=nb_read_packets -of csv=p=0 {file_path}'#/srv/ftp/railing/2025/02/28/railing_00_20250228115800.mp4
|
cmd = f'/usr/bin/ffprobe -v error -select_streams v:0 -count_packets -show_entries stream=nb_read_packets -of csv=p=0 {file_path}'#/srv/ftp/railing/2025/02/28/railing_00_20250228115800.mp4
|
||||||
try:
|
try:
|
||||||
frames = int(os.popen(cmd).read().strip())
|
frames = int(os.popen(cmd).read().strip())
|
||||||
@@ -371,15 +349,12 @@ def run_inference(file_path):
|
|||||||
|
|
||||||
logger.info(f"TOTAL_FRAMES: {frames}")
|
logger.info(f"TOTAL_FRAMES: {frames}")
|
||||||
|
|
||||||
embed_list = list()
|
embedder_list = list()
|
||||||
|
|
||||||
Gst.debug_bin_to_dot_file(pipeline, Gst.DebugGraphDetails.ALL, "pipeline_structure")
|
|
||||||
embed_results = partial(embed_results_probe, list_add=embed_list, frame_num = frames)
|
|
||||||
nugget_embed.get_static_pad("src").add_probe(Gst.PadProbeType.BUFFER, embed_results, 0)
|
|
||||||
|
|
||||||
|
|
||||||
|
embedder_results = partial(embedder_results_probe, list_add=embedder_list, frame_num = frames)
|
||||||
|
nugget_embedder.get_static_pad("src").add_probe(Gst.PadProbeType.BUFFER, embedder_results, 0)
|
||||||
|
|
||||||
Gst.debug_bin_to_dot_file(pipeline, Gst.DebugGraphDetails.ALL, "/home/thebears/local/source/pipeline_structure")
|
|
||||||
|
|
||||||
detector_list = list()
|
detector_list = list()
|
||||||
|
|
||||||
@@ -388,7 +363,7 @@ def run_inference(file_path):
|
|||||||
nugget_detector.get_static_pad("src").add_probe(Gst.PadProbeType.BUFFER, detector_results, 0)
|
nugget_detector.get_static_pad("src").add_probe(Gst.PadProbeType.BUFFER, detector_results, 0)
|
||||||
|
|
||||||
|
|
||||||
print("AFTER SETTING STATIC PADS")
|
|
||||||
def get_pipeline_string(pipeline):
|
def get_pipeline_string(pipeline):
|
||||||
if not isinstance(pipeline, Gst.Pipeline):
|
if not isinstance(pipeline, Gst.Pipeline):
|
||||||
return None
|
return None
|
||||||
@@ -403,7 +378,9 @@ def run_inference(file_path):
|
|||||||
|
|
||||||
return " ! ".join(elements)
|
return " ! ".join(elements)
|
||||||
|
|
||||||
Gst.debug_bin_to_dot_file(pipeline, Gst.DebugGraphDetails.ALL, "pipeline_structure")
|
nugget_detector.link(fakesink1)
|
||||||
|
nugget_embedder.link(fakesink2)
|
||||||
|
print(get_pipeline_string(pipeline))
|
||||||
|
|
||||||
|
|
||||||
# create an event loop and feed gstreamer bus mesages to it
|
# create an event loop and feed gstreamer bus mesages to it
|
||||||
@@ -421,45 +398,7 @@ def run_inference(file_path):
|
|||||||
pass
|
pass
|
||||||
# cleanup
|
# cleanup
|
||||||
pipeline.set_state(Gst.State.NULL)
|
pipeline.set_state(Gst.State.NULL)
|
||||||
return detector_list, embed_list
|
return detector_list, embedder_list
|
||||||
|
|
||||||
def print_pipeline_structure(pipeline):
|
|
||||||
"""
|
|
||||||
Recursively prints elements in the pipeline and their properties.
|
|
||||||
"""
|
|
||||||
if not isinstance(pipeline, Gst.Pipeline):
|
|
||||||
print("Not a valid GStreamer pipeline.")
|
|
||||||
return
|
|
||||||
|
|
||||||
def _print_element_properties(element, indent=0):
|
|
||||||
spaces = " " * indent
|
|
||||||
print(spaces + f"Element: {element.get_name()} (Type: {element.get_factory().get_name()})")
|
|
||||||
|
|
||||||
# Print its properties
|
|
||||||
for prop in element.list_properties():
|
|
||||||
try:
|
|
||||||
val = element.get_property(prop.name)
|
|
||||||
if val != prop.default_value: # Display only non-default properties
|
|
||||||
print(spaces + f" - {prop.name}: {val}")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _print_pipeline_structure(element, indent=0):
|
|
||||||
spaces = " " * indent
|
|
||||||
children = element.children if hasattr(element, 'children') else []
|
|
||||||
|
|
||||||
if len(children) > 0:
|
|
||||||
print(spaces + f"[{element.get_name()}]")
|
|
||||||
for child in children:
|
|
||||||
_print_pipeline_structure(child, indent + 2)
|
|
||||||
else:
|
|
||||||
_print_element_properties(element, indent)
|
|
||||||
|
|
||||||
print("\nPipeline Structure:")
|
|
||||||
print("===================")
|
|
||||||
_print_pipeline_structure(pipeline)
|
|
||||||
print("===================\n")
|
|
||||||
|
|
||||||
|
|
||||||
def get_detailed_pipeline_string(pipeline):
|
def get_detailed_pipeline_string(pipeline):
|
||||||
"""Generate a more detailed pipeline string with properties"""
|
"""Generate a more detailed pipeline string with properties"""
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import argparse
|
|||||||
pfm = LogColorize.watch_and_fix_permissions
|
pfm = LogColorize.watch_and_fix_permissions
|
||||||
|
|
||||||
logger = get_logger(__name__,'/var/log/ml_vision_logs/00_watch_and_fix_permissions', stdout=True, systemd=False)
|
logger = get_logger(__name__,'/var/log/ml_vision_logs/00_watch_and_fix_permissions', stdout=True, systemd=False)
|
||||||
Gst.debug_set_default_threshold(Gst.DebugLevel.INFO)
|
Gst.debug_set_default_threshold(Gst.DebugLevel.ERROR)
|
||||||
os.environ.pop("DISPLAY",':0')
|
os.environ.pop("DISPLAY",':0')
|
||||||
target_width_detect = 1280
|
target_width_detect = 1280
|
||||||
target_height_detect = 720
|
target_height_detect = 720
|
||||||
@@ -26,6 +26,99 @@ target_width_embed = 512
|
|||||||
target_height_embed = 512
|
target_height_embed = 512
|
||||||
|
|
||||||
MUXER_BATCH_TIMEOUT_USEC = 1000000
|
MUXER_BATCH_TIMEOUT_USEC = 1000000
|
||||||
|
|
||||||
|
def print_pipeline_structure(pipeline):
|
||||||
|
"""
|
||||||
|
Recursively prints elements in the pipeline and their properties.
|
||||||
|
"""
|
||||||
|
if not isinstance(pipeline, Gst.Pipeline):
|
||||||
|
print("Not a valid GStreamer pipeline.")
|
||||||
|
return
|
||||||
|
|
||||||
|
def _print_element_properties(element, indent=0):
|
||||||
|
spaces = " " * indent
|
||||||
|
print(spaces + f"Element: {element.get_name()} (Type: {element.get_factory().get_name()})")
|
||||||
|
|
||||||
|
# Print its properties
|
||||||
|
for prop in element.list_properties():
|
||||||
|
try:
|
||||||
|
val = element.get_property(prop.name)
|
||||||
|
if val != prop.default_value: # Display only non-default properties
|
||||||
|
print(spaces + f" - {prop.name}: {val}")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _print_pipeline_structure(element, indent=0):
|
||||||
|
spaces = " " * indent
|
||||||
|
children = element.children if hasattr(element, 'children') else []
|
||||||
|
|
||||||
|
if len(children) > 0:
|
||||||
|
print(spaces + f"[{element.get_name()}]")
|
||||||
|
for child in children:
|
||||||
|
_print_pipeline_structure(child, indent + 2)
|
||||||
|
else:
|
||||||
|
_print_element_properties(element, indent)
|
||||||
|
|
||||||
|
print("\nPipeline Structure:")
|
||||||
|
print("===================")
|
||||||
|
_print_pipeline_structure(pipeline)
|
||||||
|
print("===================\n")
|
||||||
|
|
||||||
|
|
||||||
|
def get_detailed_pipeline_string(pipeline):
|
||||||
|
"""Generate a more detailed pipeline string with properties"""
|
||||||
|
if not isinstance(pipeline, Gst.Pipeline):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_element_string(element):
|
||||||
|
# Get element factory name
|
||||||
|
factory = element.get_factory()
|
||||||
|
if factory:
|
||||||
|
element_str = factory.get_name()
|
||||||
|
else:
|
||||||
|
element_str = element.get_name()
|
||||||
|
|
||||||
|
# Add properties
|
||||||
|
props = []
|
||||||
|
for prop in element.list_properties():
|
||||||
|
# Skip some properties that are typically not set in command line
|
||||||
|
if prop.name in ('name', 'parent'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
val = element.get_property(prop.name)
|
||||||
|
if val is not None and val != prop.default_value:
|
||||||
|
# Format value appropriately based on type
|
||||||
|
if isinstance(val, str):
|
||||||
|
props.append(f"{prop.name}=\"{val}\"")
|
||||||
|
elif isinstance(val, bool):
|
||||||
|
props.append(f"{prop.name}={str(val).lower()}")
|
||||||
|
else:
|
||||||
|
props.append(f"{prop.name}={val}")
|
||||||
|
except:
|
||||||
|
# Skip properties that can't be read
|
||||||
|
pass
|
||||||
|
|
||||||
|
if props:
|
||||||
|
element_str += " " + " ".join(props)
|
||||||
|
|
||||||
|
return element_str
|
||||||
|
|
||||||
|
result = []
|
||||||
|
|
||||||
|
# Simple approach - just gets top-level elements
|
||||||
|
iterator = pipeline.iterate_elements()
|
||||||
|
while True:
|
||||||
|
ret, element = iterator.next()
|
||||||
|
if ret != Gst.IteratorResult.OK:
|
||||||
|
break
|
||||||
|
result.append(get_element_string(element))
|
||||||
|
|
||||||
|
return " ! ".join(result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def embed_results_probe(pad,info,u_data, list_add, frame_num = 0):
|
def embed_results_probe(pad,info,u_data, list_add, frame_num = 0):
|
||||||
gst_buffer = info.get_buffer()
|
gst_buffer = info.get_buffer()
|
||||||
print("HEY I AM PROBING EMBEDDINGS")
|
print("HEY I AM PROBING EMBEDDINGS")
|
||||||
@@ -243,7 +336,9 @@ def create_source_bin(uri):
|
|||||||
return nbin
|
return nbin
|
||||||
|
|
||||||
|
|
||||||
def run_inference(file_path):
|
#def run_inference(file_path):
|
||||||
|
if True:
|
||||||
|
file_path = '/home/thebears/local/source/short.mp4'
|
||||||
os.environ.pop("DISPLAY",None)
|
os.environ.pop("DISPLAY",None)
|
||||||
if not file_path.startswith('file://'):
|
if not file_path.startswith('file://'):
|
||||||
file_path = 'file://'+file_path
|
file_path = 'file://'+file_path
|
||||||
@@ -421,97 +516,7 @@ def run_inference(file_path):
|
|||||||
pass
|
pass
|
||||||
# cleanup
|
# cleanup
|
||||||
pipeline.set_state(Gst.State.NULL)
|
pipeline.set_state(Gst.State.NULL)
|
||||||
return detector_list, embed_list
|
# return detector_list, embed_list
|
||||||
|
|
||||||
def print_pipeline_structure(pipeline):
|
|
||||||
"""
|
|
||||||
Recursively prints elements in the pipeline and their properties.
|
|
||||||
"""
|
|
||||||
if not isinstance(pipeline, Gst.Pipeline):
|
|
||||||
print("Not a valid GStreamer pipeline.")
|
|
||||||
return
|
|
||||||
|
|
||||||
def _print_element_properties(element, indent=0):
|
|
||||||
spaces = " " * indent
|
|
||||||
print(spaces + f"Element: {element.get_name()} (Type: {element.get_factory().get_name()})")
|
|
||||||
|
|
||||||
# Print its properties
|
|
||||||
for prop in element.list_properties():
|
|
||||||
try:
|
|
||||||
val = element.get_property(prop.name)
|
|
||||||
if val != prop.default_value: # Display only non-default properties
|
|
||||||
print(spaces + f" - {prop.name}: {val}")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _print_pipeline_structure(element, indent=0):
|
|
||||||
spaces = " " * indent
|
|
||||||
children = element.children if hasattr(element, 'children') else []
|
|
||||||
|
|
||||||
if len(children) > 0:
|
|
||||||
print(spaces + f"[{element.get_name()}]")
|
|
||||||
for child in children:
|
|
||||||
_print_pipeline_structure(child, indent + 2)
|
|
||||||
else:
|
|
||||||
_print_element_properties(element, indent)
|
|
||||||
|
|
||||||
print("\nPipeline Structure:")
|
|
||||||
print("===================")
|
|
||||||
_print_pipeline_structure(pipeline)
|
|
||||||
print("===================\n")
|
|
||||||
|
|
||||||
|
|
||||||
def get_detailed_pipeline_string(pipeline):
|
|
||||||
"""Generate a more detailed pipeline string with properties"""
|
|
||||||
if not isinstance(pipeline, Gst.Pipeline):
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_element_string(element):
|
|
||||||
# Get element factory name
|
|
||||||
factory = element.get_factory()
|
|
||||||
if factory:
|
|
||||||
element_str = factory.get_name()
|
|
||||||
else:
|
|
||||||
element_str = element.get_name()
|
|
||||||
|
|
||||||
# Add properties
|
|
||||||
props = []
|
|
||||||
for prop in element.list_properties():
|
|
||||||
# Skip some properties that are typically not set in command line
|
|
||||||
if prop.name in ('name', 'parent'):
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
val = element.get_property(prop.name)
|
|
||||||
if val is not None and val != prop.default_value:
|
|
||||||
# Format value appropriately based on type
|
|
||||||
if isinstance(val, str):
|
|
||||||
props.append(f"{prop.name}=\"{val}\"")
|
|
||||||
elif isinstance(val, bool):
|
|
||||||
props.append(f"{prop.name}={str(val).lower()}")
|
|
||||||
else:
|
|
||||||
props.append(f"{prop.name}={val}")
|
|
||||||
except:
|
|
||||||
# Skip properties that can't be read
|
|
||||||
pass
|
|
||||||
|
|
||||||
if props:
|
|
||||||
element_str += " " + " ".join(props)
|
|
||||||
|
|
||||||
return element_str
|
|
||||||
|
|
||||||
result = []
|
|
||||||
|
|
||||||
# Simple approach - just gets top-level elements
|
|
||||||
iterator = pipeline.iterate_elements()
|
|
||||||
while True:
|
|
||||||
ret, element = iterator.next()
|
|
||||||
if ret != Gst.IteratorResult.OK:
|
|
||||||
break
|
|
||||||
result.append(get_element_string(element))
|
|
||||||
|
|
||||||
return " ! ".join(result)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user