-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Camera Screen goes black when using Skia Frame Processors with VisionCamera (doesn't happen with normal frame processors) #2897
Comments
Same issue here.
-> in component: This will show black screen on some devices. I think it's linked to devices who are using Vulkan and Angle for OpenGL support, including a lot of samsung devices as wcandillon stated. @DragonDare are you on a samsung device/emulator? Also I think this issue should be addressed in react-native-vision-camera |
yes I would definitely recommend to try on 1.7.7 and above. |
Im using a Motorola Edge 40 physical device. Also I did mention this issue in vision camera github, no comments so far. Could you bump up the issue there? Will get some recognition. |
Tried with skia version 1.7.7 right now, same problem. |
@wcandillon any updates on this issue? If possible, could we atleast debug if this is a vision camera issue or a skia issue? Thanks |
@DragonDare Yes I think it would be interesting to have proper support for VisionCamera, would you be ok to add a small example of Skia/Vision Camera to the example app: https://github.com/Shopify/react-native-skia/tree/main/apps/paper @mrousavy Is that something you monitor on your side as well? Maybe we need to do some touch up on the integration part. |
@wcandillon I did try the example repo https://github.com/mrousavy/VisionCameraSkiaDemo, which uses Skia Frame processors and it did give me a black screen (Yes i removed the black paint in the code) |
Yea I added Skia as a dependency - but I don't update it everytime a new version gets released. It definitely helps to also add VisionCamera to the Skia example app to test this integration better! |
Originally posted by @DragonDare in #3365 |
lol ok no worries happens to the best of us 😂 |
Did you try on a samsung s8 / s22+ / s24 ? Got a list of 400+ crash events on a few particular samsung devices with simply:
|
I expect it to work on these models (s8 / s22+ / s24 ) with the latest
RN Skia version, if not we can definitely take a look.
…On Thu, Jan 23, 2025 at 12:22 PM maxximee ***@***.***> wrote:
Guys @mrousavy @wcandillon @maxximee
I just realised I didn't add the "frame.render()" in my skia frame processor. This fixed the issue. The Camera is visible now.
const frameProcessor = useSkiaFrameProcessor((frame) => {
'worklet';
frame.render();
I don't know why I'm just coming across this. https://react-native-vision-camera.com/docs/guides/skia-frame-processors.
Completely missed this when doing my initial research.
Originally posted by @DragonDare in #3365
Did you try on a samsung s8 / s22+ / s24 ?
—
Reply to this email directly, view it on GitHub or unsubscribe.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
Got hands on a samsung s8 and it's clearly still crashing with "@shopify/react-native-skia": "^1.10.2": 2025-01-24 11:26:31.530 19443-19793 ReactNativeJS com.klim.klimfilmscanner E Frame Processor Error: Exception in HostFunction: Failed to convert NativeBuffer to SkImage!, js engine: VisionCamera And on other specific devices, for example pixel 9 with api 35 it shows a black screen:
If anyone can give it a try and give me a feedback that would be great. I'd happy to be told I made a mistake somewhere... |
that's interesting, the NativeBuffer API is tested on samsung s8 but I
will give it another look just to be sure.
Then it might be related to the way it operate with vision-camera
maybe, let's see. this is where having an example of using
vision-camera on the skia example app would be useful for testing.
…On Fri, Jan 24, 2025 at 5:30 AM maxximee ***@***.***> wrote:
I expect it to work on these models (s8 / s22+ / s24 ) with the latest
RN Skia version, if not we can definitely take a look.
…
Got hands on a samsung s8 and it's clearly still crashing with ***@***.***/react-native-skia": "^1.10.2":
Screenshot_20250124-112705_Film_Scanner.1.jpg (view on web)
2025-01-24 11:26:31.530 19443-19793 ReactNativeJS com.klim.klimfilmscanner E Frame Processor Error: Exception in HostFunction: Failed to convert NativeBuffer to SkImage!, js engine: VisionCamera
2025-01-24 11:26:31.547 19443-19792 skia com.klim.klimfilmscanner D Could not create EGL image, err = (0x3003)
2025-01-24 11:26:31.547 19443-19792 RNSkia com.klim.klimfilmscanner I Failed to convert HardwareBuffer to OpenGL Texture!
—
Reply to this email directly, view it on GitHub or unsubscribe.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
Description
I'm trying to implement pose detection by drawing stick-figure of the pose on my app. But with Skia Frame processor, the camera screen goes black with only the stick figure being visible. However, if i use a normal frame processor, the camera is visible and not black.
Packages:
"react-native-fast-tflite": "^1.5.1",
"@shopify/react-native-skia": "1.5.0",
"react-native-worklets-core": "^1.5.0",
"vision-camera-resize-plugin": "^3.2.0"
"react-native-vision-camera": "^4.6.3"
React Native Skia Version
1.5.0
React Native Version
0.76.6
Using New Architecture
Steps to Reproduce
Snack, Code Example, Screenshot, or Link to Repository
Here is my camera screen code which is creating the problem.
import TopAppBar from '@/components/TopAppBar';
import { SlamdunkTheme } from '@/constants/Theme';
import { scaleHeight, scaleWidth } from '@/utils/scaling';
import React, { useEffect, useMemo } from 'react';
import { StyleSheet, View, Text, Platform } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { Camera, useCameraDevice, useCameraPermission, useSkiaFrameProcessor } from 'react-native-vision-camera';
import { useResizePlugin } from 'vision-camera-resize-plugin';
import { TensorflowModel, useTensorflowModel } from 'react-native-fast-tflite';
import { PaintStyle, Skia } from '@shopify/react-native-skia';
import getBestFormat from './formatFilter';
function tensorToString(tensor: TensorflowModel['inputs'][number]): string {
return
${tensor.dataType} [${tensor.shape}]
;}
const LINE_WIDTH = 1;
const MIN_CONFIDENCE = 0.2;
const VIEW_WIDTH = scaleWidth(375);
const CameraScreen = () => {
const device = useCameraDevice('back');
const { hasPermission, requestPermission } = useCameraPermission();
useEffect(() => {
if (!hasPermission) {
requestPermission().catch((err) => {
console.error('Camera permission request failed:', err);
});
}
}, [hasPermission, requestPermission]);
if (!device) {
return Loading camera...;
}
const { resize } = useResizePlugin();
const delegate = Platform.OS === 'ios' ? 'core-ml' : undefined;
const plugin = useTensorflowModel(
require('../assets/models/singlepose-lightning-tflite-float16.tflite'),
delegate,
);
const format = useMemo(
() => (device != null ? getBestFormat(device, 720, 1000) : undefined),
[device],
);
console.log(format?.videoWidth, format?.videoHeight);
const pixelFormat = Platform.OS === 'ios' ? 'rgb' : 'yuv';
useEffect(() => {
const model = plugin.model;
if (model == null) {
return;
}
console.log(
Model: ${model.inputs.map(tensorToString)} -> ${model.outputs.map( tensorToString, )}
,);
}, [plugin]);
const inputTensor = plugin.model?.inputs[0];
const inputWidth = inputTensor?.shape[1] ?? 0;
const inputHeight = inputTensor?.shape[2] ?? 0;
if (inputTensor != null) {
console.log(
Input: ${inputTensor.dataType} ${inputWidth} x ${inputHeight}
,);
}
// to get from px -> dp since we draw in the camera coordinate system
const SCALE = (format?.videoWidth ?? VIEW_WIDTH) / VIEW_WIDTH;
const paint = Skia.Paint();
paint.setStyle(PaintStyle.Fill);
paint.setStrokeWidth(LINE_WIDTH * SCALE);
paint.setColor(Skia.Color('yellow'));
const lines = [
// left shoulder -> elbow
5, 7,
// right shoulder -> elbow
6, 8,
// left elbow -> wrist
7, 9,
// right elbow -> wrist
8, 10,
// left hip -> knee
11, 13,
// right hip -> knee
12, 14,
// left knee -> ankle
13, 15,
// right knee -> ankle
14, 16,
];
const rotation = Platform.OS === 'ios' ? '0deg' : '90deg'; // hack to get android oriented properly
const frameProcessor = useSkiaFrameProcessor(
frame => {
'worklet';
);
return (
Make sure your body is positioned correctly
{hasPermission && (
)}
{/*
*/}
);
};
export default CameraScreen;
const styles = StyleSheet.create({
overlay: {
...StyleSheet.absoluteFillObject,
top: scaleHeight(161),
alignItems: 'center',
},
textBox: {
width: scaleWidth(290),
alignSelf: 'center',
},
camera: {
height: scaleHeight(638),
},
instructionText: {
fontFamily: SlamdunkTheme.fonts.poppinsRegular,
fontSize: 22,
fontWeight: 400,
lineHeight: 33,
color: SlamdunkTheme.colors.backgroundColor,
textAlign: 'center',
},
dottedBox: {
width: scaleWidth(319),
height: scaleHeight(514),
borderWidth: 2,
borderColor: SlamdunkTheme.colors.backgroundVariant3,
borderStyle: 'dashed',
backgroundColor: SlamdunkTheme.colors.backgroundVariant3,
borderRadius: 8,
},
});
The text was updated successfully, but these errors were encountered: