Skip to content

Commit 9ac45d9

Browse files
committed
Fix type signatures after rebase
1 parent 9b77da7 commit 9ac45d9

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

apps/computer-vision/components/vision_camera/tasks/ObjectDetectionTask.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
SSDLITE_320_MOBILENET_V3_LARGE,
99
YOLO26N,
1010
useObjectDetection,
11+
CocoLabel,
12+
CocoLabelYolo,
1113
} from 'react-native-executorch';
1214
import { labelColor, labelColorBg } from '../utils/colors';
1315
import { TaskProps } from './types';
@@ -50,7 +52,9 @@ export default function ObjectDetectionTask({
5052
? rfdetr
5153
: yolo26n;
5254

53-
const [detections, setDetections] = useState<Detection[]>([]);
55+
type CommonDetection = Omit<Detection, 'label'> & { label: string };
56+
57+
const [detections, setDetections] = useState<CommonDetection[]>([]);
5458
const [imageSize, setImageSize] = useState({ width: 1, height: 1 });
5559
const lastFrameTimeRef = useRef(Date.now());
5660

@@ -69,8 +73,19 @@ export default function ObjectDetectionTask({
6973
const detRof = active.runOnFrame;
7074

7175
const updateDetections = useCallback(
72-
(p: { results: Detection[]; imageWidth: number; imageHeight: number }) => {
73-
setDetections(p.results);
76+
(p: {
77+
results:
78+
| Detection<typeof CocoLabel>[]
79+
| Detection<typeof CocoLabelYolo>[];
80+
imageWidth: number;
81+
imageHeight: number;
82+
}) => {
83+
setDetections(
84+
p.results.map((det) => ({
85+
...det,
86+
label: String(det.label),
87+
}))
88+
);
7489
setImageSize({ width: p.imageWidth, height: p.imageHeight });
7590
const now = Date.now();
7691
const diff = now - lastFrameTimeRef.current;
@@ -95,7 +110,9 @@ export default function ObjectDetectionTask({
95110
try {
96111
if (!detRof) return;
97112
const isFrontCamera = cameraPositionSync.getDirty() === 'front';
98-
const result = detRof(frame, isFrontCamera, 0.5);
113+
const result = detRof(frame, isFrontCamera, {
114+
detectionThreshold: 0.5,
115+
});
99116
// Sensor frames are landscape-native, so width/height are swapped
100117
// relative to portrait screen orientation.
101118
const screenW = frame.height;

packages/react-native-executorch/src/modules/computer_vision/ObjectDetectionModule.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ export class ObjectDetectionModule<
132132

133133
/**
134134
* Returns the available input sizes for this model, or undefined if the model accepts any size.
135-
*
136135
* @returns An array of available input sizes, or undefined if not constrained.
137-
*
138136
* @example
139137
* ```typescript
140138
* const sizes = model.getAvailableInputSizes(); // [384, 512, 640] for YOLO models, or undefined for RF-DETR
@@ -146,10 +144,12 @@ export class ObjectDetectionModule<
146144

147145
/**
148146
* Override runOnFrame to provide an options-based API for VisionCamera integration.
147+
* @returns A worklet function for frame processing, or null if the model is not loaded.
149148
*/
150149
override get runOnFrame():
151150
| ((
152151
frame: any,
152+
isFrontCamera: boolean,
153153
options?: ObjectDetectionOptions<ResolveLabels<T>>
154154
) => Detection<ResolveLabels<T>>[])
155155
| null {
@@ -171,6 +171,7 @@ export class ObjectDetectionModule<
171171

172172
return (
173173
frame: any,
174+
isFrontCamera: boolean,
174175
options?: ObjectDetectionOptions<ResolveLabels<T>>
175176
): Detection<ResolveLabels<T>>[] => {
176177
'worklet';
@@ -192,6 +193,7 @@ export class ObjectDetectionModule<
192193

193194
return baseRunOnFrame(
194195
frame,
196+
isFrontCamera,
195197
detectionThreshold,
196198
iouThreshold,
197199
classIndices,
@@ -206,12 +208,10 @@ export class ObjectDetectionModule<
206208
* Supports two input types:
207209
* 1. **String path/URI**: File path, URL, or Base64-encoded string
208210
* 2. **PixelData**: Raw pixel data from image libraries (e.g., NitroImage)
209-
*
210211
* @param input - A string image source (file path, URI, or Base64) or a {@link PixelData} object.
211212
* @param options - Optional configuration for detection inference. Includes `detectionThreshold`, `inputSize`, and `classesOfInterest`.
212213
* @returns A Promise resolving to an array of {@link Detection} objects.
213214
* @throws {RnExecutorchError} If the model is not loaded or if an invalid `inputSize` is provided.
214-
*
215215
* @example
216216
* ```typescript
217217
* const detections = await model.forward('path/to/image.jpg', {

packages/react-native-executorch/src/types/objectDetection.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export interface Detection<L extends LabelEnum = typeof CocoLabel> {
3434

3535
/**
3636
* Options for configuring object detection inference.
37-
*
3837
* @category Types
3938
* @typeParam L - The label enum type for filtering classes of interest.
4039
* @property {number} [detectionThreshold] - Minimum confidence score for detections (0-1). Defaults to model-specific value.
@@ -166,9 +165,7 @@ export interface ObjectDetectionType<L extends LabelEnum> {
166165
/**
167166
* Returns the available input sizes for multi-method models (e.g., YOLO).
168167
* Returns undefined for single-method models (e.g., RF-DETR, SSDLite).
169-
*
170168
* @returns Array of available input sizes or undefined
171-
*
172169
* @example
173170
* ```typescript
174171
* const sizes = model.getAvailableInputSizes(); // [384, 512, 640] for YOLO models
@@ -189,9 +186,11 @@ export interface ObjectDetectionType<L extends LabelEnum> {
189186
* @param options - Optional configuration for detection inference
190187
* @returns Array of Detection objects representing detected items in the frame.
191188
*/
192-
runOnFrame: (
193-
frame: Frame,
194-
isFrontCamera: boolean,
195-
options?: ObjectDetectionOptions<L>
196-
) => Detection<L>[];
189+
runOnFrame:
190+
| ((
191+
frame: Frame,
192+
isFrontCamera: boolean,
193+
options?: ObjectDetectionOptions<L>
194+
) => Detection<L>[])
195+
| null;
197196
}

0 commit comments

Comments
 (0)