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)
- π Fatal Error on App Initialization: IllegalArgumentException - width must be positive in CameraDeviceDetails.getFormats HOT 5
- π Unable to scan code-39 barcode. HOT 2
- π V3 is not reading Data-Matrix codes with black background on Android. HOT 4
- π [4.5.3] Google Api Error: Invalid request - Your app declares support for 'riscv64' architecture, but the following libraries are missing HOT 21
- π Can't find VisionCamera.xcodeproj as Readme HOT 3
- π InitializationException - Device reporting less cameras than anticipated HOT 7
- π Fatal Error on App Initialization: IllegalArgumentException - width must be positive in CameraDeviceDetails.getFormats HOT 1
- π§ v4.5.3 fails to build on Android - jetified-camera-core-1.5.0-alpha01/jni/riscv64/libimage_processing_util_jni.so is not an ABI HOT 12
- π TakePhoto() doesn't work with Android Emulator (Pixel 4 API 28, Pixel 4 API 31, Pixel 8 API 31) HOT 1
- β¨ Able to use this library detect QR code from the image HOT 3
- π Issue launching camera on iOS HOT 1
- π§ Unable to find a specification for `react-native-worklets-core` depended upon by `VisionCamera/FrameProcessors` HOT 3
- π Audio is not working ^4.5.3 (IOS) HOT 2
- π§ could not build Objective-C module 'vision_camera_code_scanner' HOT 2
- π Production Build Error with 4.5.3 HOT 3
- π§ Production Build Error with 4.5.3 HOT 5
- β¨ Document Scanner HOT 3
- π error when trying to upload the app to Play Store v4.5.2 and v4.5.3 HOT 3
- π V3 Π½Π΅ ΡΡΠΈΡΡΠ²Π°Π΅Ρ ΠΊΠΎΠ΄Ρ Data-Matrix Ρ ΡΠ΅ΡΠ½ΡΠΌ ΡΠΎΠ½ΠΎΠΌ Π½Π° Android HOT 1
- π react-native-vision-camera | App crashing after setting FPS and applying frameProcessor to Camera HOT 4
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.