From 53f82eda82a1aad7912ed9a3b39d4c1841cfdd39 Mon Sep 17 00:00:00 2001 From: Luna D Dragon Date: Sun, 19 Oct 2025 21:29:15 +0530 Subject: [PATCH 1/6] Ensure camera configuration works on enumerate_camera_devices enumerate_camera_devices previously did not check if a camera configuration worked. This resulted in users being presented with a set of configurations, some of which did not work. enumerate_camera_devices now attempted to capture a frame. If this does not work the configuration is not returned. This greatly reduces the number of "false" configurations. However there are some configurations which do not track but are still appended, I am unsure how to test these without requiring the camera be pointed at a person on startup. --- Mods/MediaPipe/_tracker/Project/new_tracker.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Mods/MediaPipe/_tracker/Project/new_tracker.py b/Mods/MediaPipe/_tracker/Project/new_tracker.py index 4bb067ac..79b66be3 100644 --- a/Mods/MediaPipe/_tracker/Project/new_tracker.py +++ b/Mods/MediaPipe/_tracker/Project/new_tracker.py @@ -835,7 +835,15 @@ def enumerate_camera_devices(): "path" : camera_info.path, "index" : camera_info.index } - - all_camera_data.append(camera_data) - + + cap = cv2.VideoCapture(camera_info.index, capture_api_preference) + working = False + if cap.isOpened(): + ret, frame = cap.read() + if ret and frame is not None: + working = True + cap.release() + if working: + all_camera_data.append(camera_data) + return all_camera_data From bea561b232f7d9f9e9d9e15f4fa1f6bd7e9df58d Mon Sep 17 00:00:00 2001 From: Luna D Dragon Date: Mon, 20 Oct 2025 12:41:23 +0530 Subject: [PATCH 2/6] Check if device is busy If a device is busy(i.e) used by another device assume it works, to tests this we check if we can open it using linuxpy and assume the configuration works if we get a errno = 16 which is "Device or resource busy" --- .../MediaPipe/_tracker/Project/new_tracker.py | 29 ++++++++++++++----- .../_tracker/Project/requirements.txt | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Mods/MediaPipe/_tracker/Project/new_tracker.py b/Mods/MediaPipe/_tracker/Project/new_tracker.py index 79b66be3..b0f3dd74 100644 --- a/Mods/MediaPipe/_tracker/Project/new_tracker.py +++ b/Mods/MediaPipe/_tracker/Project/new_tracker.py @@ -835,15 +835,28 @@ def enumerate_camera_devices(): "path" : camera_info.path, "index" : camera_info.index } - - cap = cv2.VideoCapture(camera_info.index, capture_api_preference) - working = False - if cap.isOpened(): + + if sys.platform == "linux": + from linuxpy.video.device import Device, VideoCapture + + cap = cv2.VideoCapture(camera_info.index, capture_api_preference) + works = False + if cap.isOpened(): ret, frame = cap.read() if ret and frame is not None: - working = True - cap.release() - if working: + works = True + else: + with Device(camera_info.path) as camera: + try: + for frame in camera: + pass + except OSError as e: + if e.errno == 16: + works = True + cap.release() + if works: + all_camera_data.append(camera_data) + else: all_camera_data.append(camera_data) - + return all_camera_data diff --git a/Mods/MediaPipe/_tracker/Project/requirements.txt b/Mods/MediaPipe/_tracker/Project/requirements.txt index 21607760..3374aef2 100644 --- a/Mods/MediaPipe/_tracker/Project/requirements.txt +++ b/Mods/MediaPipe/_tracker/Project/requirements.txt @@ -2,4 +2,4 @@ mediapipe==0.10.14 psutil==6.0.0 cv2-enumerate-cameras==1.1.18.2 numpy==1.26.0 - +linuxpy==0.23.0; sys_platform == "linux" From 9b585ce28bddbdd53b4c9aa788f30262cff4890b Mon Sep 17 00:00:00 2001 From: Luna D Dragon Date: Wed, 12 Nov 2025 20:22:14 +0530 Subject: [PATCH 3/6] Mediapipe: deduplicate cameras on windows On windows CAP_ANY returns 2 "entries" for every camera. Direct Show (DSHOW) and Media Foundation (MSMF) MSMF was introduced in windows vista and DSHOW has since been deprecated and its docs carry the warning it maybe ripped out in a future windows version. For future readiness only filter by CAP_MSMF. --- Mods/MediaPipe/_tracker/Project/new_tracker.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Mods/MediaPipe/_tracker/Project/new_tracker.py b/Mods/MediaPipe/_tracker/Project/new_tracker.py index b0f3dd74..a36fa570 100644 --- a/Mods/MediaPipe/_tracker/Project/new_tracker.py +++ b/Mods/MediaPipe/_tracker/Project/new_tracker.py @@ -797,6 +797,11 @@ def enumerate_camera_devices(): if sys.platform == "linux": capture_api_preference = cv2.CAP_V4L2 + # CAP_ANY provides a Direct Show(DSHOW) backend and a Media Foundation(MSMF) backend + # MSMF is more modern and DSHOW maybe removed in any future version of windows so filter by MSMF + if sys.platform == "win32": + capture_api_preference = cv2.CAP_MSMF + # On Linux, we sometimes see stuff showing up as just "video#", so # let's at least try to correlate paths and IDs from # /dev/v4l/by-id . From 003daa327d9db8de5223389b0654991db0a104d1 Mon Sep 17 00:00:00 2001 From: Luna D Dragon Date: Sat, 29 Nov 2025 22:01:55 +0530 Subject: [PATCH 4/6] MediaPipe: fix performance issues on windows We now set OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS to "0" to fix the performance issues based on https://github.com/opencv/opencv/issues/17687\ This for reasons beyond my understanding fixes the issue. --- Mods/MediaPipe/_tracker/Project/new_tracker.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Mods/MediaPipe/_tracker/Project/new_tracker.py b/Mods/MediaPipe/_tracker/Project/new_tracker.py index a36fa570..066d9abc 100644 --- a/Mods/MediaPipe/_tracker/Project/new_tracker.py +++ b/Mods/MediaPipe/_tracker/Project/new_tracker.py @@ -3,6 +3,11 @@ import mediapipe from mediapipe.tasks import python from mediapipe.tasks.python import vision +import os +# this has to be set before cv2 is imported +# https://github.com/opencv/opencv/issues/17687 +os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0" + import cv2 import time import json @@ -14,7 +19,6 @@ from kiri_math import lerp import socket -import os import sys import psutil From 35db1566f650b3c7a00e214d86419b7366a627e7 Mon Sep 17 00:00:00 2001 From: Luna D Dragon Date: Mon, 8 Dec 2025 18:40:51 +0530 Subject: [PATCH 5/6] update platform_status.json --- Core/UI/Images/icons/kiri_smug.png.import | 34 +++++++++++++++++++ .../KiriPythonRPCWrapper/platform_status.json | 24 ++++++------- 2 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 Core/UI/Images/icons/kiri_smug.png.import diff --git a/Core/UI/Images/icons/kiri_smug.png.import b/Core/UI/Images/icons/kiri_smug.png.import new file mode 100644 index 00000000..e420f785 --- /dev/null +++ b/Core/UI/Images/icons/kiri_smug.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bqosafyakp6kp" +path="res://.godot/imported/kiri_smug.png-3779d780d643bd959b80f9294c1515ce.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Core/UI/Images/icons/kiri_smug.png" +dest_files=["res://.godot/imported/kiri_smug.png-3779d780d643bd959b80f9294c1515ce.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/addons/KiriPythonRPCWrapper/platform_status.json b/addons/KiriPythonRPCWrapper/platform_status.json index f02968e9..d73edb03 100644 --- a/addons/KiriPythonRPCWrapper/platform_status.json +++ b/addons/KiriPythonRPCWrapper/platform_status.json @@ -3,33 +3,33 @@ "Linux-arm64": { "complete_filename": "cpython-3.12.7+20241016-aarch64-unknown-linux-gnu-install_only_stripped.tar.gz", "download_url": "https://github.com/indygreg/python-build-standalone/releases/download/20241016/cpython-3.12.7%2B20241016-aarch64-unknown-linux-gnu-install_only_stripped.tar.gz", - "file_size": 17865102, + "file_size": 17865102.0, "sort": "cpython-00000003-00000012-00000007-20241016-aarch64-unknown-linux-gnu-install_only_stripped-tar-gz" }, "Linux-x86_64": { "complete_filename": "cpython-3.12.5+20240814-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz", "download_url": "https://github.com/indygreg/python-build-standalone/releases/download/20240814/cpython-3.12.5%2B20240814-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz", - "file_size": 21984711, + "file_size": 21984711.0, "sort": "cpython-00000003-00000012-00000005-20240814-x86_64-unknown-linux-gnu-install_only_stripped-tar-gz" }, "Windows-x86_64": { "complete_filename": "cpython-3.12.5+20240814-x86_64-pc-windows-msvc-shared-install_only_stripped.tar.gz", "download_url": "https://github.com/indygreg/python-build-standalone/releases/download/20240814/cpython-3.12.5%2B20240814-x86_64-pc-windows-msvc-shared-install_only_stripped.tar.gz", - "file_size": 23569213, + "file_size": 23569213.0, "sort": "cpython-00000003-00000012-00000005-20240814-x86_64-pc-windows-msvc-shared-install_only_stripped-tar-gz" }, - "macOS-x86_64": { - "complete_filename": "cpython-3.12.5+20240814-x86_64-apple-darwin-install_only_stripped.tar.gz", - "download_url": "https://github.com/indygreg/python-build-standalone/releases/download/20240814/cpython-3.12.5%2B20240814-x86_64-apple-darwin-install_only_stripped.tar.gz", - "file_size": 16564547, - "sort": "cpython-00000003-00000012-00000005-20240814-x86_64-apple-darwin-install_only_stripped-tar-gz" - }, "macOS-arm64": { "complete_filename": "cpython-3.12.5+20240814-aarch64-apple-darwin-install_only_stripped.tar.gz", "download_url": "https://github.com/indygreg/python-build-standalone/releases/download/20240814/cpython-3.12.5%2B20240814-aarch64-apple-darwin-install_only_stripped.tar.gz", - "file_size": 16223961, + "file_size": 16223961.0, "sort": "cpython-00000003-00000012-00000005-20240814-aarch64-apple-darwin-install_only_stripped-tar-gz" + }, + "macOS-x86_64": { + "complete_filename": "cpython-3.12.5+20240814-x86_64-apple-darwin-install_only_stripped.tar.gz", + "download_url": "https://github.com/indygreg/python-build-standalone/releases/download/20240814/cpython-3.12.5%2B20240814-x86_64-apple-darwin-install_only_stripped.tar.gz", + "file_size": 16564547.0, + "sort": "cpython-00000003-00000012-00000005-20240814-x86_64-apple-darwin-install_only_stripped-tar-gz" } }, - "requirements": "mediapipe==0.10.14\npsutil==6.0.0\ncv2-enumerate-cameras==1.1.18.2\nnumpy==1.26.0\n\n" -} + "requirements": "mediapipe==0.10.14\npsutil==6.0.0\ncv2-enumerate-cameras==1.1.18.2\nnumpy==1.26.0\nlinuxpy==0.23.0; sys_platform == \"linux\"\n" +} \ No newline at end of file From ed5a98f16f30069ddd6d18ddd9a63eb1669fbbf5 Mon Sep 17 00:00:00 2001 From: Luna D Dragon Date: Mon, 8 Dec 2025 18:51:22 +0530 Subject: [PATCH 6/6] Add fallback for win32 to CAP_DSHOW If CAP_MSMF fails to get any cameras we now enumerate cameras using DSHOW preserving the ability to run snudio in wine(if anyone is actually doing that) --- Mods/MediaPipe/_tracker/Project/new_tracker.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Mods/MediaPipe/_tracker/Project/new_tracker.py b/Mods/MediaPipe/_tracker/Project/new_tracker.py index 066d9abc..e4a56b52 100644 --- a/Mods/MediaPipe/_tracker/Project/new_tracker.py +++ b/Mods/MediaPipe/_tracker/Project/new_tracker.py @@ -821,9 +821,11 @@ def enumerate_camera_devices(): pass all_camera_data = [] - - for camera_info in enumerate_cameras(apiPreference=capture_api_preference): - + cameras = enumerate_cameras(apiPreference=capture_api_preference) + if sys.platform == "win32" and len(cameras) == 0: + capture_api_preference = cv2.CAP_DSHOW + cameras = enumerate_cameras(apiPreference=capture_api_preference) + for camera_info in cameras: camera_name = camera_info.name if re.match("video[0-9]+", camera_info.name):