-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
131 lines (118 loc) · 3.02 KB
/
App.tsx
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React, {useEffect} from 'react';
import {StatusBar, StyleSheet, Text, View, TextInput} from 'react-native';
import 'react-native-reanimated';
import Animated, {
useAnimatedProps,
useSharedValue,
} from 'react-native-reanimated';
import {
Camera,
useCameraDevices,
useFrameProcessor,
} from 'react-native-vision-camera';
import {labelImage} from './labelImage';
const AnimatedTextInput: any = Animated.createAnimatedComponent(TextInput);
const App = () => {
const [hasPermission, setHasPermission] = React.useState(false);
const label1 = useSharedValue('');
const label2 = useSharedValue('');
const label3 = useSharedValue('');
const textProps = useAnimatedProps(
() => ({text: label1.value}),
[label1.value],
);
const textProps2 = useAnimatedProps(
() => ({text: label2.value}),
[label2.value],
);
const textProps3 = useAnimatedProps(
() => ({text: label3.value}),
[label3.value],
);
useEffect(() => {
Camera.requestCameraPermission().then(status => {
if (status === 'authorized') {
setHasPermission(true);
}
});
}, []);
const devices = useCameraDevices();
const device = devices.back;
const frameProcessor = useFrameProcessor(frame => {
'worklet';
const imageLabels = labelImage(frame);
label1.value = imageLabels[0]?.label;
label2.value = imageLabels[1]?.label;
label3.value = imageLabels[2]?.label;
}, []);
if (!hasPermission) {
return (
<View style={styles.container}>
<Text style={styles.text}>No permission</Text>
</View>
);
}
if (device == null) {
return (
<View style={styles.container}>
<Text style={styles.text}>Waiting</Text>
</View>
);
}
return (
<View style={styles.container}>
<StatusBar hidden />
<Camera
style={StyleSheet.absoluteFill}
device={device}
isActive
frameProcessor={frameProcessor}
frameProcessorFps={20}
/>
<View style={styles.containerLabels}>
<AnimatedTextInput
underlineColorAndroid="transparent"
editable={false}
value={label1.value}
style={styles.text}
animatedProps={textProps}
/>
<AnimatedTextInput
underlineColorAndroid="transparent"
editable={false}
value={label2.value}
style={styles.text}
animatedProps={textProps2}
/>
<AnimatedTextInput
underlineColorAndroid="transparent"
editable={false}
value={label3.value}
style={styles.text}
animatedProps={textProps3}
/>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'black',
justifyContent: 'center',
alignItems: 'center',
},
text: {
fontSize: 20,
color: 'white',
textAlign: 'right',
},
containerLabels: {
position: 'absolute',
backgroundColor: 'rgba(0,0,0,0.6)',
top: 0,
right: 0,
width: 200,
},
});
export default App;