@react-opencv/fiber 0.1.3 → 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 CHANGED
@@ -54,13 +54,19 @@ Renders a `<canvas>` and executes the CV pipeline defined by its children.
54
54
  <CvCanvas
55
55
  style={{ maxWidth: "100%" }}
56
56
  className="my-canvas"
57
- onResult={(mat) => { /* final Mat before display */ }}
57
+ onResult={(mat) => { /* cloned Mat of the final result */ }}
58
58
  >
59
59
  {/* CV operation tree */}
60
60
  </CvCanvas>
61
61
  ```
62
62
 
63
- Supports `ref` forwarding to the underlying canvas element.
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 |
64
70
 
65
71
  ### CV operation elements
66
72
 
@@ -104,14 +110,57 @@ By default, each operation is called as `cv.op(src, dst, ...params)` — matchin
104
110
  </cvApplyColorMap>
105
111
  ```
106
112
 
107
- ### `<cvImage>`
113
+ ### Special leaf elements
108
114
 
109
- Special element that loads an image (URL or data URI) into a `Mat`.
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`.
110
120
 
111
121
  ```tsx
112
122
  <cvImage src="https://example.com/photo.jpg" />
113
123
  ```
114
124
 
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
+
115
164
  ## Examples
116
165
 
117
166
  The `examples/` directory contains interactive demos with different filter combinations. [**Live demo**](https://erasta.github.io/react-opencv-fiber/)
@@ -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>>;
@@ -12,5 +12,6 @@ export declare class CvNode {
12
12
  insertBefore(child: CvNode, before: CvNode): void;
13
13
  propagateNotify(notify: (() => void) | null): void;
14
14
  dispose(): void;
15
+ cloneMat(_cv: CV): Mat | null;
15
16
  loadImage(cv: CV): Promise<Mat>;
16
17
  }
@@ -14,6 +14,8 @@ type CvElements = {
14
14
  } & {
15
15
  cvImage: CvOpProps;
16
16
  cv_image: CvOpProps;
17
+ cvMat: CvOpProps;
18
+ cv_mat: CvOpProps;
17
19
  };
18
20
  declare module "react" {
19
21
  namespace JSX {