Skip to content

Commit 7bea029

Browse files
refactor: add missing comments
1 parent 506cdc2 commit 7bea029

File tree

7 files changed

+35
-38
lines changed

7 files changed

+35
-38
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#pragma once
22

3-
// NOTE: This header must NOT include <jsi/jsi.h> — it is used in JSI-free unit
4-
// tests.
5-
63
#include <array>
74
#include <opencv2/opencv.hpp>
85
#include <string>
@@ -12,9 +9,12 @@ namespace rnexecutorch::utils {
129
enum class Orientation { Up, Down, Left, Right };
1310

1411
inline Orientation orientationFromString(const std::string &s) {
15-
if (s == "down") return Orientation::Down;
16-
if (s == "left") return Orientation::Left;
17-
if (s == "right") return Orientation::Right;
12+
if (s == "down")
13+
return Orientation::Down;
14+
if (s == "left")
15+
return Orientation::Left;
16+
if (s == "right")
17+
return Orientation::Right;
1818
return Orientation::Up;
1919
}
2020

@@ -91,7 +91,8 @@ void inverseRotatePoints(std::array<P, 4> &points,
9191

9292
#if defined(__APPLE__)
9393
if (orient.isMirrored) {
94-
bool swapped = (orient.orientation == Orientation::Up || orient.orientation == Orientation::Down);
94+
bool swapped = (orient.orientation == Orientation::Up ||
95+
orient.orientation == Orientation::Down);
9596
float sw = swapped ? h : w;
9697
float sh = swapped ? w : h;
9798
for (auto &p : points) {

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ export const useOCR = ({ model, preventLoad = false }: OCRProps): OCRType => {
3535

3636
if (preventLoad) return;
3737

38-
controller.load(
39-
model.detectorSource,
40-
model.recognizerSource,
41-
model.language,
42-
setDownloadProgress
43-
);
38+
controller
39+
.load(
40+
model.detectorSource,
41+
model.recognizerSource,
42+
model.language,
43+
setDownloadProgress
44+
)
45+
.then(() => {
46+
const worklet = controller.runOnFrame;
47+
if (worklet) setRunOnFrame(() => worklet);
48+
});
4449

4550
return () => {
4651
setRunOnFrame(null);
@@ -57,15 +62,6 @@ export const useOCR = ({ model, preventLoad = false }: OCRProps): OCRType => {
5762
preventLoad,
5863
]);
5964

60-
useEffect(() => {
61-
if (!isReady) {
62-
setRunOnFrame(null);
63-
return;
64-
}
65-
const worklet = controller.runOnFrame;
66-
if (worklet) setRunOnFrame(() => worklet);
67-
}, [controller, isReady]);
68-
6965
const forward = useCallback(
7066
(imageSource: string | PixelData): Promise<OCRDetection[]> =>
7167
controller.forward(imageSource),

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@ export const useVerticalOCR = ({
4040

4141
if (preventLoad) return;
4242

43-
controller.load(
44-
model.detectorSource,
45-
model.recognizerSource,
46-
model.language,
47-
independentCharacters,
48-
setDownloadProgress
49-
);
43+
controller
44+
.load(
45+
model.detectorSource,
46+
model.recognizerSource,
47+
model.language,
48+
independentCharacters,
49+
setDownloadProgress
50+
)
51+
.then(() => {
52+
const worklet = controller.runOnFrame;
53+
if (worklet) setRunOnFrame(() => worklet);
54+
});
5055

5156
return () => {
5257
setRunOnFrame(null);
@@ -64,15 +69,6 @@ export const useVerticalOCR = ({
6469
preventLoad,
6570
]);
6671

67-
useEffect(() => {
68-
if (!isReady) {
69-
setRunOnFrame(null);
70-
return;
71-
}
72-
const worklet = controller.runOnFrame;
73-
if (worklet) setRunOnFrame(() => worklet);
74-
}, [controller, isReady]);
75-
7672
const forward = useCallback(
7773
(imageSource: string | PixelData): Promise<OCRDetection[]> =>
7874
controller.forward(imageSource),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export interface ObjectDetectionType<L extends LabelEnum> {
139139
* Available after model is loaded (`isReady: true`).
140140
*
141141
* @param frame - VisionCamera Frame object
142+
* @param isFrontCamera - Whether the front camera is active, used for mirroring corrections.
142143
* @param detectionThreshold - The threshold for detection sensitivity.
143144
* @returns Array of Detection objects representing detected items in the frame.
144145
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export interface OCRType {
136136
* Available after model is loaded (`isReady: true`).
137137
*
138138
* @param frame - VisionCamera Frame object
139+
* @param isFrontCamera - Whether the front camera is active, used for mirroring corrections.
139140
* @returns Array of OCRDetection results for the frame.
140141
*/
141142
runOnFrame: ((frame: Frame, isFrontCamera: boolean) => OCRDetection[]) | null;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export interface SemanticSegmentationType<L extends LabelEnum> {
177177
* Available after model is loaded (`isReady: true`).
178178
*
179179
* @param frame - VisionCamera Frame object
180+
* @param isFrontCamera - Whether the front camera is active, used for mirroring corrections.
180181
* @param classesOfInterest - Labels for which to return per-class probability masks.
181182
* @param resizeToInput - Whether to resize masks to original frame dimensions. Defaults to `true`.
182183
* @returns Object with `ARGMAX` Int32Array and per-class Float32Array masks.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export interface StyleTransferType {
8686
* Available after model is loaded (`isReady: true`).
8787
*
8888
* @param frame - VisionCamera Frame object
89+
* @param isFrontCamera - Whether the front camera is active, used for mirroring corrections.
8990
* @returns PixelData containing the stylized frame as raw RGB pixel data.
9091
*/
9192
runOnFrame: ((frame: Frame, isFrontCamera: boolean) => PixelData) | null;

0 commit comments

Comments
 (0)