hailo-ai / hailo-rpi5-examples

MIT License
268 stars 38 forks source link

detection.py doesn't handle filesrc with spaces in the path. #29

Closed jdimpson closed 1 week ago

jdimpson commented 1 month ago

When I run: python ./basic_pipelines/detection.py --input '/media/video/movies/Godzilla Minus One (2023)/Sample 2.mp4'

I get the following output (I've truncated length of the first and third lines of output, but not, I believe, the important parts):

hailomuxer name=hmux filesrc location=/media/video/movies/Godzilla Minus One (2023)/Sample 2.mp4 name=src_0 ! queue name=queue_dec264 max-size-buffers=3 max-size-bytes=0 max-size-time=0 [...] 
gst_parse_error: no element "Minus" (1)
hailomuxer name=hmux filesrc location=/media/video/movies/Godzilla Minus One (2023)/Sample 2.mp4 name=src_0 ! queue name=queue_dec264 max-size-buffers=3 max-size-bytes=0 max-size-time=0 [...]

It seems the spaces in the file name are not being passed to the call to gstreamer correctly.

When I run the modified command: python ./basic_pipelines/detection.py --input '/media/video/movies/Godzilla\ Minus\ One\ \(2023\)/Sample\ 2.mp4'

the example works as expected (except that sometimes Godzilla is detected as a horse and sometimes as a bird, but I'll open a a different issue for that[1]). The outlook looks like this (again, truncated):

hailomuxer name=hmux filesrc location=/media/video/movies/Godzilla\ Minus\ One\ \(2023\)/Sample\ 2.mp4 name=src_0 ! queue name=queue_dec264 max-size-buffers=3 max-size-bytes=0 max-size-time=0
Frame count: 1

Frame count: 2
[...]

I think detection.py needs to use Python's pathlib when handling filesrc inputs, or at least needs to implement some kind of escape code to handle spaces and perhaps other odd characters in file names.

Are you open to merge requests?

[1] For the record, this is a joke. Obviously I'd have to open a detection-related issue on the appropriate YOLO* data set repositories!

jdimpson commented 1 month ago

OK the simplest and I think best fix was to change line 163 of detection.py from:

f"filesrc location={self.video_source} name=src_0 ! "

to

f"filesrc location=\"{self.video_source}\" name=src_0 ! "

jdimpson commented 1 month ago

Similar fixes in instance_segmentation.py and pose_estimation.py are needed where filesrc is being configured.