Comments (7)
why not just
const frameProcessor = useFrameProcessor((frame) => {
'worklet'
runAtTargetFps(15, () => {
lowHzFrameProcessor(frame)
})
// optional; either `runAsync`, or just call directly. whatever works for you
runAsync(frame, () => {
'worklet'
highHzFrameProcessor(frame)
})
})
?
from react-native-vision-camera.
// I've been closing it in this plugin because it's // the plugin that always runs and for the most part // it seems to work fine image.close()
Why? Why are you closing the Frame? The documentation tells you that you should not close the Frame, VisionCamera handles that for you.
from react-native-vision-camera.
Again, you should not close the Frame.
That's why there's no documentation - you should not close it.
It is closed automatically when all runAsync and frameProcessor calls have completed.
If you intend to keep it longer than a runAsync call (eg when it goes out of scope in your native plugin) call incrementRefCount() first, and then decrementRefCount() after you're done.
from react-native-vision-camera.
🤦 Thanks! I think a combination of working late on a Sunday + brainfart made me not realize I could do that. I think I just misunderstood how the runAtTargetFps function worked. Appreciate the answer!
from react-native-vision-camera.
haha no worries - glad it helped!
from react-native-vision-camera.
Sorry to bring this up again, but I'm still occasionally running into issues where the image is closed too early. Here's my current implementation:
// what I'm doing in RN
const frameProcessor = useFrameProcessor((frame: Frame) => {
'worklet'
runAtTargetFps(5, () => {
runAsync(frame, () => {
'worklet'
runSlowPlugin(frame);
});
});
runFastPlugin(frame);
});
// my native plugins
// slow plugin implementation
override fun callback(frame: Frame, params: MutableMap<String, Any>?): Boolean {
val image = frame.image ?: return false
// should be nearly instant as I'm just moving data around
// However, I think it may be sometimes slower than the
// fast plugin which is why I think there is the
// "image is already closed" issue
val buffers = extractBuffers(image)
runVeryLongProcess(image)
return false
}
// fast plugin implementation
override fun callback(frame: Frame, params: MutableMap<String, Any>?): Double {
val image = frame.image ?: return 0.0
// do some processing
val value = // ...
// I've been closing it in this plugin because it's
// the plugin that always runs and for the most part
// it seems to work fine
image.close()
return val
}
I've seen the information about writing an asynchronous frame copy, but I'm not sure how to do it in kotlin. The documentation seems to indicate that I can do something like:
val frameCopy = Frame(
frame.image,
frame.timestamp,
frame.orientation,
frame.isMirrored
)
runVeryLongProcess(frameCopy.image)
But I'm still occasionally getting the "image is closed" issue. A temporary fix I had was to add a parameter to the fast plugin to prevent it from closing the image and then always closing it in the slow plugin. However, if the slow one happened to run very quickly then it would throw the error, and I had to keep track of the frame count to determine if I should try running the 5 fps frame plugin.
Is there any documentation on how to copy the image in kotlin without it being closed? Alternatively, is there a way to detect if the image is already closed and just return early instead of trying to continue the plugins? If I don't ever explicitly close the image will I have memory leaks or is Android smart enough to garbage collect it?
Feel free to close this again. I didn't want to open a new issue without the context but I understand it's a little disorganized if threads keep reopening.
from react-native-vision-camera.
Oh, okay. Thanks. I couldn't find documentation about closing the frame on the RNVC website, do you know which section it's in? I tried searching for "close" on the website and also in the /docs
directory of the repo and couldn't find it mentioned. I found a mention in a comment in src/Frame.ts
in #229 but it looks like it was removed in #1472:
/**
* Closes and disposes the Frame.
* Only close frames that you have created yourself, e.g. by copying the frame you receive in a frame processor.
*
* @example
* ```ts
* const frameProcessor = useFrameProcessor((frame) => {
* const smallerCopy = resize(frame, 480, 270)
* // run AI ...
* smallerCopy.close()
* // don't close `frame`!
* })
* ```
*/
close(): void;
}
If you get a chance could you take a look and see if it's still in the documentation? Definitely not a priority but if you can't find it either I could make a PR adding it to "Creating Frame Processor Plugins (Android)" section of the docs website, just let me know!
Thanks again. Your super quick responses make working with RNVC one of the best experiences I've had in the couple years I've been working in mobile development.
from react-native-vision-camera.
Related Issues (20)
- 💭 Get "Missing purpose string" Apple violation when VCEnableLocation is false HOT 3
- 💭 onIitialized only work when the isActive once. HOT 2
- 🐛 onOutputOrientationChanged outputs wrong value on tablets HOT 6
- ✨ Hello author, can you add a cropping function after taking the photo? HOT 3
- 🐛 system/camera-is-restricted Camera functionality is not available because it has been restricted by the operating system, possibly due to a device policy. HOT 4
- 💭 Question: Implementing Virtual Background and AR Try-On Glasses with Frame Processing HOT 2
- 💭 CodeScanner does not recognize Data Matrix code on a black background HOT 2
- 🐛 photo.orientation is wrong when outputOrientation = preview on Android HOT 1
- 🐛 OutputOrientation: "Duplicate label in when" HOT 1
- 💭 Add filter to photo when photo is taken HOT 2
- 💭 Obtaining camera calibration data HOT 4
- 🐛 Crash in Android release build HOT 3
- 🐛 Failed to convert NativeBuffer to SkImage HOT 2
- 🔧 RCT_NEW_ARCH_ENABLED=1 failed pod install HOT 2
- 🐛 Cannot debug via Google Chrome if using Android Native method marked as synchronous HOT 2
- 🐛 Crash in iOS release build when using SkiaFrameProcessor HOT 2
- 🐛 Cached apps freezer is freezing app on Google Pixel with Android 14 HOT 1
- 🐛 App Crashes when try to implement camera inside modal. HOT 1
- 💭 iOS photo quality vs native camera HOT 1
- 🐛 RN 0.74, RNVC 4.3.2. Take a photo or snapshot on iOS, the file does not exist at the path indicated by the response HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-vision-camera.