feat: add OpenCV loader, Otsu threshold and margin-aware mask tracing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
immortaly007andClaude Opus 5.5 committed 2026-10-15 14:43:41 +02:00
1 parent 8d597e856e
commit 5e4eebaaa2
5 files changed
+231

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
export type CV = typeof import('@techstark/opencv-js');
let loading: Promise<{ cv: CV }> | null = null;
// Wrapped in an object: the cv module is a thenable, so resolving with it directly never settles.
export function loadOpenCV(): Promise<{ cv: CV }> {
loading ??= (async () => {
const mod = (await import('@techstark/opencv-js')) as unknown as { default: CV };
const cv = mod.default;
if (!cv.Mat) {
await new Promise<void>((resolve) => {
(cv as unknown as { onRuntimeInitialized: () => void }).onRuntimeInitialized = () => resolve();
});
}
return { cv };
})();
return loading;
}