-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
126 lines (106 loc) · 3.63 KB
/
Copy pathtypes.ts
File metadata and controls
126 lines (106 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// This file is part of @robomous/opencv-react project from Robomous.
// It is subject to the license terms in the LICENSE file found in the top-level directory
import type { RefObject } from 'react';
/**
* Minimal typing for the OpenCV.js namespace.
* Consumers can augment this via module augmentation if needed.
*/
export interface OpenCVNamespace {
// Core Mat
Mat: new (...args: unknown[]) => CVMat;
MatVector: new () => CVMatVector;
Size: new (width: number, height: number) => CVSize;
Point: new (x: number, y: number) => CVPoint;
Scalar: new (v0: number, v1?: number, v2?: number, v3?: number) => CVScalar;
CLAHE: new (clipLimit?: number, tileGridSize?: CVSize) => CVCLAHE;
// Image I/O
imread(canvas: HTMLCanvasElement | string): CVMat;
imshow(canvas: HTMLCanvasElement | string, mat: CVMat): void;
// Color conversion
cvtColor(src: CVMat, dst: CVMat, code: number, dstCn?: number): void;
// Runtime
onRuntimeInitialized?: () => void;
// Color conversion constants
COLOR_RGBA2GRAY: number;
COLOR_RGB2GRAY: number;
COLOR_GRAY2RGBA: number;
COLOR_BGR2RGB: number;
COLOR_RGB2BGR: number;
// Allow additional members from the full OpenCV.js API
[key: string]: unknown;
}
export interface CVMat {
delete(): void;
rows: number;
cols: number;
data: Uint8Array;
data32F: Float32Array;
size(): CVSize;
}
export interface CVMatVector {
delete(): void;
size(): number;
get(index: number): CVMat;
push_back(mat: CVMat): void;
}
export interface CVSize {
width: number;
height: number;
}
export interface CVPoint {
x: number;
y: number;
}
export interface CVScalar {
[index: number]: number;
}
export interface CVCLAHE {
apply(src: CVMat, dst: CVMat): void;
delete(): void;
}
// ─── Hook types ─────────────────────────────────────────────────────────────
export interface UseOpenCVOptions {
/** Automatically load OpenCV when the component mounts. Defaults to true. */
autoLoad?: boolean;
/** Override the default OpenCV.js asset URL. */
src?: string;
}
export interface UseOpenCVReturn {
cv: OpenCVNamespace | null;
isReady: boolean;
isLoading: boolean;
error: Error | null;
load: () => Promise<void>;
}
// ─── Component types ─────────────────────────────────────────────────────────
export interface LoadPayload {
canvas: HTMLCanvasElement;
context: CanvasRenderingContext2D;
image: HTMLImageElement;
}
export interface ProcessPayload extends LoadPayload {
cv: OpenCVNamespace;
outputCanvas?: HTMLCanvasElement;
}
export interface OpenCVCanvasProps {
/** Source image URL to load and draw onto the internal canvas. */
src: string;
/** Optional ref to an external output canvas for processed results. */
outputCanvasRef?: RefObject<HTMLCanvasElement | null>;
/**
* Whether to call `onProcess` automatically after the image loads and
* OpenCV is ready. Defaults to true.
*/
autoProcess?: boolean;
className?: string;
crossOrigin?: '' | 'anonymous' | 'use-credentials';
/** Called once the source image has been drawn to the internal canvas. */
onLoad?: (payload: LoadPayload) => void;
/**
* Called when OpenCV is ready and the image has been drawn.
* Use the `finally` block to call `mat.delete()` on all created Mats.
*/
onProcess?: (payload: ProcessPayload) => void | Promise<void>;
/** Called when an error occurs during image loading or processing. */
onError?: (error: Error) => void;
}