Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/03-hooks/02-computer-vision/useClassification.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ You need more details? Check the following resources:

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/interfaces/ClassificationType.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The function returns a promise, which can resolve either to an error or an object containing categories with their probabilities.
To run the model, you can use the [`forward`](../../06-api-reference/interfaces/ClassificationType.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The function returns a promise, which can resolve either to an error or an object containing categories with their probabilities.

:::info
Images from external sources are stored in your application's temporary directory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ You need more details? Check the following resources:

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/interfaces/ImageEmbeddingsType.md#forward) method. It accepts one argument which is a URI/URL to an image you want to encode. The function returns a promise, which can resolve either to an error or an array of numbers representing the embedding.
To run the model, you can use the [`forward`](../../06-api-reference/interfaces/ImageEmbeddingsType.md#forward) method. It accepts one argument which is a URI/URL to an image you want to encode or base64 (whole URI or only raw base64). The function returns a promise, which can resolve either to an error or an array of numbers representing the embedding.

## Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You need more details? Check the following resources:

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/interfaces/ImageSegmentationType.md#forward) method. It accepts three arguments: a required image, an optional list of classes, and an optional flag whether to resize the output to the original dimensions.
To run the model, you can use the [`forward`](../../06-api-reference/interfaces/ImageSegmentationType.md#forward) method. It accepts three arguments: a required image - can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64), an optional list of classes, and an optional flag whether to resize the output to the original dimensions.

- The image can be a remote URL, a local file URI, or a base64-encoded image.
- The [`classesOfInterest`](../../06-api-reference/interfaces/ImageSegmentationType.md#classesofinterest) list contains classes for which to output the full results. By default the list is empty, and only the most probable classes are returned (essentially an arg max for each pixel). Look at [`DeeplabLabel`](../../06-api-reference/enumerations/DeeplabLabel.md) enum for possible classes.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/03-hooks/02-computer-vision/useOCR.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ You need more details? Check the following resources:

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/interfaces/OCRType.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The function returns an array of [`OCRDetection`](../../06-api-reference/interfaces/OCRDetection.md) objects. Each object contains coordinates of the bounding box, the text recognized within the box, and the confidence score. For more information, please refer to the reference or type definitions.
To run the model, you can use the [`forward`](../../06-api-reference/interfaces/OCRType.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The function returns an array of [`OCRDetection`](../../06-api-reference/interfaces/OCRDetection.md) objects. Each object contains coordinates of the bounding box, the text recognized within the box, and the confidence score. For more information, please refer to the reference or type definitions.

## Detection object

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ You need more details? Check the following resources:

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/interfaces/ObjectDetectionType.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The function returns an array of [`Detection`](../../06-api-reference/interfaces/Detection.md) objects. Each object contains coordinates of the bounding box, the label of the detected object, and the confidence score. For more information, please refer to the reference or type definitions.
To run the model, you can use the [`forward`](../../06-api-reference/interfaces/ObjectDetectionType.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The function returns an array of [`Detection`](../../06-api-reference/interfaces/Detection.md) objects. Each object contains coordinates of the bounding box, the label of the detected object, and the confidence score. For more information, please refer to the reference or type definitions.

## Detection object

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/03-hooks/02-computer-vision/useStyleTransfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You need more details? Check the following resources:

## Running the model

To run the model, you can use [`forward`](../../06-api-reference/interfaces/StyleTransferType.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The function returns a promise which can resolve either to an error or a URL to generated image.
To run the model, you can use [`forward`](../../06-api-reference/interfaces/StyleTransferType.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The function returns a promise which can resolve either to an error or a URL to generated image.

:::info
Images from external sources and the generated image are stored in your application's temporary directory.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/03-hooks/02-computer-vision/useVerticalOCR.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ You need more details? Check the following resources:

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/interfaces/OCRType.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The function returns an array of [`OCRDetection`](../../06-api-reference/interfaces/OCRDetection.md) objects. Each object contains coordinates of the bounding box, the text recognized within the box, and the confidence score. For more information, please refer to the reference or type definitions.
To run the model, you can use the [`forward`](../../06-api-reference/interfaces/OCRType.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The function returns an array of [`OCRDetection`](../../06-api-reference/interfaces/OCRDetection.md) objects. Each object contains coordinates of the bounding box, the text recognized within the box, and the confidence score. For more information, please refer to the reference or type definitions.

## Detection object

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ For more information on loading resources, take a look at [loading models](../..

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/classes/ClassificationModule.md#forward) method on the module object. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The method returns a promise, which can resolve either to an error or an object containing categories with their probabilities.
To run the model, you can use the [`forward`](../../06-api-reference/classes/ClassificationModule.md#forward) method on the module object. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The method returns a promise, which can resolve either to an error or an object containing categories with their probabilities.

## Managing memory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ For more information on loading resources, take a look at [loading models](../..

## Running the model

[`forward`](../../06-api-reference/classes/ImageEmbeddingsModule.md#forward) accepts one argument, which is a URI/URL to an image you want to encode. The function returns a promise, which can resolve either to an error or an array of numbers representing the embedding.
[`forward`](../../06-api-reference/classes/ImageEmbeddingsModule.md#forward) accepts one argument: image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The function returns a promise, which can resolve either to an error or an array of numbers representing the embedding.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ For more information on loading resources, take a look at [loading models](../..

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/classes/ImageSegmentationModule.md#forward) method on the module object. It accepts three arguments: a required image, an optional list of classes, and an optional flag whether to resize the output to the original dimensions.
To run the model, you can use the [`forward`](../../06-api-reference/classes/ImageSegmentationModule.md#forward) method on the module object. It accepts three arguments: a required image - can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64), an optional list of classes, and an optional flag whether to resize the output to the original dimensions.

- The image can be a remote URL, a local file URI, or a base64-encoded image.
- The [`classesOfInterest`](../../06-api-reference/classes/ImageSegmentationModule.md#classesofinterest) list contains classes for which to output the full results. By default the list is empty, and only the most probable classes are returned (essentially an arg max for each pixel). Look at [`DeeplabLabel`](../../06-api-reference/enumerations/DeeplabLabel.md) enum for possible classes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ For more information on loading resources, take a look at [loading models](../..

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/classes/OCRModule.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The method returns a promise, which can resolve either to an error or an array of [`OCRDetection`](../../06-api-reference/interfaces/OCRDetection.md) objects. Each object contains coordinates of the bounding box, the label of the detected object, and the confidence score.
To run the model, you can use the [`forward`](../../06-api-reference/classes/OCRModule.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The method returns a promise, which can resolve either to an error or an array of [`OCRDetection`](../../06-api-reference/interfaces/OCRDetection.md) objects. Each object contains coordinates of the bounding box, the label of the detected object, and the confidence score.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ For more information on loading resources, take a look at [loading models](../..

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/classes/ObjectDetectionModule.md#forward) method on the module object. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The method returns a promise, which can resolve either to an error or an array of [`Detection`](../../06-api-reference/interfaces/Detection.md) objects. Each object contains coordinates of the bounding box, the label of the detected object, and the confidence score.
To run the model, you can use the [`forward`](../../06-api-reference/classes/ObjectDetectionModule.md#forward) method on the module object. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The method returns a promise, which can resolve either to an error or an array of [`Detection`](../../06-api-reference/interfaces/Detection.md) objects. Each object contains coordinates of the bounding box, the label of the detected object, and the confidence score.

## Managing memory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ For more information on loading resources, take a look at [loading models](../..

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/classes/StyleTransferModule.md#forward) method on the module object. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The method returns a promise, which can resolve either to an error or a URL to generated image.
To run the model, you can use the [`forward`](../../06-api-reference/classes/StyleTransferModule.md#forward) method on the module object. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The method returns a promise, which can resolve either to an error or a URL to generated image.

## Managing memory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ For more information on loading resources, take a look at [loading models](../..

## Running the model

To run the model, you can use the [`forward`](../../06-api-reference/classes/VerticalOCRModule.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The method returns a promise, which can resolve either to an error or an array of [`OCRDetection`](../../06-api-reference/interfaces/OCRDetection.md) objects. Each object contains coordinates of the bounding box, the label of the detected object, and the confidence score.
To run the model, you can use the [`forward`](../../06-api-reference/classes/VerticalOCRModule.md#forward) method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image (whole URI or only raw base64). The method returns a promise, which can resolve either to an error or an array of [`OCRDetection`](../../06-api-reference/interfaces/OCRDetection.md) objects. Each object contains coordinates of the bounding box, the label of the detected object, and the confidence score.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ cv::Mat readImage(const std::string &imageURI) {
while (std::getline(uriStream, stringData, ',')) {
++segmentIndex;
}
if (segmentIndex != 1) {
if (segmentIndex != 2) {
throw RnExecutorchError(RnExecutorchErrorCode::FileReadFailed,
"Read image error: invalid base64 URI");
}
Expand All @@ -104,8 +104,10 @@ cv::Mat readImage(const std::string &imageURI) {
cv::Mat(1, imageData.size(), CV_8UC1, (void *)imageData.data()),
cv::IMREAD_COLOR);
} else {
throw RnExecutorchError(RnExecutorchErrorCode::FileReadFailed,
"Read image error: unknown protocol");
// fallback to raw base64 content
auto data = base64_decode(imageURI);
cv::Mat encodedData(1, data.size(), CV_8UC1, (void *)data.data());
image = cv::imdecode(encodedData, cv::IMREAD_COLOR);
}

if (image.empty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ endfunction()

add_rn_test(NumericalTests unit/NumericalTest.cpp)
add_rn_test(LogTests unit/LogTest.cpp)
add_rn_test(FileUtilsTest unit/FileUtilsTest.cpp)
add_rn_test(ImageProcessingTest unit/ImageProcessingTest.cpp
SOURCES
${IMAGE_UTILS_SOURCES}
LIBS opencv_deps
)

add_rn_test(BaseModelTests integration/BaseModelTest.cpp)

add_rn_test(ClassificationTests integration/ClassificationTest.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ MODELS_DIR="$SCRIPT_DIR/integration/assets/models"
TEST_EXECUTABLES=(
"NumericalTests"
"LogTests"
"FileUtilsTest"
"ImageProcessingTest"
"BaseModelTests"
"ClassificationTests"
"ObjectDetectionTests"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "../data_processing/ImageProcessing.h"
#include <gtest/gtest.h>
#include <opencv2/opencv.hpp>
#include <string>

#include <rnexecutorch/Error.h>
#include <rnexecutorch/ErrorCodes.h>

const std::string RAW_BASE64_JPEG =
"/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP////////////////////////////////////////"
"//////////////////////////////////////////////2wBDAf//////////////////////"
"////////////////////////////////////////////////////////////////"
"wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAj/"
"xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAQAAAAAAAAAAAAAAAAAAAAH/"
"xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwC/gAf/2Q==";

namespace rnexecutorch::image_processing {
TEST(ReadImageTest, WorksWithWholeUriBase64) {
std::string dataUri = "data:image/jpeg;base64," + RAW_BASE64_JPEG;

cv::Mat image;
ASSERT_NO_THROW({ image = readImage(dataUri); });

EXPECT_FALSE(image.empty());
EXPECT_EQ(image.rows, 1);
EXPECT_EQ(image.cols, 1);
}

TEST(ReadImageTest, WorksWithRawBase64Content) {
cv::Mat image;
ASSERT_NO_THROW({ image = readImage(RAW_BASE64_JPEG); });

EXPECT_FALSE(image.empty());
EXPECT_EQ(image.rows, 1);
EXPECT_EQ(image.cols, 1);
}

TEST(ReadImageTest, FailsForInvalidBase64UriFormat) {
std::string invalidUri =
"data:image/jpeg;base64,extra,comma," + RAW_BASE64_JPEG;

EXPECT_THROW({ readImage(invalidUri); }, RnExecutorchError);

try {
readImage(invalidUri);
} catch (const RnExecutorchError &e) {
EXPECT_EQ(e.getNumericCode(),
static_cast<int32_t>(RnExecutorchErrorCode::FileReadFailed));
}
}

TEST(ReadImageTest, FailsForInvalidBase64Data) {
std::string badDataUri = "data:image/jpeg;base64,NOT_A_VALID_IMAGE_DATA";

EXPECT_THROW({ readImage(badDataUri); }, RnExecutorchError);

try {
readImage(badDataUri);
} catch (const RnExecutorchError &e) {
EXPECT_STREQ(e.what(), "Read image error: invalid argument");
}
}
} // namespace rnexecutorch::image_processing