-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
112 lines (100 loc) · 2.85 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { StyleSheet, Text, View, Button } from "react-native";
import React, { useState, useEffect } from "react";
import { Camera } from "expo-camera";
import * as FaceDetector from "expo-face-detector";
export default function App() {
const [hasPermission, setHasPermission] = useState();
const [faceData, setFaceData] = useState([]);
const [permission, requestPermission] = Camera.useCameraPermissions();
if (!permission) {
// Camera permissions are still loading
return <View />;
}
// useEffect(() => {
// (async () => {
// const { status } = await Camera.requestCameraPermissionsAsync;
// setHasPermission(status === "granted");
// })();
// }, []);
if (!permission.granted) {
return (
<View>
<Text style={styles.permissionText}>No access to Camera</Text>
<Button onPress={requestPermission} title="Grant permission" />
</View>
);
}
function getFaceDataView() {
if (faceData.length === 0) {
return (
<View style={styles.faces}>
<Text style={styles.faceDesc}>Yüz bulunamadı :/</Text>
</View>
);
} else {
return faceData.map((face, index) => {
const eyesShut =
face.rightEyeOpenProbability < 0.4 &&
face.leftEyeOpenProbability < 0.4;
// const winking =
// !eyesShut &&
// (face.rightEyeOpenProbability < 0.4 || leftEyeOpenProbability < 0.4);
const smiling = face.smilingProbability > 0.3;
return (
<View style={styles.faces}>
<Text style={styles.faceDesc}>
Gözler: {eyesShut ? "Kapalı" : "Açık"}
</Text>
{/* <Text style={styles.faceDesc}>Winking: {winking.toString()}</Text> */}
<Text style={styles.faceDesc}>
Gülümseme: {smiling ? "Var" : "Yok"}
</Text>
</View>
);
});
}
}
const handleFacesDetected = ({ faces }) => {
setFaceData(faces);
console.log(faces);
};
return (
<Camera
type={Camera.Constants.Type.front}
style={styles.camera}
onFacesDetected={handleFacesDetected}
faceDetectorSettings={{
mode: FaceDetector.FaceDetectorMode.fast,
detectLandmarks: FaceDetector.FaceDetectorLandmarks.all,
runClassifications: FaceDetector.FaceDetectorClassifications.all,
minDetectionInterval: 100,
tracking: true,
}}
>
{getFaceDataView()}
</Camera>
);
}
const styles = StyleSheet.create({
camera: {
flex: 1,
alignItems: "flex-start",
justifyContent: "flex-start",
top: 40,
},
faces: {
backgroundColor: "#ffffff",
width: "50%",
alignSelf: "flex-start",
alignItems: "center",
justifyContent: "center",
margin: 16,
},
faceDesc: {
fontSize: 20,
},
permissionText: {
top: 100,
alignSelf: "center",
},
});