Skip to content

Commit 35c2a3f

Browse files
feat: some improvements
1 parent 2f29c67 commit 35c2a3f

File tree

13 files changed

+19
-220
lines changed

13 files changed

+19
-220
lines changed

apps/computer-vision/app/object_detection/index.tsx

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -50,49 +50,6 @@ export default function ObjectDetectionScreen() {
5050
}
5151
};
5252

53-
const runForwardPixels = async () => {
54-
try {
55-
console.log('Testing with hardcoded pixel data...');
56-
57-
// Create a simple 320x320 test image (all zeros - black image)
58-
// In a real scenario, you would load actual image pixel data here
59-
const width = 320;
60-
const height = 320;
61-
const channels = 3; // RGB
62-
63-
// Create a black image (you can replace this with actual pixel data)
64-
const rgbData = new Uint8Array(width * height * channels);
65-
66-
// Optionally, add some test pattern (e.g., white square in center)
67-
for (let y = 100; y < 220; y++) {
68-
for (let x = 100; x < 220; x++) {
69-
const idx = (y * width + x) * 3;
70-
rgbData[idx + 0] = 255; // R
71-
rgbData[idx + 1] = 255; // G
72-
rgbData[idx + 2] = 255; // B
73-
}
74-
}
75-
76-
const pixelData: PixelData = {
77-
dataPtr: rgbData,
78-
sizes: [height, width, channels],
79-
scalarType: ScalarType.BYTE,
80-
};
81-
82-
console.log('Running forward with hardcoded pixel data...', {
83-
sizes: pixelData.sizes,
84-
dataSize: pixelData.dataPtr.byteLength,
85-
});
86-
87-
// Run inference using unified forward() API
88-
const output = await ssdLite.forward(pixelData, 0.3);
89-
console.log('Pixel data result:', output.length, 'detections');
90-
setResults(output);
91-
} catch (e) {
92-
console.error('Error in runForwardPixels:', e);
93-
}
94-
};
95-
9653
if (!rfDetr.isReady) {
9754
return (
9855
<Spinner

packages/react-native-executorch/common/rnexecutorch/data_processing/ImageProcessing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ readImageToTensor(const std::string &path,
225225
if (tensorDims.size() < 2) {
226226
char errorMessage[100];
227227
std::snprintf(errorMessage, sizeof(errorMessage),
228-
"Unexpected tensor size, expected at least 2 dimentions "
228+
"Unexpected tensor size, expected at least 2 dimensions "
229229
"but got: %zu.",
230230
tensorDims.size());
231231
throw RnExecutorchError(RnExecutorchErrorCode::UnexpectedNumInputs,

packages/react-native-executorch/common/rnexecutorch/utils/FrameExtractor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ cv::Mat extractFromAHardwareBuffer(void *hardwareBuffer) {
8888
errorMessage);
8989
}
9090

91-
// Note: We don't unlock here - Vision Camera manages the lifecycle
92-
91+
AHardwareBuffer_unlock(buffer, nullptr);
9392
return mat;
9493
#else
9594
throw RnExecutorchError(RnExecutorchErrorCode::PlatformNotSupported,
@@ -111,4 +110,4 @@ cv::Mat extractFromNativeBuffer(uint64_t bufferPtr) {
111110
#endif
112111
}
113112

114-
} // namespace rnexecutorch::utils
113+
} // namespace rnexecutorch::utils

packages/react-native-executorch/common/rnexecutorch/utils/FrameExtractor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ namespace rnexecutorch::utils {
2222
*/
2323
cv::Mat extractFromNativeBuffer(uint64_t bufferPtr);
2424

25-
} // namespace rnexecutorch::utils
25+
} // namespace rnexecutorch::utils

packages/react-native-executorch/common/rnexecutorch/utils/FrameProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ cv::Mat extractFrame(jsi::Runtime &runtime, const jsi::Object &frameData) {
2525

2626
return extractFromNativeBuffer(bufferPtr);
2727
}
28-
} // namespace rnexecutorch::utils
28+
} // namespace rnexecutorch::utils

packages/react-native-executorch/common/rnexecutorch/utils/FrameProcessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ using namespace facebook;
2424
*/
2525
cv::Mat extractFrame(jsi::Runtime &runtime, const jsi::Object &frameData);
2626

27-
} // namespace rnexecutorch::utils
27+
} // namespace rnexecutorch::utils

packages/react-native-executorch/src/controllers/BaseOCRController.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,11 @@ import { Logger } from '../common/Logger';
22
import { symbols } from '../constants/ocr/symbols';
33
import { RnExecutorchErrorCode } from '../errors/ErrorCodes';
44
import { RnExecutorchError, parseUnknownError } from '../errors/errorUtils';
5-
import { Frame, PixelData, ResourceSource, ScalarType } from '../types/common';
5+
import { isPixelData } from '../modules/computer_vision/VisionModule';
6+
import { Frame, PixelData, ResourceSource } from '../types/common';
67
import { OCRLanguage, OCRDetection } from '../types/ocr';
78
import { ResourceFetcher } from '../utils/ResourceFetcher';
89

9-
function isPixelData(input: unknown): input is PixelData {
10-
return (
11-
typeof input === 'object' &&
12-
input !== null &&
13-
'dataPtr' in input &&
14-
input.dataPtr instanceof Uint8Array &&
15-
'sizes' in input &&
16-
Array.isArray(input.sizes) &&
17-
input.sizes.length === 3 &&
18-
'scalarType' in input &&
19-
input.scalarType === ScalarType.BYTE
20-
);
21-
}
22-
2310
export abstract class BaseOCRController {
2411
protected nativeModule: any;
2512
public isReady: boolean = false;

packages/react-native-executorch/src/hooks/computer_vision/useImageSegmentation.ts

Lines changed: 0 additions & 131 deletions
This file was deleted.

packages/react-native-executorch/src/hooks/computer_vision/useSemanticSegmentation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PixelData } from '../..';
12
import {
23
SemanticSegmentationModule,
34
SegmentationLabels,
@@ -49,7 +50,7 @@ export const useSemanticSegmentation = <
4950
});
5051

5152
const forward = <K extends keyof SegmentationLabels<ModelNameOf<C>>>(
52-
imageSource: string,
53+
imageSource: string | PixelData,
5354
classesOfInterest: K[] = [],
5455
resizeToInput: boolean = true
5556
) =>

packages/react-native-executorch/src/hooks/useModuleFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export function useModuleFactory<
5555

5656
return () => {
5757
currentInstance?.delete();
58+
setInstance(null);
59+
setIsReady(false);
5860
};
5961

6062
// eslint-disable-next-line react-hooks/exhaustive-deps

0 commit comments

Comments
 (0)