From 82851b0308098a6b785fdfa8d1a84eebcd2c70d5 Mon Sep 17 00:00:00 2001 From: Isaac Hermida Date: Wed, 2 Oct 2024 12:20:10 +0200 Subject: [PATCH] eiq-examples: improvements * do not run the demos in background, if not they can not be ctrl+c. * fix service dependencies: required camera and weston. * patch the examples to: ** set camera resolution to 1280x720 ** set default format to ov5640 camera (YUYV) ** detect the "x" event when the demo application is running in windowed mode (not fullscreen). Signed-off-by: Isaac Hermida --- .../eiq-examples/eiq-examples_git.bbappend | 3 +- ...ture-x-windows-and-increase-resoluti.patch | 138 ++++++++++++++++++ .../files/scripts/launch_eiq_demo.sh | 2 +- .../files/service/eiqdemo.service | 8 +- 4 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/patches/0004-improvements-capture-x-windows-and-increase-resoluti.patch diff --git a/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/eiq-examples_git.bbappend b/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/eiq-examples_git.bbappend index b9ca14bee..a1db80aeb 100644 --- a/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/eiq-examples_git.bbappend +++ b/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/eiq-examples_git.bbappend @@ -13,6 +13,7 @@ SRC_URI += " \ file://patches/0001-Customize-EiQ-demos.patch \ file://patches/0002-dms-update-the-demo-to-use-the-landmark-full-model.patch \ file://patches/0003-download_models-update-the-download-location-of-some.patch \ + file://patches/0004-improvements-capture-x-windows-and-increase-resoluti.patch \ file://scripts/launch_eiq_demo.sh \ file://service/eiqdemo.service \ " @@ -25,7 +26,7 @@ do_download_transform_models() { do_download_transform_models[network] = "1" # Add the custom task to download and transform the models. -addtask do_download_transform_models after do_patch before do_install +addtask download_transform_models after do_patch before do_install inherit systemd diff --git a/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/patches/0004-improvements-capture-x-windows-and-increase-resoluti.patch b/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/patches/0004-improvements-capture-x-windows-and-increase-resoluti.patch new file mode 100644 index 000000000..87ad567d0 --- /dev/null +++ b/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/patches/0004-improvements-capture-x-windows-and-increase-resoluti.patch @@ -0,0 +1,138 @@ +From: Isaac Hermida +Date: Wed, 2 Oct 2024 11:58:15 +0200 +Subject: [PATCH] improvements: capture "x" windows and increase resolution + +When running in window mode (no fullscreen), stop the application. +Increase the camera resolution to 1280x720. + +Signed-off-by: Isaac Hermida +--- + dms/main.py | 13 +++++++++---- + face_recognition/main.py | 12 ++++++++---- + gesture_detection/main.py | 13 +++++++++---- + object_detection/main.py | 13 +++++++++---- + 4 files changed, 35 insertions(+), 16 deletions(-) + +diff --git a/dms/main.py b/dms/main.py +index e74b6be1b938..99b501ca2194 100644 +--- a/dms/main.py ++++ b/dms/main.py +@@ -14,10 +14,10 @@ from eye_landmark import EyeMesher + from face_landmark import FaceMesher + from utils import * + +-WIDTH=640 +-HEIGH=480 +-FLIP=None # None, skip, 0: Flip vertically, 1: Flip horizontally (around the y-axis), -1: Flip both vertically and horizontally +-FORMAT=0 # None, skip (YUYV, default), 0 MJPG (for usb camera) ++WIDTH=1280 ++HEIGH=720 ++FLIP=None # None, skip, 0: Flip vertically, 1: Flip horizontally (around the y-axis), -1: Flip both vertically and horizontally ++FORMAT=None # None, skip (YUYV, default), 0 MJPG (for usb camera) + + # Always enforce the Ethos NPU, use the converted vela models + MODEL_PATH = pathlib.Path("../vela_models/") +@@ -197,6 +197,11 @@ while ret: + if FLIP is not None: + image = cv2.flip(image, FLIP) + if cv2.waitKey(1) & 0xFF == ord('q'): ++ # "q" key pressed ++ break ++ ++ if cv2.getWindowProperty(window_name, cv2.WND_PROP_AUTOSIZE): ++ # Window closed by click 'X' + break + except Exception as err: + # Ignore exceptions +diff --git a/face_recognition/main.py b/face_recognition/main.py +index 33ffa7161fac..40ca9f8afb91 100644 +--- a/face_recognition/main.py ++++ b/face_recognition/main.py +@@ -13,10 +13,10 @@ from face_detection import YoloFace + from face_recognition import Facenet + from face_database import FaceDatabase + +-WIDTH=640 +-HEIGH=480 +-FLIP=None # None, skip, 0: Flip vertically, 1: Flip horizontally (around the y-axis), -1: Flip both vertically and horizontally +-FORMAT=0 # None, skip (YUYV, default), 0 MJPG (for usb camera) ++WIDTH=1280 ++HEIGH=720 ++FLIP=None # None, skip, 0: Flip vertically, 1: Flip horizontally (around the y-axis), -1: Flip both vertically and horizontally ++FORMAT=None # None, skip (YUYV, default), 0 MJPG (for usb camera) + + parser = argparse.ArgumentParser() + parser.add_argument( +@@ -144,6 +144,10 @@ while True: + while cv2.waitKey(100) & 0xFF == 0xFF: + pass + ++ if cv2.getWindowProperty(window_name, cv2.WND_PROP_AUTOSIZE): ++ # Window closed by click 'X' ++ break ++ + time.sleep(2) + vid.release() + cv2.destroyAllWindows() +diff --git a/gesture_detection/main.py b/gesture_detection/main.py +index 15b85976fd72..8ad2c9bd409b 100644 +--- a/gesture_detection/main.py ++++ b/gesture_detection/main.py +@@ -63,10 +63,10 @@ if args.input.isdigit(): + else: + cap_input = args.input + +-WIDTH=640 +-HEIGH=480 +-FLIP=None # None, skip, 0: Flip vertically, 1: Flip horizontally (around the y-axis), -1: Flip both vertically and horizontally +-FORMAT=0 # None, skip (YUYV, default), 0 MJPG (for usb camera) ++WIDTH=1280 ++HEIGH=720 ++FLIP=None # None, skip, 0: Flip vertically, 1: Flip horizontally (around the y-axis), -1: Flip both vertically and horizontally ++FORMAT=None # None, skip (YUYV, default), 0 MJPG (for usb camera) + + # This pipeline for the OV5640 camera in case the other command fails + # capture = cv2.VideoCapture("v4l2src device=%s ! imxvideoconvert_pxp ! video/x-raw,format=RGB16,width=%d,height=%d " \ +@@ -100,6 +100,11 @@ while ret: + + ret, frame = capture.read() + if cv2.waitKey(1) & 0xFF == ord('q'): ++ # "q" key pressed ++ break ++ ++ if cv2.getWindowProperty(window_name, cv2.WND_PROP_AUTOSIZE): ++ # Window closed by click 'X' + break + + cv2.waitKey(2000) +diff --git a/object_detection/main.py b/object_detection/main.py +index efa614ebd44b..34ba17eddffb 100644 +--- a/object_detection/main.py ++++ b/object_detection/main.py +@@ -13,10 +13,10 @@ import argparse + + from labels import label2string + +-WIDTH=640 +-HEIGH=480 +-FLIP=None # None, skip, 0: Flip vertically, 1: Flip horizontally (around the y-axis), -1: Flip both vertically and horizontally +-FORMAT=0 # None, skip (YUYV, default), 0 MJPG (for usb camera) ++WIDTH=1280 ++HEIGH=720 ++FLIP=None # None, skip, 0: Flip vertically, 1: Flip horizontally (around the y-axis), -1: Flip both vertically and horizontally ++FORMAT=None # None, skip (YUYV, default), 0 MJPG (for usb camera) + + # Always enforce the Ethos NPU, use the converted vela models + MODEL_PATH = "../vela_models/ssd_mobilenet_v1_quant_vela.tflite" +@@ -122,6 +122,11 @@ while ret: + if FLIP is not None: + frame = cv2.flip(frame, FLIP) + if cv2.waitKey(1) & 0xFF == ord('q'): ++ # "q" key pressed ++ break ++ ++ if cv2.getWindowProperty(window_name, cv2.WND_PROP_AUTOSIZE): ++ # Window closed by click 'X' + break + + cv2.waitKey(2000) diff --git a/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/scripts/launch_eiq_demo.sh b/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/scripts/launch_eiq_demo.sh index d719c2988..374dd6d79 100644 --- a/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/scripts/launch_eiq_demo.sh +++ b/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/scripts/launch_eiq_demo.sh @@ -36,4 +36,4 @@ DEMO_DIR="/usr/bin/eiq-examples-git/${DEMO}" cd "${DEMO_DIR}" || exit # Execute the demo pre-configuring the display settings. -WAYLAND_DISPLAY=/run/wayland-0 DISPLAY=:0.0 XDG_RUNTIME_DIR=/run/user/0 python3 main.py -i /dev/video0 -f -d /usr/lib/libethosu_delegate.so & +WAYLAND_DISPLAY=/run/wayland-0 DISPLAY=:0.0 XDG_RUNTIME_DIR=/run/user/0 python3 main.py -i /dev/video0 -f -d /usr/lib/libethosu_delegate.so diff --git a/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/service/eiqdemo.service b/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/service/eiqdemo.service index 2189e5d4a..7313c5b8f 100644 --- a/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/service/eiqdemo.service +++ b/meta-digi-dey/dynamic-layers/meta-ml/recipes-libraries/eiq-examples/files/service/eiqdemo.service @@ -1,10 +1,12 @@ [Unit] Description=Initialization of EiQ DMS demo -After=multi-user.target +After=graphical.target +ConditionPathExists=/dev/video0 [Service] -Type=forking +Type=exec +RemainAfterExit=yes ExecStart=/etc/demos/scripts/launch_eiq_demo.sh [Install] -WantedBy=multi-user.target +WantedBy=graphical.target