Skip to content

leandre000/Face_Direction_Tracker_iot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

25 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– Face Direction & Speed Tracker using OpenCV

๐Ÿง  Project by: Shema Leandre

Field: Intelligent Systems & Robotics
Date: 2025
Repository: Face_Direction_Tracker_Project


๐ŸŽฏ Objective

This project demonstrates how to use OpenCV to detect a human face in real time, track its movement direction (Left, Right), and calculate the movement speed in pixels per second.

The system visually overlays:

  • A green bounding box around the detected face
  • Direction text (Left, Right, Up, Down)
  • Speed (px/s) on the live video feed

๐Ÿงฉ Features

โœ… Real-time face detection via OpenCV Haar Cascade
โœ… Dynamic direction tracking between consecutive frames
โœ… Speed estimation based on pixel displacement per second
โœ… Overlay visualization (text + bounding box)
โœ… Well-documented, readable, and modular code structure


๐Ÿง  How It Works (Logic Flow)

Step Operation Description
1๏ธโƒฃ Frame Capture Webcam feed captures live video frames.
2๏ธโƒฃ Preprocessing Each frame converted to grayscale for faster detection.
3๏ธโƒฃ Face Detection Haar Cascade locates the face rectangle (x, y, w, h).
4๏ธโƒฃ Center Calculation Center = (x + w/2, y + h/2) gives face midpoint.
5๏ธโƒฃ Tracking Compare center positions between current & previous frame.
6๏ธโƒฃ Direction Decision Based on displacement (dx, dy): determines Left/Right/Up/Down.
7๏ธโƒฃ Speed Computation Uses Euclidean distance & time delta โ†’ speed = distance / ฮ”t.
8๏ธโƒฃ Display Overlay Direction and speed are displayed on live video.

โš™๏ธ Technologies Used

Tool Purpose
Python 3.x Core programming language
OpenCV (cv2) Image & video processing
time module Measuring frame intervals for speed
Git & GitHub Version control and collaboration

๐Ÿงฉ Step 1 โ€” Install Dependencies

Make sure you have Python 3.x and OpenCV installed:

1.pip install opencv-python 2.Step 2 โ€” Run the Script 3.Execute the main script in your terminal: python face_direction_tracker.py โŒ Step 4 โ€” Exit To close the live webcam window, press:

๐Ÿง  Working Logic (Step-by-Step):

1.Capture Frame: The webcam captures each video frame in real-time. 2.Convert to Grayscale: Makes detection faster and easier for OpenCV. 3.Face Detection: Haar Cascade identifies the bounding box of your face. 4.Calculate Center: Compute (cx, cy) โ€” the midpoint of the face box. 5.Compare Frames: Measure how much the center moved since the last frame. 6.Compute Direction:

If cxโ‚‚ > cxโ‚ โ†’ Face moved Right

If cxโ‚‚ < cxโ‚ โ†’ Face moved Left

If cyโ‚‚ > cyโ‚ โ†’ Face moved Down

If cyโ‚‚ < cyโ‚ โ†’ Face moved Up

7.Compute Speed: Calculate pixels moved per second.

8.Overlay Results: Display direction and speed text on the live feed.

๐Ÿงฎ Formula for Speed Speed

( ๐‘‘ ๐‘ฅ ) 2 + ( ๐‘‘ ๐‘ฆ ) 2 ฮ” ๐‘ก Speed= ฮ”t (dx) 2 +(dy) 2

Where:

dx = cxโ‚‚ - cxโ‚ โ†’ horizontal movement

dy = cyโ‚‚ - cyโ‚ โ†’ vertical movement

ฮ”t โ†’ time difference between frames

๐Ÿ“Š Example Output When you move your face, the terminal and live video display: Direction: Left Speed: 120.54 px/s โœ… A green rectangle surrounds your face and updates continuously.

๐Ÿ“ˆ Visualization Overview Frame Detected Face Computed Center Output Frame 1 Yes (320, 240) โ€” Frame 2 Yes (380, 240) Direction: Right, Speed: 60 px/s Frame 3 Yes (380, 280) Direction: Down, Speed: 40 px/s

๐Ÿง  What I Learned:

From this project, I developed practical understanding of: ๐Ÿงฉ How OpenCV detects and tracks moving objects ๐Ÿงฎ How to measure position change for motion detection โฑ๏ธ How to calculate speed based on time intervals ๐Ÿง  The concept of direction vectors in computer vision

๐Ÿš€ Future Improvements: Improvement and Description ๐Ÿ”น Use Mediapipe or Dlib For more accurate face landmarks ๐Ÿ”น Add 3D Head Pose Estimation Estimate angles (pitch, yaw, roll) ๐Ÿ”น Integrate with servo motors Make a robot head follow user movement ๐Ÿ”น Data Logging Save motion data for ML training or analytics ๐Ÿ”น Optimize frame rate Use multi-threading for smoother tracking

๐Ÿ“˜ References & Learning Materials: 1.OpenCV Official Documentation 2.PyImageSearch Tutorials 3.Real-Time Object Tracking (LearnOpenCV)

๐Ÿค– Face Direction & Speed Tracker using OpenCV

๐Ÿ‘จโ€๐ŸŽ“ By: Shema Leandre

Field: Intelligent Systems & Robotics
Year: 2025


About

Face_Direction_Tracker_ & Recognition Project using OpenCV and Python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages