On Day 2, we’ll set up real-time pose detection using TensorFlow.js and PoseNet/BlazePose to track body movements during workouts.
1. Why Use AI Pose Detection for Workouts?
✅ Tracks Exercise Form → AI detects body posture and gives real-time feedback.
✅ Counts Reps Automatically → No need to manually count squats, push-ups, or lunges.
✅ Detects Incorrect Movements → AI warns if form is incorrect to prevent injuries.
✅ Works Without Wearables → Just a smartphone camera is enough!
2. Choosing a Pose Detection Model
- PoseNet (Fast, Good for Basic Tracking)
- BlazePose (More Advanced, Supports Angles & 33 Key Points)
For this tutorial, we’ll use BlazePose, as it provides better workout tracking.
3. Installing TensorFlow & Pose Detection
Run:
npm install @tensorflow/tfjs @tensorflow-models/pose-detection @tensorflow/tfjs-react-native expo-camera
expo install expo-gl
4. Setting Up Camera for Pose Detection
We’ll integrate Expo Camera to capture the user’s workout movements.
✅ Step 1: Create WorkoutScreen.js
Inside src/screens/WorkoutScreen.js
:
import React, { useRef, useState, useEffect } from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
import { Camera } from 'expo-camera';
import * as tf from '@tensorflow/tfjs';
import * as poseDetection from '@tensorflow-models/pose-detection';
import { cameraWithTensors } from '@tensorflow/tfjs-react-native';
const TensorCamera = cameraWithTensors(Camera);
export default function WorkoutScreen() {
const [permission, setPermission] = useState(null);
const [poseData, setPoseData] = useState(null);
const cameraRef = useRef(null);
let detector = null;
useEffect(() => {
(async () => {
const { status } = await Camera.requestPermissionsAsync();
setPermission(status === 'granted');
await tf.ready();
detector = await poseDetection.createDetector(poseDetection.SupportedModels.BlazePose);
})();
}, []);
const handlePoseDetection = async (imageTensor) => {
if (!detector) return;
const poses = await detector.estimatePoses(imageTensor);
if (poses.length > 0) {
setPoseData(poses[0].keypoints);
}
};
if (permission === null) return <Text>Requesting camera permission...</Text>;
if (permission === false) return <Text>No access to camera</Text>;
return (
<View style={styles.container}>
<TensorCamera
ref={cameraRef}
style={styles.camera}
type={Camera.Constants.Type.front}
onReady={handlePoseDetection}
autorender={true}
/>
{poseData && <Text>Pose Detected: {JSON.stringify(poseData)}</Text>}
</View>
);
}
const styles = StyleSheet.create({
container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
camera: { width: '100%', height: '70%' },
});
5. Adding Workout Tracking to Navigation
✅ Step 1: Update App.js
Modify App.js
to add a workout screen:
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import HomeScreen from './src/screens/HomeScreen';
import WorkoutScreen from './src/screens/WorkoutScreen';
const Stack = createStackNavigator();
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Workout" component={WorkoutScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
✅ Step 2: Add “Start Workout” Button in Home Screen
Modify HomeScreen.js
:
<Button title="Start Workout" onPress={() => navigation.navigate('Workout')} />
6. Running the AI Pose Detection
Run:
npx expo start
- Grant camera permission when prompted.
- The camera detects body movement and displays pose keypoints.
7. Preparing for Tomorrow: AI Rep Counting & Form Correction
Tomorrow, we’ll:
- Track squats, push-ups, and lunges using pose angles.
- Correct incorrect form using AI analysis.
8. Key Concepts Covered
✅ Set up real-time camera-based pose detection.
✅ Installed TensorFlow.js & BlazePose for AI tracking.
✅ Integrated pose detection into the app.
9. Next Steps: AI Workout Rep Counting & Form Correction
Tomorrow, we’ll:
- Use AI to count squats, push-ups, and lunges.
- Detect incorrect workout form in real-time.
10. References & Learning Resources
11. SEO Keywords:
AI workout tracker, React Native pose detection, TensorFlow BlazePose app, AI fitness tracking, AI-powered personal trainer.