An iOS app that uses the device camera to detect and overlay the skeletal structure (bones) of people in real-time using Apple's Vision framework.
- 🎥 Real-time camera feed processing
- 🦴 Human pose detection and skeleton overlay
- 🎨 Visual bone connections with confidence-based opacity
- 👤 Multi-person detection support
- 📱 Native iOS app using SwiftUI
- iOS 14.0 or later
- Xcode 13.0 or later
- Physical iOS device with camera (simulator doesn't support camera)
- Swift 5.5+
- SwiftUI: Modern UI framework
- AVFoundation: Camera capture and video processing
- Vision Framework: Human body pose detection (
VNDetectHumanBodyPoseRequest) - Core Image: Image processing
SkeletonDetection.xcodeproj/ # Xcode project file
SkeletonDetection/
├── SkeletonDetectionApp.swift # Main app entry point
├── ContentView.swift # Main view with camera and overlay
├── CameraManager.swift # Camera capture and frame management
├── CameraView.swift # UIKit camera view wrapper
├── PoseDetectionService.swift # Vision framework pose detection
├── SkeletonOverlayView.swift # SwiftUI skeleton rendering
├── Info.plist # App permissions
├── Assets.xcassets/ # Asset catalog
└── Preview Content/ # Preview assets
README.md # This file
The project is already fully configured and ready to use!
-
Open the project in Xcode:
open SkeletonDetection.xcodeproj
-
Connect your iOS device via USB
-
Select your device as the build target in Xcode (top toolbar)
-
Configure code signing:
- Click on the project in the navigator
- Select "SkeletonDetection" target
- Go to "Signing & Capabilities"
- Select your Team (you may need to add your Apple ID)
-
Click Run (
▶️ ) or pressCmd + R -
Grant camera permission when prompted on your device
That's it! The app should now launch and start detecting your skeleton.
If you need to create the project from scratch:
- Open Xcode
- Select File → New → Project
- Choose iOS → App
- Fill in project details:
- Product Name:
SkeletonDetection - Interface: SwiftUI
- Language: Swift
- Product Name:
- Add all the
.swiftfiles to your project - Replace the
Info.plistwith the provided one
The CameraManager class uses AVFoundation to:
- Request camera permissions
- Set up a capture session with the front-facing camera
- Process video frames at high quality
- Output frames as CVPixelBuffer objects
The PoseDetectionService uses Vision framework to:
- Process each video frame with
VNDetectHumanBodyPoseRequest - Detect up to multiple people in the frame
- Identify 19 body joints (nose, eyes, ears, shoulders, elbows, wrists, hips, knees, ankles, neck, root)
- Return confidence scores for each detected joint
The SkeletonOverlayView renders:
- Bones: Lines connecting related joints (e.g., shoulder to elbow, elbow to wrist)
- Joints: Circles at each detected body point
- Confidence visualization: Opacity based on detection confidence
Vision framework returns normalized coordinates (0-1) with origin at bottom-left. The app converts these to SwiftUI coordinates with origin at top-left.
The app detects these joints:
- Head: nose, left/right eyes, left/right ears
- Torso: neck, left/right shoulders, left/right hips, root
- Arms: left/right elbows, left/right wrists
- Legs: left/right knees, left/right ankles
The skeleton overlay draws connections between:
- Head bones: nose ↔ eyes ↔ ears, nose ↔ neck
- Torso: neck ↔ shoulders ↔ hips, hip ↔ hip
- Left arm: shoulder → elbow → wrist
- Right arm: shoulder → elbow → wrist
- Left leg: hip → knee → ankle
- Right leg: hip → knee → ankle
Edit SkeletonOverlayView.swift:
// Bones color
.stroke(Color.cyan, lineWidth: 3) // Change to .red, .blue, etc.
// Joints color
Circle().fill(Color.green) // Change to preferred color.frame(width: 8, height: 8) // Increase for larger dots.stroke(Color.cyan, lineWidth: 3) // Increase lineWidthEdit PoseDetectionService.swift:
recognizedPoint.confidence > 0.1 // Increase to 0.3 or 0.5 for stricter detectionEdit CameraManager.swift:
.default(.builtInWideAngleCamera, for: .video, position: .back) // Change .front to .back- Ensure you're running on a physical device (not simulator)
- Check that camera permissions are enabled in Settings → Privacy → Camera
- Verify Info.plist contains
NSCameraUsageDescription
- Ensure good lighting conditions
- Stand in front of the camera with full body visible
- Try adjusting the confidence threshold (lower for more detections)
- Check console for Vision framework errors
- Ensure deployment target is iOS 14.0 or later
- Clean build folder: Product → Clean Build Folder (Cmd + Shift + K)
- Restart Xcode if issues persist
- Go to Signing & Capabilities in Xcode
- Ensure "Automatically manage signing" is checked
- Add your Apple ID account if needed (Xcode → Settings → Accounts)
- The app processes every frame, which can be CPU-intensive
- Consider adding frame skipping logic in
CameraManager.swift - Reduce video quality if needed (change
.highto.medium)
For better performance:
- Use a newer device (A12 chip or later recommended)
- Ensure good lighting
- Keep the full body visible in frame
- Close background apps
- Open
SkeletonDetection.xcodeproj - Select your device
- Click Run (
▶️ )
# List available devices
xcrun xcodebuild -project SkeletonDetection.xcodeproj -list
# Build for connected device
xcodebuild -project SkeletonDetection.xcodeproj \
-scheme SkeletonDetection \
-destination 'platform=iOS,id=<device-id>' \
build
# Install on device (requires proper provisioning)
xcodebuild -project SkeletonDetection.xcodeproj \
-scheme SkeletonDetection \
-destination 'platform=iOS,id=<device-id>' \
installPotential improvements:
- Recording video with skeleton overlay
- Saving screenshots
- Angle measurements between joints
- Exercise form analysis
- Motion tracking and gesture recognition
- 3D skeleton visualization with ARKit
- Export joint coordinates for analysis
- Workout rep counter
- Real-time form correction feedback
This app:
- Only processes camera data locally on device
- Does not save or transmit any images or video
- Uses Vision framework which runs entirely on-device
- Requires camera permission to function
- AVFoundation: Camera capture
- Vision: Body pose detection
- SwiftUI: User interface
- Core Image: Image processing
- Combine: Reactive programming
VNDetectHumanBodyPoseRequest: Vision request for body poseVNHumanBodyPoseObservation: Contains detected joint positionsAVCaptureSession: Manages camera input/outputCVPixelBuffer: Raw video frame data
Free to use and modify for personal and commercial projects.
Built with:
- Apple Vision Framework
- AVFoundation
- SwiftUI
- Core Image
For issues or questions:
- Check the Troubleshooting section
- Review Apple's Vision Framework documentation
- Check console logs in Xcode for detailed error messages
When you first run the app:
- The app will request camera permission - tap "Allow"
- Stand back so your full body is visible in the frame
- The skeleton overlay should appear automatically
- Move around to see the skeleton track your movements in real-time!
- Lighting: Ensure good, even lighting on your body
- Background: A plain background helps detection accuracy
- Clothing: Avoid baggy clothes that obscure body shape
- Distance: Stand 6-10 feet from the camera for full body visibility
- Stability: Hold your device steady or use a tripod
Enjoy tracking your skeleton! 🦴✨