Skip to content

Latest commit

Β 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Botzface - Real-Time Face Tracking Android App

Android Kotlin ML Kit CameraX

An interactive Android application featuring a bot character whose eyes follow your face in real-time using on-device ML Kit face detection.

Features β€’ Architecture β€’ Setup β€’ Usage β€’ Technologies


πŸ“± Overview

Botzface is a fun and interactive Android application that demonstrates real-time face tracking using Google's ML Kit. The app displays an animated bot character that tracks human faces through the device's front camera, with eyes that follow your position and expressions that respond to your facial features.

Key Highlights

  • 🎯 Real-time face tracking with smooth animations
  • πŸ‘οΈ Eye movement follows detected face position
  • 😊 Expression recognition (smiling, eyes open/closed)
  • πŸ“± On-device processing - no internet required
  • ⚑ Optimized performance for smooth experience
  • πŸ”’ Privacy-focused - no data storage or transmission

✨ Features

Core Functionality

  • Live Camera Preview: Uses front-facing camera with CameraX
  • Face Detection: Powered by Google ML Kit for accurate tracking
  • Animated Bot Character: Custom-drawn bot face with reactive expressions
  • Eye Tracking: Bot eyes follow the detected face position
  • Facial Expression Response: Reacts to smiling and eye states
  • Multiple Face Support: Detects and tracks multiple faces (focuses on primary face)
  • Bounding Box Overlay: Visual feedback showing detected face regions

Technical Features

  • MVVM Architecture: Clean separation of concerns
  • Dependency Injection: Using Hilt for scalable code
  • Lifecycle-Aware: Proper resource management
  • Permission Handling: Modern runtime permission requests
  • Smooth Animations: ValueAnimator with interpolators

πŸ—οΈ Architecture

The app follows Clean Architecture principles with MVVM pattern:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Presentation Layer β”‚
β”‚ (Activities, Fragments, ViewModels) β”‚
β”‚ CameraFragment.kt β”‚
β”‚ FaceDetectionViewModel.kt β”‚
β”‚ PetbotFaceView.kt (Custom View) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Domain Layer β”‚
β”‚ (Use Cases, Models) β”‚
β”‚ DetectFacesUseCase.kt β”‚
β”‚ DetectedFace.kt (Model) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Data Layer β”‚
β”‚ (Repository, Data Sources) β”‚
β”‚ FaceDetectionRepository.kt β”‚
β”‚ FaceData.kt (Model) β”‚
β”‚ ML Kit Face Detection API β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

app/
β”œβ”€β”€ data/
β”‚ β”œβ”€β”€ model/
β”‚ β”‚ └── FaceData.kt
β”‚ └── repository/
β”‚ └── FaceDetectionRepository.kt
β”œβ”€β”€ domain/
β”‚ β”œβ”€β”€ model/
β”‚ β”‚ └── DetectedFace.kt
β”‚ └── usecase/
β”‚ └── DetectFacesUseCase.kt
β”œβ”€β”€ presentation/
β”‚ β”œβ”€β”€ ui/
β”‚ β”‚ β”œβ”€β”€ CameraFragment.kt
β”‚ β”‚ └── custom/
β”‚ β”‚ β”œβ”€β”€ PetbotFaceView.kt
β”‚ β”‚ └── FaceOverlayView.kt
β”‚ β”œβ”€β”€ viewmodel/
β”‚ β”‚ └── FaceDetectionViewModel.kt
β”‚ └── util/
β”‚ └── PermissionUtils.kt
β”œβ”€β”€ di/
β”‚ └── AppModule.kt
└── PetbotApplication.kt

πŸš€ Setup

Prerequisites

  • Android Studio: Ladybug (2024.2.2) or higher
  • Minimum SDK: API 24 (Android 7.0 Nougat)
  • Target SDK: API 35 (Android 15)
  • Kotlin: 2.0.21
  • Gradle: 8.9

Installation

  1. Clone the repository
git clone https://github.com/Ravindu56/botzface.git
cd botzface
  1. Open in Android Studio
  • Open Android Studio
  • Select "Open an Existing Project"
  • Navigate to the cloned directory
  1. Sync Gradle
  • Wait for Gradle sync to complete
  • Download dependencies (first sync may take a few minutes)
  1. Build the project
./gradlew build
  1. Run on device/emulator
  • Connect an Android device with USB debugging enabled, or
  • Start an Android emulator (API 24+)
  • Click Run ▢️ in Android Studio

πŸ“– Usage

