Skip to content

Commit 1c5cae4

Browse files
authored
Merge pull request #1234 from 770navyasharma/main
Issue #1232 Resolved
2 parents 5b67465 + 604a553 commit 1c5cae4

File tree

4 files changed

+240
-0
lines changed

4 files changed

+240
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Gait Recognition Project
2+
## Description
3+
The Gait Recognition project focuses on recognizing individuals based on their walking patterns. Gait recognition is a biometric authentication technique that identifies people by analyzing the unique way they walk. This technique has a wide range of applications, including security, surveillance, and even healthcare for detecting abnormalities in walking patterns.
4+
5+
This project uses OpenCV for video processing and image extraction, and Machine Learning for classifying the gait patterns of different individuals.
6+
## Features
7+
- **Video Processing**: Extract frames from video to analyze walking sequences.
8+
- **Pose Estimation**: Track key points of the human body to model the walking pattern.
9+
- **Gait Classification**: Classify individuals based on their walking patterns using machine learning models.
10+
- **Custom Dataset Support**: Can be adapted to different datasets of gait sequences for training and testing.
11+
12+
## Dependencies
13+
To run this project, you need the following libraries installed:
14+
- OpenCV for video and image processing:
15+
```
16+
pip install opencv-python
17+
18+
```
19+
- Numpy for numerical operations:
20+
```
21+
pip install numpy
22+
23+
```
24+
- scikit-learn for training the classification models:
25+
```
26+
pip install scikit-learn
27+
28+
```
29+
- TensorFlow or PyTorch (optional) for deep learning models (if using advanced classification):
30+
31+
```
32+
pip install tensorflow
33+
34+
```
35+
or
36+
```
37+
pip install torch torchvision
38+
39+
```
40+
41+
## How to Run
42+
- Install the required dependencies mentioned above.
43+
- Clone the project repository:
44+
```
45+
git clone https://github.com/your-repo/gait-recognition.git
46+
47+
```
48+
49+
- Navigate to the project directory:
50+
```
51+
cd gait-recognition
52+
53+
```
54+
- Prepare the dataset:
55+
- Place video files of individuals walking into the data/ folder.
56+
- Ensure that the videos are named appropriately for each individual (e.g., person_1.mp4, person_2.mp4).
57+
- Run the script to extract gait features and classify individuals:
58+
```
59+
python gait_recognition.py
60+
61+
```
62+
## How It Works
63+
Gait recognition works by extracting frames from a video sequence, detecting the human body in each frame, and then tracking key points such as the head, shoulders, hips, and feet. These key points form a "pose" for each frame, and the sequence of poses over time is used to capture the unique walking pattern (gait) of an individual.
64+
## Step-by-Step Process:
65+
- Frame Extraction:
66+
The video is processed to extract individual frames. Each frame is analyzed to detect the person in the scene.
67+
- Pose Estimation:
68+
- The key points of the human body are detected using a pose estimation model (such as OpenPose or the PoseNet model from TensorFlow).
69+
- These key points (like the head, shoulders, and knees) are tracked over time, forming a sequence of body movements.
70+
- Feature Extraction:
71+
The relative positions of key body points are extracted from each frame to form a feature vector for each step in the walking cycle.
72+
73+
- Classification:
74+
Machine learning models (such as Support Vector Machines, Random Forests, or Neural Networks) are used to classify the feature vectors based on the unique walking patterns of different individuals.
75+
- Prediction:
76+
Once the model is trained, it can classify the gait of new individuals based on their walking patterns.
77+
```
78+
- data/ # Folder for video data
79+
- gait_recognition.py # Main script for gait recognition
80+
- model/ # Folder to save trained models
81+
- README.md # Project documentation
82+
83+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import cv2
2+
import numpy as np
3+
from sklearn.neighbors import KNeighborsClassifier
4+
5+
# Load the pre-trained gait recognition model (or train a new one)
6+
model = KNeighborsClassifier(n_neighbors=3)
7+
8+
# Function to perform background subtraction and silhouette extraction
9+
def extract_silhouette(frame):
10+
# Convert the frame to grayscale
11+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
12+
13+
# Apply background subtraction
14+
fgmask = cv2.createBackgroundSubtractorMOG2().apply(gray)
15+
16+
# Threshold to binarize the silhouette
17+
_, silhouette = cv2.threshold(fgmask, 250, 255, cv2.THRESH_BINARY)
18+
19+
return silhouette
20+
21+
# Function to extract gait features from the silhouette
22+
def extract_gait_features(silhouette):
23+
# Example: Extract contour area as a feature
24+
contours, _ = cv2.findContours(silhouette, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
25+
if contours:
26+
largest_contour = max(contours, key=cv2.contourArea)
27+
return [cv2.contourArea(largest_contour)]
28+
return [0] # Return zero if no valid silhouette is found
29+
30+
# Start capturing video (from webcam or pre-recorded video)
31+
cap = cv2.VideoCapture('walking_video.mp4')
32+
33+
while True:
34+
ret, frame = cap.read()
35+
if not ret:
36+
break
37+
38+
# Extract silhouette from the current frame
39+
silhouette = extract_silhouette(frame)
40+
41+
# Extract gait features
42+
gait_features = extract_gait_features(silhouette)
43+
44+
# Display the silhouette
45+
cv2.imshow("Silhouette", silhouette)
46+
47+
# Check for user input to exit
48+
if cv2.waitKey(1) & 0xFF == ord('q'):
49+
break
50+
51+
cap.release()
52+
cv2.destroyAllWindows()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Virtual Painter Project
2+
3+
## Description
4+
The Virtual Painter is an interactive project where users can draw on the screen by tracking a colored object (e.g., a red pen or green object) via a webcam. As the object moves across the screen, it leaves a virtual trail, creating a painting or drawing effect. This project uses OpenCV to detect the object's color and track its movement, allowing for real-time drawing on the screen.
5+
6+
This fun and engaging project can be used for educational purposes, drawing games, or creative activities by tracking specific color objects and adjusting the canvas features.
7+
8+
## Features
9+
- **Real-time color tracking**: Detect and track an object with a specific color using the HSV color range.
10+
- **Dynamic Drawing**: Draw on the screen by moving the color object in front of the webcam.
11+
- **Customizable canvas**: Modify the color range and adjust the drawing features.
12+
- **Noise Filtering**: Ignores smaller irrelevant contours to prevent noise from interfering with the drawing.
13+
14+
## Dependencies
15+
To run this project, the following Python packages are required:
16+
- OpenCV for image processing:
17+
```pip install opencv-python```
18+
19+
- Numpy for numerical operations:
20+
```pip install numpy```
21+
22+
## How to Run
23+
- Install the required dependencies mentioned above.
24+
- Download or clone the project files:
25+
```git clone https://github.com/your-repo/your-project.git```
26+
- Navigate to the project directory:
27+
```cd your-project-folder```
28+
- Run the script:
29+
```python virtual_painter.py```
30+
- **Use a colored object** (like a red or green pen) in front of the webcam to start drawing. Move the object around to see the trail created on the screen.
31+
32+
## How It Works
33+
34+
The project works by using OpenCV to capture video from the webcam and detect the movement of an object based on its color. The HSV (Hue, Saturation, and Value) color space is used to define a range for detecting specific colors. Once the object is detected, its coordinates are tracked, and a trail is drawn on the canvas.
35+
## Color Detection
36+
The color detection is done using the HSV color range, which separates color (Hue) from intensity (Saturation and Value). The object's color is detected by defining lower and upper bounds in HSV format, which is then used to create a mask to highlight the colored object.
37+
## Tracking and Drawing
38+
Once the object is detected, its position is tracked, and the coordinates are stored in a list. The cv2.line() or cv2.circle() function is then used to draw lines or points on the screen at those coordinates, creating a virtual drawing effect.
39+
## Project Structure
40+
```
41+
- virtual_painter.py # Main script for the virtual painter
42+
- README.md # Documentation for the project
43+
```
44+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import cv2
2+
import numpy as np
3+
4+
# HSV color range for detecting the color object (adjust this range for different colors)
5+
lower_bound = np.array([0, 120, 70])
6+
upper_bound = np.array([10, 255, 255])
7+
8+
# Initialize variables
9+
my_points = [] # List to store points for drawing
10+
11+
# Function to detect color and return the coordinates of the detected object
12+
def find_color(img, lower_bound, upper_bound):
13+
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # Convert to HSV color space
14+
mask = cv2.inRange(hsv_img, lower_bound, upper_bound) # Create mask for specific color
15+
16+
# Find contours in the masked image
17+
contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
18+
x, y, w, h = 0, 0, 0, 0
19+
20+
for contour in contours:
21+
area = cv2.contourArea(contour)
22+
if area > 500: # Filter by area size to remove noise
23+
x, y, w, h = cv2.boundingRect(contour)
24+
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2) # Draw a rectangle around the object
25+
return x + w // 2, y
26+
27+
return None
28+
29+
# Function to draw on canvas based on detected points
30+
def draw_on_canvas(points, img):
31+
for point in points:
32+
cv2.circle(img, (point[0], point[1]), 10, (0, 0, 255), cv2.FILLED) # Draw red circles at each point
33+
34+
# Capture video from webcam
35+
cap = cv2.VideoCapture(0)
36+
37+
while True:
38+
success, img = cap.read() # Read frame from webcam
39+
if not success:
40+
break
41+
42+
# Find the object in the current frame
43+
new_point = find_color(img, lower_bound, upper_bound)
44+
45+
# If a new point is detected, add it to the list
46+
if new_point:
47+
my_points.append(new_point)
48+
49+
# Draw on the canvas using the points stored
50+
draw_on_canvas(my_points, img)
51+
52+
# Display the frame
53+
cv2.imshow("Virtual Painter", img)
54+
55+
# Break the loop on 'q' key press
56+
if cv2.waitKey(1) & 0xFF == ord('q'):
57+
break
58+
59+
# Release the webcam and close windows
60+
cap.release()
61+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)