|
25 | 25 | os.add_dll_directory(str(_LIB_DIR)) |
26 | 26 | os.environ["PATH"] = str(_LIB_DIR) + os.pathsep + os.environ.get("PATH", "") |
27 | 27 |
|
| 28 | + |
| 29 | +def _win_to_wsl_path(path: str) -> str: |
| 30 | + """Translate a Windows-style path (C:\\...) to a WSL /mnt/ path when running in WSL.""" |
| 31 | + import re |
| 32 | + if not path: |
| 33 | + return path |
| 34 | + # Already a Unix path — leave it alone |
| 35 | + if path.startswith('/'): |
| 36 | + return path |
| 37 | + # Windows drive letter: C:\Users\... → /mnt/c/Users/... |
| 38 | + match = re.match(r'^([A-Za-z]):[/\\](.*)', path) |
| 39 | + if match: |
| 40 | + drive = match.group(1).lower() |
| 41 | + rest = match.group(2).replace('\\', '/') |
| 42 | + return f'/mnt/{drive}/{rest}' |
| 43 | + return path |
| 44 | + |
28 | 45 | import numpy as np |
29 | 46 | from PIL import Image |
30 | 47 |
|
@@ -56,14 +73,17 @@ def _edgetpu_lib_name(): |
56 | 73 | """Return the platform-specific libedgetpu shared library name.""" |
57 | 74 | import platform |
58 | 75 | system = platform.system() |
59 | | - |
60 | | - # Priority order for checking local delegate libs |
61 | | - candidates = [ |
62 | | - Path(__file__).parent.parent / "libedgetpu.so.1", # WSL root |
63 | | - Path(__file__).parent.parent / "lib" / "libedgetpu.so.1", # OSX/Linux layout |
64 | | - ] |
65 | | - |
| 76 | + |
66 | 77 | if system == "Linux": |
| 78 | + # Priority 1: system-installed library (copied here by deploy.bat — works on NTFS-free path) |
| 79 | + system_lib = Path("/usr/local/lib/libedgetpu.so.1") |
| 80 | + if system_lib.exists(): |
| 81 | + return str(system_lib) |
| 82 | + # Priority 2: bundled alongside the skill (may fail if on /mnt/c NTFS mount) |
| 83 | + candidates = [ |
| 84 | + Path(__file__).parent.parent / "libedgetpu.so.1", |
| 85 | + Path(__file__).parent.parent / "lib" / "libedgetpu.so.1", |
| 86 | + ] |
67 | 87 | for cand in candidates: |
68 | 88 | if cand.exists(): |
69 | 89 | return str(cand.resolve()) |
@@ -411,6 +431,8 @@ def detect_frame(self, frame_path: str) -> Tuple[List[Dict[str, Any]], Dict[str, |
411 | 431 | t0 = time.perf_counter() |
412 | 432 |
|
413 | 433 | try: |
| 434 | + # Translate Windows paths to WSL /mnt/ paths when running inside WSL |
| 435 | + frame_path = _win_to_wsl_path(frame_path) |
414 | 436 | img = Image.open(frame_path).convert("RGB") |
415 | 437 | except Exception as e: |
416 | 438 | log(f"ERROR reading frame: {e}") |
|
0 commit comments