Skip to content

feat: add integration with vision camera v5#810

Merged
NorbertKlockiewicz merged 26 commits intomainfrom
@nk/vision-camera
Mar 2, 2026
Merged

feat: add integration with vision camera v5#810
NorbertKlockiewicz merged 26 commits intomainfrom
@nk/vision-camera

Conversation

@NorbertKlockiewicz
Copy link
Copy Markdown
Contributor

@NorbertKlockiewicz NorbertKlockiewicz commented Feb 16, 2026

Description

This PR adds real-time camera frame processing capabilities to React Native ExecuTorch by integrating with VisionCamera v5. It introduces a new VisionModule base class and extends ObjectDetectionModule to support three input methods: image URLs/paths, raw pixel data (PixelData), and live camera frames.

This PR includes:

  • a dedicated screen for testing object detection + vision camera
  • new tests for added methods

Introduces a breaking change?

  • Yes
  • No

Type of change

  • Bug fix (change which fixes an issue)
  • New feature (change which adds functionality)
  • Documentation update (improves or adds clarity to existing documentation)
  • Other (chores, tests, code style improvements etc.)

Tested on

  • iOS
  • Android

Testing instructions

Run the computer vision example app and test object detection and object detection (live)

Screenshots

Related issues

Checklist

  • 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

@NorbertKlockiewicz NorbertKlockiewicz changed the title @nk/vision camera feat: add integration with vision camera v5 Feb 18, 2026
@NorbertKlockiewicz NorbertKlockiewicz force-pushed the @nk/vision-camera branch 2 times, most recently from 96f2c14 to f3e17e2 Compare February 19, 2026 21:03
msluszniak

This comment was marked as resolved.

msluszniak

This comment was marked as resolved.

@NorbertKlockiewicz NorbertKlockiewicz changed the title feat: add integration with vision camera v5 feat!: add integration with vision camera v5 Feb 23, 2026
@NorbertKlockiewicz NorbertKlockiewicz changed the title feat!: add integration with vision camera v5 feat: add integration with vision camera v5 Feb 23, 2026
@NorbertKlockiewicz NorbertKlockiewicz marked this pull request as ready for review February 23, 2026 18:41
@NorbertKlockiewicz NorbertKlockiewicz self-assigned this Feb 23, 2026
@NorbertKlockiewicz NorbertKlockiewicz linked an issue Feb 23, 2026 that may be closed by this pull request
msluszniak

This comment was marked as resolved.

@msluszniak msluszniak added the feature PRs that implement a new feature label Feb 24, 2026
msluszniak

This comment was marked as resolved.

@NorbertKlockiewicz NorbertKlockiewicz force-pushed the @nk/vision-camera branch 3 times, most recently from c1ff490 to 983242e Compare February 25, 2026 13:09
Copy link
Copy Markdown
Member

@msluszniak msluszniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I would wait for a review from someone that knows TS more than me ;)

Comment on lines +61 to +64
/**
* Thrown when a feature or platform is not supported in the current environment.
*/
PlatformNotSupported = 119,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to add this to error handling docs

model,
preventLoad: preventLoad,
});
}) as ObjectDetectionType;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the type assertion here?

Comment thread packages/react-native-executorch/src/hooks/useModule.ts Outdated
Comment thread packages/react-native-executorch/src/hooks/useModule.ts Outdated
Comment thread packages/react-native-executorch/src/types/common.ts Outdated
@msluszniak
Copy link
Copy Markdown
Member

msluszniak commented Feb 26, 2026

I think you need to rebase because your changes to auto-generated api is as for the older code (before my commit with packages bump).

Comment thread packages/react-native-executorch/common/rnexecutorch/models/VisionModel.h Outdated
@NorbertKlockiewicz
Copy link
Copy Markdown
Contributor Author

The memory leak we've catched is caused by vision camera and hopefully will be fixed soon. The PR should be now ready to merge, just need an approve from @chmjkb

Copy link
Copy Markdown
Collaborator

@chmjkb chmjkb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, good job 👏🏻
make sure to add the issue we talked about today regarding weird orientation behavior cc @NorbertKlockiewicz

@NorbertKlockiewicz NorbertKlockiewicz merged commit 62ac55d into main Mar 2, 2026
6 checks passed
@NorbertKlockiewicz NorbertKlockiewicz deleted the @nk/vision-camera branch March 2, 2026 13:52
Comment on lines +16 to +27
cv::Mat extractFrame(jsi::Runtime &runtime, const jsi::Object &frameData) {
if (!hasNativeBuffer(runtime, frameData)) {
throw RnExecutorchError(RnExecutorchErrorCode::InvalidUserInput,
"FrameProcessor: No nativeBuffer found in frame");
}

auto nativeBufferValue = frameData.getProperty(runtime, "nativeBuffer");
uint64_t bufferPtr = static_cast<uint64_t>(
nativeBufferValue.asBigInt(runtime).asUint64(runtime));

return extractFromNativeBuffer(bufferPtr);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you releasing the NativeBuffer again via .release()?

I think it might make sense to either do this in JS via a helper worklet function (simpler), or in native C++ (where you'd have to carry the jsi::Function that does the release() along yourself).

See VisionCamera V5 docs: A Frame's NativeBuffer

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is what you observed as a memory leak.

NativeBuffer is a +1 retained buffer, you need to call release() on it. I do this in <SkiaCamera /> too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature PRs that implement a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vision Camera integration - initial API (Object Detection)

4 participants