@react-opencv/fiber 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -8
- package/dist/components/OpenCvProvider.d.ts +3 -3
- package/dist/fiber/CvCanvas.d.ts +1 -0
- package/dist/fiber/CvNode.d.ts +1 -0
- package/dist/fiber/executePipeline.d.ts +2 -2
- package/dist/fiber/matDebug.d.ts +2 -0
- package/dist/fiber/types.d.ts +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +657 -583
- package/dist/types.d.ts +7 -0
- package/package.json +22 -2
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# react-opencv-fiber
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@react-opencv/fiber)
|
|
4
|
+
|
|
3
5
|
A React renderer for OpenCV.js. Write image-processing pipelines as JSX — each element maps to an OpenCV operation, and the tree executes bottom-up through a custom React reconciler.
|
|
4
6
|
|
|
5
7
|
[**Live demo**](https://erasta.github.io/react-opencv-fiber/)
|
|
@@ -52,13 +54,19 @@ Renders a `<canvas>` and executes the CV pipeline defined by its children.
|
|
|
52
54
|
<CvCanvas
|
|
53
55
|
style={{ maxWidth: "100%" }}
|
|
54
56
|
className="my-canvas"
|
|
55
|
-
onResult={(mat) => { /*
|
|
57
|
+
onResult={(mat) => { /* cloned Mat of the final result */ }}
|
|
56
58
|
>
|
|
57
59
|
{/* CV operation tree */}
|
|
58
60
|
</CvCanvas>
|
|
59
61
|
```
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
| Prop | Type | Description |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| `style` | `CSSProperties` | CSS styles for the canvas element |
|
|
66
|
+
| `className` | `string` | CSS class for the canvas element |
|
|
67
|
+
| `headless` | `boolean` | When `true`, runs the pipeline without rendering a canvas (returns `null`). Useful for producing intermediate results via `onResult`. |
|
|
68
|
+
| `onResult` | `(mat: Mat) => void` | Called with a **cloned** Mat after each pipeline run. The clone stays valid across re-runs — you own it. |
|
|
69
|
+
| `ref` | `Ref<HTMLCanvasElement>` | Forwarded to the underlying canvas element |
|
|
62
70
|
|
|
63
71
|
### CV operation elements
|
|
64
72
|
|
|
@@ -89,22 +97,92 @@ Operations are nested inside-out — the innermost element runs first:
|
|
|
89
97
|
|
|
90
98
|
Props map directly to OpenCV function parameters. Array values are coerced to the appropriate OpenCV types (`Size`, `Point`, `Scalar`).
|
|
91
99
|
|
|
92
|
-
|
|
100
|
+
#### `__srcParam` / `__dstParam`
|
|
93
101
|
|
|
94
|
-
|
|
102
|
+
By default, each operation is called as `cv.op(src, dst, ...params)` — matching the OpenCV.js convention of `src` at position 0 and `dst` at position 1. Some functions use a different argument order. Use `__srcParam` and `__dstParam` to override the position:
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
{/* applyColorMap expects cv.applyColorMap(src, colormap, dst) */}
|
|
106
|
+
<cvApplyColorMap colormap={2} __dstParam={2}>
|
|
107
|
+
<cvCvtColor code={11}>
|
|
108
|
+
<cvImage src="photo.jpg" />
|
|
109
|
+
</cvCvtColor>
|
|
110
|
+
</cvApplyColorMap>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Special leaf elements
|
|
114
|
+
|
|
115
|
+
These are leaf nodes that provide input to the pipeline (they have no children).
|
|
116
|
+
|
|
117
|
+
#### `<cvImage>`
|
|
118
|
+
|
|
119
|
+
Loads an image (URL or data URI) into a `Mat`.
|
|
95
120
|
|
|
96
121
|
```tsx
|
|
97
122
|
<cvImage src="https://example.com/photo.jpg" />
|
|
98
123
|
```
|
|
99
124
|
|
|
100
|
-
|
|
125
|
+
#### `<cvMat>`
|
|
126
|
+
|
|
127
|
+
Accepts an existing `Mat` as pipeline input. The mat is **cloned internally**, so the original stays valid and is never disposed by the pipeline.
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
<cvMat mat={someMatFromState} />
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Use this to share the output of one pipeline as input to another (see [Sharing results between pipelines](#sharing-results-between-pipelines)).
|
|
134
|
+
|
|
135
|
+
### Sharing results between pipelines
|
|
136
|
+
|
|
137
|
+
Use `headless` mode to run a pipeline without a canvas, capture its result with `onResult`, and feed it into other pipelines via `<cvMat>`:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
const [blurredMat, setBlurredMat] = useState<Mat | null>(null);
|
|
141
|
+
|
|
142
|
+
{/* Headless pipeline: blur and share result */}
|
|
143
|
+
<CvCanvas headless onResult={setBlurredMat}>
|
|
144
|
+
<cvGaussianBlur ksize={[5, 5]} sigmaX={0}>
|
|
145
|
+
<cvImage src="photo.jpg" />
|
|
146
|
+
</cvGaussianBlur>
|
|
147
|
+
</CvCanvas>
|
|
148
|
+
|
|
149
|
+
{/* Display the blurred intermediate */}
|
|
150
|
+
<CvCanvas>
|
|
151
|
+
<cvMat mat={blurredMat} />
|
|
152
|
+
</CvCanvas>
|
|
153
|
+
|
|
154
|
+
{/* Apply further operations on the shared result */}
|
|
155
|
+
<CvCanvas>
|
|
156
|
+
<cvCanny threshold1={50} threshold2={150}>
|
|
157
|
+
<cvMat mat={blurredMat} />
|
|
158
|
+
</cvCanny>
|
|
159
|
+
</CvCanvas>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Both `onResult` and `<cvMat>` clone the Mat, so there are no ownership conflicts — each pipeline manages its own memory.
|
|
163
|
+
|
|
164
|
+
## Examples
|
|
165
|
+
|
|
166
|
+
The `examples/` directory contains interactive demos with different filter combinations. [**Live demo**](https://erasta.github.io/react-opencv-fiber/)
|
|
167
|
+
|
|
168
|
+
<p>
|
|
169
|
+
<img src="gifs/canny-gaussian.gif" width="400" />
|
|
170
|
+
<img src="gifs/adaptive-threshold-blur.gif" width="400" />
|
|
171
|
+
</p>
|
|
172
|
+
<p>
|
|
173
|
+
<img src="gifs/edge-preserving-canny.gif" width="400" />
|
|
174
|
+
<img src="gifs/laplacian-blur.gif" width="400" />
|
|
175
|
+
</p>
|
|
176
|
+
<p>
|
|
177
|
+
<img src="gifs/median-equalize.gif" width="400" />
|
|
178
|
+
</p>
|
|
101
179
|
|
|
102
|
-
|
|
180
|
+
To run locally:
|
|
103
181
|
|
|
104
182
|
```sh
|
|
105
183
|
npm install
|
|
106
|
-
|
|
107
|
-
npm
|
|
184
|
+
npm run build
|
|
185
|
+
cd examples && npm install && npx vite
|
|
108
186
|
```
|
|
109
187
|
|
|
110
188
|
## Acknowledgements
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { OpenCVContextValue } from "../types";
|
|
1
|
+
import type { CvDebugConfig, OpenCVContextValue } from "../types";
|
|
2
2
|
export declare function useOpenCv(): OpenCVContextValue;
|
|
3
|
-
export declare const OpenCvProvider: ({ openCvVersion, openCvPath,
|
|
3
|
+
export declare const OpenCvProvider: ({ openCvVersion, openCvPath, debug, children, }: {
|
|
4
4
|
openCvVersion?: string;
|
|
5
5
|
openCvPath?: string;
|
|
6
|
-
|
|
6
|
+
debug?: CvDebugConfig;
|
|
7
7
|
children: any;
|
|
8
8
|
}) => import("react/jsx-runtime").JSX.Element;
|
package/dist/fiber/CvCanvas.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface CvCanvasProps {
|
|
|
4
4
|
children?: ReactNode;
|
|
5
5
|
style?: CSSProperties;
|
|
6
6
|
className?: string;
|
|
7
|
+
headless?: boolean;
|
|
7
8
|
onResult?: (mat: Mat) => void;
|
|
8
9
|
}
|
|
9
10
|
export declare const CvCanvas: import("react").ForwardRefExoticComponent<CvCanvasProps & import("react").RefAttributes<HTMLCanvasElement>>;
|
package/dist/fiber/CvNode.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { CV, Mat } from "../types";
|
|
1
|
+
import type { CV, Mat, CvDebugConfig } from "../types";
|
|
2
2
|
import { CvNode } from "./CvNode";
|
|
3
|
-
export declare function executePipeline(cv: CV, node: CvNode): Promise<Mat | null>;
|
|
3
|
+
export declare function executePipeline(cv: CV, node: CvNode, missingOps?: Set<string>, debug?: CvDebugConfig): Promise<Mat | null>;
|
package/dist/fiber/types.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { CvCanvas } from "./fiber/CvCanvas";
|
|
|
3
3
|
export type { CvCanvasProps } from "./fiber/CvCanvas";
|
|
4
4
|
export type { CvOpProps } from "./fiber/types";
|
|
5
5
|
import "./fiber/types";
|
|
6
|
-
export type { CV, Mat, OpenCVContextValue, ParamConfig, SignatureParam, SignatureOverload, SignatureEntry, } from "./types";
|
|
6
|
+
export type { CV, Mat, CvDebugConfig, OpenCVContextValue, ParamConfig, SignatureParam, SignatureOverload, SignatureEntry, } from "./types";
|