Skip to content

Commit 211757d

Browse files
authored
feat: port object detection to C++ (#361)
## Description Port object detection native code to C++ ### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] 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 ### Related issues #260 #255 ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings
1 parent e8b05c1 commit 211757d

30 files changed

Lines changed: 229 additions & 597 deletions

File tree

packages/react-native-executorch/android/src/main/java/com/swmansion/rnexecutorch/ObjectDetection.kt

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

packages/react-native-executorch/android/src/main/java/com/swmansion/rnexecutorch/RnExecutorchPackage.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class RnExecutorchPackage : TurboReactPackage() {
1818
LLM(reactContext)
1919
} else if (name == ETModule.NAME) {
2020
ETModule(reactContext)
21-
} else if (name == ObjectDetection.NAME) {
22-
ObjectDetection(reactContext)
2321
} else if (name == SpeechToText.NAME) {
2422
SpeechToText(reactContext)
2523
} else if (name == OCR.NAME) {
@@ -60,17 +58,6 @@ class RnExecutorchPackage : TurboReactPackage() {
6058
true,
6159
)
6260

63-
moduleInfos[ObjectDetection.NAME] =
64-
ReactModuleInfo(
65-
ObjectDetection.NAME,
66-
ObjectDetection.NAME,
67-
false, // canOverrideExistingModule
68-
false, // needsEagerInit
69-
true, // hasConstants
70-
false, // isCxxModule
71-
true,
72-
)
73-
7461
moduleInfos[SpeechToText.NAME] =
7562
ReactModuleInfo(
7663
SpeechToText.NAME,

packages/react-native-executorch/android/src/main/java/com/swmansion/rnexecutorch/models/objectDetection/SSDLiteLargeModel.kt

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

packages/react-native-executorch/android/src/main/java/com/swmansion/rnexecutorch/utils/ObjectDetectionUtils.kt

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

packages/react-native-executorch/common/rnexecutorch/RnExecutorchInstaller.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <rnexecutorch/host_objects/JsiConversions.h>
44
#include <rnexecutorch/models/classification/Classification.h>
55
#include <rnexecutorch/models/image_segmentation/ImageSegmentation.h>
6+
#include <rnexecutorch/models/object_detection/ObjectDetection.h>
67
#include <rnexecutorch/models/style_transfer/StyleTransfer.h>
78

89
namespace rnexecutorch {
@@ -31,5 +32,10 @@ void RnExecutorchInstaller::injectJSIBindings(
3132
*jsiRuntime, "loadClassification",
3233
RnExecutorchInstaller::loadModel<Classification>(
3334
jsiRuntime, jsCallInvoker, "loadClassification"));
35+
36+
jsiRuntime->global().setProperty(
37+
*jsiRuntime, "loadObjectDetection",
38+
RnExecutorchInstaller::loadModel<ObjectDetection>(
39+
jsiRuntime, jsCallInvoker, "loadObjectDetection"));
3440
}
3541
} // namespace rnexecutorch

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ cv::Mat readImage(const std::string &imageURI) {
111111
throw std::runtime_error("Read image error: invalid argument");
112112
}
113113

114+
cv::cvtColor(image, image, cv::COLOR_BGR2RGB);
114115
return image;
115116
}
116117

0 commit comments

Comments
 (0)