Skip to content

Commit 45e40a6

Browse files
fix: fix bug in ocrs, remove node_modules from cv example app (#122)
## Description <!-- Provide a concise and descriptive summary of the changes implemented in this PR. --> ### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation update (improves or adds clarity to existing documentation) ### Tested on - [x] iOS - [x] Android ### Testing instructions <!-- Provide step-by-step instructions on how to test your changes. Include setup details if necessary. --> ### Screenshots <!-- Add screenshots here, if applicable --> ### Related issues <!-- Link related issues here using #issue-number --> ### Checklist - [x] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [ ] My changes generate no new warnings ### Additional notes <!-- Include any additional information, assumptions, or context that reviewers might need to understand this PR. -->
1 parent e01599f commit 45e40a6

File tree

12 files changed

+45
-166
lines changed

12 files changed

+45
-166
lines changed

android/src/main/java/com/swmansion/rnexecutorch/VerticalOCR.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class VerticalOCR(reactContext: ReactApplicationContext) :
155155

156156
resMap.putString("text", text)
157157
resMap.putArray("bbox", box.toWritableArray())
158-
resMap.putDouble("confidence", confidenceScore)
158+
resMap.putDouble("score", confidenceScore)
159159

160160
predictions.pushMap(resMap)
161161
}

android/src/main/java/com/swmansion/rnexecutorch/models/ocr/RecognitionHandler.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class RecognitionHandler(
104104

105105
resMap.putString("text", decodedTexts[0])
106106
resMap.putArray("bbox", box.toWritableArray())
107-
resMap.putDouble("confidence", confidenceScore)
107+
resMap.putDouble("score", confidenceScore)
108108

109109
res.pushMap(resMap)
110110
}

examples/computer-vision/node_modules/react-native-executorch/ios/RnExecutorch/models/ocr/VerticalDetector.h

-28
This file was deleted.

examples/computer-vision/node_modules/react-native-executorch/ios/RnExecutorch/models/ocr/VerticalDetector.mm

-118
This file was deleted.

examples/computer-vision/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"metro-config": "^0.81.0",
1717
"react": "18.3.1",
1818
"react-native": "0.76.3",
19+
"react-native-audio-api": "^0.4.13",
1920
"react-native-executorch": "^0.3.0",
2021
"react-native-image-picker": "^7.2.2",
2122
"react-native-loading-spinner-overlay": "^3.0.1",

examples/computer-vision/yarn.lock

+13
Original file line numberDiff line numberDiff line change
@@ -3889,6 +3889,7 @@ __metadata:
38893889
metro-config: ^0.81.0
38903890
react: 18.3.1
38913891
react-native: 0.76.3
3892+
react-native-audio-api: ^0.4.13
38923893
react-native-executorch: ^0.3.0
38933894
react-native-image-picker: ^7.2.2
38943895
react-native-loading-spinner-overlay: ^3.0.1
@@ -7486,6 +7487,18 @@ __metadata:
74867487
languageName: node
74877488
linkType: hard
74887489

7490+
"react-native-audio-api@npm:^0.4.13":
7491+
version: 0.4.13
7492+
resolution: "react-native-audio-api@npm:0.4.13"
7493+
peerDependencies:
7494+
react: "*"
7495+
react-native: "*"
7496+
bin:
7497+
setup-rn-audio-api-web: scripts/setup-rn-audio-api-web.js
7498+
checksum: 9a5db4626a0663224cdcdc957ed5176df9ed65df9f58bf06c5eae2a91895b7ee0f0a632ecaa79b23ef7536983485cea2720ca46201e2e690548f400b66970ff6
7499+
languageName: node
7500+
linkType: hard
7501+
74897502
"react-native-executorch@npm:^0.3.0":
74907503
version: 0.3.0
74917504
resolution: "react-native-executorch@npm:0.3.0"

examples/llama/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"metro-config": "^0.81.0",
1717
"react": "18.3.1",
1818
"react-native": "0.76.3",
19+
"react-native-audio-api": "^0.4.13",
1920
"react-native-executorch": "^0.3.0",
2021
"react-native-loading-spinner-overlay": "^3.0.1",
2122
"react-native-markdown-display": "^7.0.2",

examples/llama/yarn.lock

+13
Original file line numberDiff line numberDiff line change
@@ -6074,6 +6074,7 @@ __metadata:
60746074
metro-config: ^0.81.0
60756075
react: 18.3.1
60766076
react-native: 0.76.3
6077+
react-native-audio-api: ^0.4.13
60776078
react-native-executorch: ^0.3.0
60786079
react-native-loading-spinner-overlay: ^3.0.1
60796080
react-native-markdown-display: ^7.0.2
@@ -7555,6 +7556,18 @@ __metadata:
75557556
languageName: node
75567557
linkType: hard
75577558

