This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AnimatedLine = Animated.createAnimatedComponent(Line); | |
| //... | |
| <Svg | |
| height={Dimensions.get('window').height} | |
| width={Dimensions.get('window').width} | |
| style={styles.linesContainer}> | |
| <AnimatedLine animatedProps={leftWristToElbowPosition} stroke="red" strokeWidth="2" /> | |
| <AnimatedLine animatedProps={leftElbowToShoulderPosition} stroke="red" strokeWidth="2" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Camera | |
| frameProcessor={frameProcessor} | |
| style={StyleSheet.absoluteFill} | |
| device={device} | |
| isActive={true} | |
| orientation="portrait" | |
| frameProcessorFps={15} | |
| /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const dimensions = useWindowDimensions(); | |
| const frameProcessor = useFrameProcessor(frame => { | |
| 'worklet'; | |
| const poseObject = objectDetect(frame); | |
| const xFactor = dimensions.width / frame.width; | |
| const yFactor = dimensions.height / frame.height; | |
| const poseCopy = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const usePosition = (pose, valueName1, valueName2) => { | |
| return useAnimatedStyle( | |
| () => ({ | |
| x1: pose.value[valueName1].x, | |
| y1: pose.value[valueName1].y, | |
| x2: pose.value[valueName2].x, | |
| y2: pose.value[valueName2].y, | |
| }), | |
| [pose], | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const leftWristToElbowPosition = usePosition(pose, 'leftWrist', 'leftElbow'); | |
| const leftElbowToShoulderPosition = usePosition(pose, 'leftElbow', 'leftShoulder'); | |
| const leftShoulderToHipPosition = usePosition(pose, 'leftShoulder', 'leftHip'); | |
| const leftHipToKneePosition = usePosition(pose, 'leftHip', 'leftKnee'); | |
| const leftKneeToAnklePosition = usePosition(pose, 'leftKnee', 'leftAnkle'); | |
| const rightWristToElbowPosition = usePosition(pose, 'rightWrist', 'rightElbow'); | |
| const rightElbowToShoulderPosition = usePosition(pose, 'rightElbow', 'rightShoulder'); | |
| const rightShoulderToHipPosition = usePosition(pose, 'rightShoulder', 'rightHip'); | |
| const rightHipToKneePosition = usePosition(pose, 'rightHip', 'rightKnee'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const defaultPose = { | |
| leftShoulder: {x: 0, y: 0}, | |
| rightShoulder: {x: 0, y: 0}, | |
| leftElbow: {x: 0, y: 0}, | |
| rightElbow: {x: 0, y: 0}, | |
| leftWrist: {x: 0, y: 0}, | |
| rightWrist: {x: 0, y: 0}, | |
| leftHip: {x: 0, y: 0}, | |
| rightHip: {x: 0, y: 0}, | |
| leftKnee: {x: 0, y: 0}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function objectDetect(frame) { | |
| 'worklet'; | |
| return __poseDetection(frame); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| plugins: [ | |
| [ | |
| 'react-native-reanimated/plugin', | |
| { | |
| globals: ['__poseDetection'], | |
| }, | |
| ], | |
| ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| #import <VisionCamera/FrameProcessorPlugin.h> | |
| #import <VisionCamera/Frame.h> | |
| #import "PoseDetection.h" | |
| @interface PoseDetectionFrameProcessor : NSObject | |
| @end | |
| @implementation PoseDetectionFrameProcessor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (error != nil) { | |
| // Error. | |
| return @{}; | |
| } | |
| if (poses.count == 0) { | |
| // No pose detected. | |
| return @{}; | |
| } | |
NewerOlder