如何使用react-native-vision-camera的帧处理器来检测人脸?

huangapple go评论81阅读模式
英文:

How to use react-native-vision-camera Frame Processor to detect human face?

问题

Here is the translated code portion:

如何使用react-native-vision-camera的Frame Processor来检测人脸我尝试使用一个名为vision-camera-face-detector的包但在尝试创建我的React Native CLI应用APK时失败了是否有其他方法可以使用react-native-vision-camera的Frame Processor来检测人脸

export default function App() {
  const [cameraPermission, setCameraPermission] = useState();

  useEffect(() => {
    (async () => {
      const cameraPermissionStatus = await Camera.requestCameraPermission();
      setCameraPermission(cameraPermissionStatus);
    })();
  }, []);

  console.log(`摄像头权限状态:${cameraPermission}`);

  const devices = useCameraDevices();
  const cameraDevice = devices.back;

  const renderDetectorContent = () => {
    if (cameraDevice && cameraPermission === 'authorized') {
      return (
        <Camera
          style={styles.camera}
          device={cameraDevice}
          isActive={true}
        />
      );
    }
    return <ActivityIndicator size="large" color="#1C6758" />;
  };

  return (
    <View style={styles.screen}>
      <SafeAreaView style={styles.saveArea}>
        <View style={styles.header}>
          <Text style={styles.headerText}>React Native 人脸检测器</Text>
        </View>
      </SafeAreaView>

      {renderDetectorContent()}
    </View>
  );
}

I've provided the translated code portion as requested. If you have any more translation needs or questions, feel free to ask.

英文:

How to use react-native-vision-camera Frame Processor to detect human faces? I tried using a package called vision-camera-face-detector but it fails my built when I am trying to create my react native cli app apk is there any other solution to detect human faces using react-native-vision-camera Frame Processor?

export default function App() {
const [cameraPermission, setCameraPermission] = useState();
useEffect(() =&gt; {
(async () =&gt; {
const cameraPermissionStatus = await Camera.requestCameraPermission();
setCameraPermission(cameraPermissionStatus);
})();
}, []);
console.log(`Camera permission status: ${cameraPermission}`);
const devices = useCameraDevices();
const cameraDevice = devices.back;
const renderDetectorContent = () =&gt; {
if (cameraDevice &amp;&amp; cameraPermission === &#39;authorized&#39;) {
return (
&lt;Camera
style={styles.camera}
device={cameraDevice}
isActive={true}
/&gt;
);
}
return &lt;ActivityIndicator size=&quot;large&quot; color=&quot;#1C6758&quot; /&gt;;
};
return (
&lt;View style={styles.screen}&gt;
&lt;SafeAreaView style={styles.saveArea}&gt;
&lt;View style={styles.header}&gt;
&lt;Text style={styles.headerText}&gt;React Native Face Detector&lt;/Text&gt;
&lt;/View&gt;
&lt;/SafeAreaView&gt;
{renderDetectorContent()}
&lt;/View&gt;
);
}

答案1

得分: 3

我可以使用 vision-camera-face-detector 插件来检测人脸。

查看文档 https://github.com/rodgomesc/vision-camera-face-detector

以下是示例的帧处理器:

  const frameProcessor = useFrameProcessor((frame) => {
    'worklet';
    const scannedFaces = scanFaces(frame);
    runOnJS(setFaces)(scannedFaces);
  }, []);
英文:

I can use the vision-camera-face-detector plugin to detect face.

See the docs https://github.com/rodgomesc/vision-camera-face-detector

Here's example the frame processor:

  const frameProcessor = useFrameProcessor((frame) =&gt; {
&#39;worklet&#39;;
const scannedFaces = scanFaces(frame);
runOnJS(setFaces)(scannedFaces);
}, []);

huangapple
  • 本文由 发表于 2023年4月17日 17:03:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033424.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定