7559+
"react-native-audio-api@npm:^0.4.13":
7560+
version: 0.4.13
7561+
resolution: "react-native-audio-api@npm:0.4.13"
7562+
peerDependencies:
7563+
react: "*"
7564+
react-native: "*"
7565+
bin:
7566+
setup-rn-audio-api-web: scripts/setup-rn-audio-api-web.js
7567+
checksum: 9a5db4626a0663224cdcdc957ed5176df9ed65df9f58bf06c5eae2a91895b7ee0f0a632ecaa79b23ef7536983485cea2720ca46201e2e690548f400b66970ff6
7568+
languageName: node
7569+
linkType: hard
7570+
75587571
"react-native-executorch@npm:^0.3.0":
75597572
version: 0.3.0
75607573
resolution: "react-native-executorch@npm:0.3.0"

ios/RnExecutorch/OCR.mm

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#import "OCR.h"
22
#import "models/ocr/Detector.h"
33
#import "models/ocr/RecognitionHandler.h"
4-
#import "utils/ImageProcessor.h"
54
#import "models/ocr/utils/Constants.h"
5+
#import "utils/ImageProcessor.h"
66
#import <ExecutorchLib/ETModel.h>
77
#import <React/RCTBridgeModule.h>
88

@@ -80,14 +80,11 @@ of different sizes (e.g. large - 512x64, medium - 256x64, small - 128x64).
8080
@try {
8181
cv::Mat image = [ImageProcessor readImage:input];
8282
NSArray *result = [detector runModel:image];
83-
cv::Size detectorSize = [detector getModelImageSize];
84-
const CGFloat recognizerRatio = recognizerImageSize / detectorSize.width;
8583
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
86-
result = [self->recognitionHandler
87-
recognize:result
88-
imgGray:image
89-
desiredWidth:detectorSize.width * recognizerRatio
90-
desiredHeight:detectorSize.height * recognizerRatio];
84+
result = [self->recognitionHandler recognize:result
85+
imgGray:image
86+
desiredWidth:recognizerImageSize
87+
desiredHeight:recognizerImageSize];
9188
resolve(result);
9289
} @catch (NSException *exception) {
9390
reject(@"forward_error",

ios/RnExecutorch/models/ocr/Detector.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ @implementation Detector {
2121
NSArray *inputShape = [module getInputShape:@0];
2222
NSNumber *widthNumber = inputShape[inputShape.count - 2];
2323
NSNumber *heightNumber = inputShape.lastObject;
24-
24+
2525
const int height = [heightNumber intValue];
2626
const int width = [widthNumber intValue];
2727
modelSize = cv::Size(height, width);

ios/RnExecutorch/models/ocr/Recognizer.mm

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ @implementation Recognizer {
1414

1515
- (cv::Size)getModelImageSize {
1616
NSArray *inputShape = [module getInputShape:@0];
17-
NSNumber *widthNumber = inputShape[inputShape.count - 2];
18-
NSNumber *heightNumber = inputShape.lastObject;
17+
NSNumber *widthNumber = inputShape.lastObject;
18+
NSNumber *heightNumber = inputShape[inputShape.count - 2];
1919

2020
const int height = [heightNumber intValue];
2121
const int width = [widthNumber intValue];
@@ -24,8 +24,8 @@ @implementation Recognizer {
2424

2525
- (cv::Size)getModelOutputSize {
2626
NSArray *outputShape = [module getOutputShape:@0];
27-
NSNumber *widthNumber = outputShape[outputShape.count - 2];
28-
NSNumber *heightNumber = outputShape.lastObject;
27+
NSNumber *widthNumber = outputShape.lastObject;
28+
NSNumber *heightNumber = outputShape[outputShape.count - 2];
2929

3030
const int height = [heightNumber intValue];
3131
const int width = [widthNumber intValue];

ios/RnExecutorch/models/ocr/utils/RecognizerUtils.mm

+5-5
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,17 @@ + (double)computeConfidenceScore:(NSArray<NSNumber *> *)valuesArray
251251

252252
points.emplace_back(cv::Point2f(point.x, point.y));
253253
}
254-
254+
255255
cv::Rect rect = cv::boundingRect(points);
256256
cv::Mat croppedImage = img(rect);
257+
cv::cvtColor(croppedImage, croppedImage, cv::COLOR_BGR2GRAY);
258+
cv::resize(croppedImage, croppedImage, cv::Size(smallVerticalRecognizerWidth, recognizerHeight), 0, 0,
259+
cv::INTER_AREA);
260+
cv::medianBlur(img, img, 1);
257261
return croppedImage;
258262
}
259263

260264
+ (cv::Mat)cropSingleCharacter:(cv::Mat)img {
261-
cv::cvtColor(img, img, cv::COLOR_BGR2GRAY);
262-
cv::resize(img, img, cv::Size(smallVerticalRecognizerWidth, recognizerHeight), 0, 0,
263-
cv::INTER_AREA);
264-
cv::medianBlur(img, img, 1);
265265

266266
cv::Mat histogram;
267267

0 commit comments

Comments
 (0)