Skip to content

Commit d2a65b8

Browse files
committed
feat: add OCR scaffolding
1 parent 0a0f456 commit d2a65b8

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

packages/react-native-executorch/common/rnexecutorch/models/ocr/Detector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace rnexecutorch {
1010
using executorch::aten::Tensor;
1111
using executorch::extension::TensorPtr;
1212

13-
class Detector : BaseModel {
13+
class Detector : public BaseModel {
1414
public:
1515
Detector(const std::string &modelSource,
1616
std::shared_ptr<react::CallInvoker> callInvoker);
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
11
#include "OCR.h"
22

3-
namespace rnexecutorch {} // namespace rnexecutorch
3+
#include <rnexecutorch/models/ocr/Constants.h>
4+
5+
namespace rnexecutorch {
6+
OCR::OCR(std::string detectorSource, std::string recognizerSourceLarge,
7+
std::string recognizerSourceMedium, std::string recognizerSourceSmall,
8+
std::string symbols, std::shared_ptr<react::CallInvoker> callInvoker)
9+
: detector(detectorSource, callInvoker),
10+
recognitionHandler(symbols, recognizerSourceLarge, recognizerSourceMedium,
11+
recognizerSourceSmall, callInvoker) {}
12+
13+
std::vector<OCRDetection> OCR::forward(std::string input) {
14+
std::vector<DetectorBBox> detectorResult = detector.forward(input);
15+
cv::Mat grayscaleImg = imageprocessing::readImage(input);
16+
cv::cvtColor(grayscaleImg, grayscaleImg, cv::COLOR_BGR2GRAY);
17+
std::vector<OCRDetection> result = recognitionHandler.recognize(
18+
detectorResult, grayscaleImg, recognizerImageSize, recognizerImageSize);
19+
return result;
20+
}
21+
22+
void OCR::unloadModule() {
23+
detector.unload();
24+
recognitionHandler.unload();
25+
}
26+
27+
std::size_t OCR::getMemoryLowerBound() {
28+
return detector.getMemoryLowerBound() +
29+
recognitionHandler.getMemoryLowerBound();
30+
}
31+
} // namespace rnexecutorch

0 commit comments

Comments
 (0)