First Launch

  1. Grant Camera Permission: The app will request camera access on first launch
  2. Position Your Face: Place your face in front of the camera
  3. Watch the Bot: The bot's eyes will follow your face position
  4. Try Expressions: Smile or close your eyes to see the bot react

Controls

  • Eyes: Follow your face position across the screen
  • Smile: Bot smiles when you smile
  • Eyes Closed: Bot closes eyes when you close yours

πŸ› οΈ Technologies

Core Libraries

Technology Version Purpose
Kotlin 2.0.21 Primary language
CameraX 1.3.1 Camera preview and image analysis
ML Kit Face Detection 16.1.7 On-device face detection
Hilt 2.50 Dependency injection
Coroutines 1.8.1 Asynchronous programming
LiveData 2.8.6 Reactive data observation
ViewBinding - Type-safe view access

Android Jetpack Components

  • ViewModel: UI state management
  • LiveData: Observable data holder
  • Lifecycle: Lifecycle-aware components
  • Activity/Fragment KTX: Kotlin extensions

ML & Vision

  • Google ML Kit: Face detection and landmark tracking
  • Face Classification: Smile probability, eye open probability
  • Face Tracking: Persistent tracking across frames

πŸ“ Key Components

1. Face Detection Pipeline

CameraX Frame β†’ YUV to Bitmap β†’ ML Kit Detection β†’ Domain Model Mapping β†’ ViewModel β†’ UI Update

2. Custom Views

  • PetbotFaceView: Draws animated bot face with moving eyes
  • FaceOverlayView: Renders bounding boxes around detected faces

3. Animation System

  • ValueAnimator: Smooth eye movement interpolation
  • DecelerateInterpolator: Natural-feeling animations
  • Target-based tracking: Eyes gradually move to target position

βš™οΈ Configuration

Face Detection Settings

Located in FaceDetectionRepository.kt:

val options = FaceDetectorOptions.Builder()
.setPerformanceMode(FaceDetectorOptions.PERFORMANCE_MODE_FAST)
.setLandmarkMode(FaceDetectorOptions.LANDMARK_MODE_ALL)
.setClassificationMode(FaceDetectorOptions.CLASSIFICATION_MODE_ALL)
.setMinFaceSize(0.15f) // Adjust minimum face size (0.1f - 1.0f)
.enableTracking() // Enable persistent tracking
.build()

Performance Tuning

Adjust frame processing rate in CameraFragment.kt:

private val analysisInterval = 100L // Process every 100ms (10 FPS)

Lower values = smoother tracking but higher CPU usage


πŸ”§ Troubleshooting

Camera Not Starting

  • Check permissions: Ensure camera permission is granted in Settings
  • Restart app: Force stop and relaunch the app
  • Check device: Verify device has front-facing camera

Face Not Detected

  • Lighting: Ensure adequate lighting conditions
  • Distance: Position face 30-100cm from camera
  • Angle: Face camera directly (avoid extreme angles)

Performance Issues

  • Close background apps: Free up system resources
  • Reduce frame rate: Increase analysisInterval value
  • Check device specs: App optimized for Snapdragon 835 or better

🎯 Future Enhancements

  • Face Recognition - Identify and remember specific users
  • Photo Capture - Save screenshots of interactions
  • Multiple Bot Characters - Choose different bot designs
  • Expression Filters - Add AR effects and filters
  • Voice Interaction - Add speech recognition
  • Cloud Sync - Optional cloud backup of preferences
  • Settings UI - Customize sensitivity, appearance
  • Multi-language Support - Localization

πŸ“± Device Requirements

Recommended

  • Device: Sony Xperia XZ1 Compact or equivalent
  • Processor: Qualcomm Snapdragon 835 or better
  • RAM: 4GB minimum
  • Camera: Front-facing camera with autofocus
  • Android: 7.0 Nougat or higher

Tested Devices

  • Sony Xperia XZ1 Compact (Primary)
  • Android Emulator (API 24-35)

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Coding Standards

  • Follow Kotlin Coding Conventions
  • Add KDoc comments for public APIs
  • Write unit tests for business logic
  • Ensure code passes Lint checks

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2025 Ravindu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


πŸ‘¨β€πŸ’» Author

Ravindu


πŸ™ Acknowledgments

  • Google ML Kit - For providing excellent on-device ML APIs
  • Android Team - For CameraX and Jetpack libraries
  • Kotlin Team - For the amazing programming language
  • Stack Overflow Community - For countless solutions

πŸ“Š Stats

GitHub stars GitHub forks GitHub issues


Made with ❀️ and Kotlin

If you found this project helpful, please consider giving it a ⭐!

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages