Skip to content
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

scanFaces in worklet crashes app #27

Open
mxmzb opened this issue Jul 31, 2022 · 6 comments
Open

scanFaces in worklet crashes app #27

mxmzb opened this issue Jul 31, 2022 · 6 comments

Comments

@mxmzb
Copy link

mxmzb commented Jul 31, 2022

i'm getting this - any idea how to debug this best (or maybe it's a library bug)?

CleanShot 2022-07-31 at 17 28 13@2x

fresh app, these are my deps:

{
"dependencies": {
    "react": "18.2.0",
    "react-native": "0.69.3",
    "react-native-reanimated": "^2.9.1",
    "react-native-vision-camera": "^2.14.0",
    "vision-camera-face-detector": "^0.1.8",
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "babel-jest": "^28.1.3",
    "babel-plugin-module-resolver": "^4.1.0",
    "concurrently": "^7.3.0",
    "metro-react-native-babel-preset": "^0.72.0",
    "react-test-renderer": "18.2.0",
  }
}

my code:

import React from "react";
import { StyleSheet } from "react-native";
import { Camera, useCameraDevices, useFrameProcessor } from "react-native-vision-camera";
import { runOnJS } from "react-native-reanimated";

import { Ratio } from "@happycam/shared/atomic-components";

import { scanFaces, Face } from "vision-camera-face-detector";

const StreamCapture = React.memo(() => {
  const devices = useCameraDevices();
  const [cameraDevice, setCameraDevice] = React.useState("front");
  const [hasVideoPermission, setHasVideoPermissions] = React.useState(false);
  const [faces, setFaces] = React.useState<Face[]>();

  React.useEffect(() => {
    const requestCameraPermission = async () => {
      const cameraPermission = await Camera.getCameraPermissionStatus();

      if (cameraPermission !== "authorized") {
        const newCameraPermission = await Camera.requestCameraPermission();

        if (newCameraPermission === "authorized") {
          setHasVideoPermissions(true);
        }
      } else {
        setHasVideoPermissions(true);
      }
    };

    requestCameraPermission();
  }, []);

  const frameProcessor = useFrameProcessor(frame => {
    "worklet";

    const scannedFaces = scanFaces(frame);
    runOnJS(setFaces)(scannedFaces);
  }, []);

  const device = cameraDevice === "front" ? devices.front : devices.back;

  if (device !== null && hasVideoPermission) {
    return (
      <Ratio ratio={4 / 3}>
        <Camera
          style={StyleSheet.absoluteFill}
          device={device}
          isActive={true}
          video={true}
          audio={false}
          frameProcessor={frameProcessor}
          frameProcessorFps={5}
        />
      </Ratio>
    );
  }

  // TODO show message that there is no device
  return null;
});

export default StreamCapture;
@Rikirhenaldi
Copy link

@mxmzb Have you found a way to solve this problem ? I'm having the same issue.

@eloisasmorais
Copy link

eloisasmorais commented Aug 23, 2022

I was able to fix this by adding the following lines to babel.config.js

plugins: [
    [
      'react-native-reanimated/plugin',
      {
        globals: ['__scanFaces'],
      },
    ],
  ],

restart metro-bundler, if it doesn't work run yarn start --reset-cache

@mxmzb
Copy link
Author

mxmzb commented Sep 3, 2022

@Rikirhenaldi no, sorry

I was able to fix this by adding the following lines to babel.config.js

plugins: [
    [
      'react-native-reanimated/plugin',
      {
        globals: ['__scanFaces'],
      },
    ],
  ],

restart metro-bundler, if it doesn't work run yarn start --reset-cache

doesn't work for me

@adamdavareln
Copy link

@Rikirhenaldi no, sorry

I was able to fix this by adding the following lines to babel.config.js

plugins: [
    [
      'react-native-reanimated/plugin',
      {
        globals: ['__scanFaces'],
      },
    ],
  ],

restart metro-bundler, if it doesn't work run yarn start --reset-cache

doesn't work for me

same for me

@mat2718
Copy link

mat2718 commented Jan 5, 2023

can you try adding setFaces to the array in your frame processor and see if that works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@mxmzb @mat2718 @eloisasmorais @adamdavareln @Rikirhenaldi and others