Skip to content

Instantly share code, notes, and snippets.

View lukaszkurantdev's full-sized avatar

Łukasz Kurant lukaszkurantdev

View GitHub Profile
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" />
<Camera
frameProcessor={frameProcessor}
style={StyleSheet.absoluteFill}
device={device}
isActive={true}
orientation="portrait"
frameProcessorFps={15}
/>
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 = {
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],
);
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');
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},
export function objectDetect(frame) {
'worklet';
return __poseDetection(frame);
}
plugins: [
[
'react-native-reanimated/plugin',
{
globals: ['__poseDetection'],
},
],
],
#import <Foundation/Foundation.h>
#import <VisionCamera/FrameProcessorPlugin.h>
#import <VisionCamera/Frame.h>
#import "PoseDetection.h"
@interface PoseDetectionFrameProcessor : NSObject
@end
@implementation PoseDetectionFrameProcessor
if (error != nil) {
// Error.
return @{};
}
if (poses.count == 0) {
// No pose detected.
return @{};
}