Real-time face detection, facial feature recognition, and face identification in images, videos, and live webcam feeds. Perfect for security systems, attendance tracking, or your next AI project!
- Face Detection 👤: Find and highlight all faces in images, videos, or webcam streams
- Facial Features 👁️: Detect eyes, nose, mouth, and other facial landmarks
- Face Recognition 🔍: Identify people by comparing against known faces
- Multiple Formats 📁: Works with images, videos, and live webcam feeds
- Easy API 🔧: Simple Python class you can use in your own projects
pip install -r requirements.txtWhat gets installed:
opencv-python— Computer vision librarynumpy— Numerical computingmatplotlib— Visualizationscikit-learn— Machine learning
python Face\ Detection/facedetect.pyfrom FaceDetect import FaceDetect
# Initialize with image
fd = FaceDetect(source='image', image_path='photo.jpg')
# Detect faces
faces = fd.detect_faces()
print(f"Found {len(faces)} faces!")
# Recognize faces (requires known_faces folder)
identified = fd.recognize_faces(known_faces_folder='./known_people/')
for person, location in identified:
print(f"Found {person} at {location}")✅ Detect all faces in images
✅ Real-time webcam processing
✅ Video file processing
✅ Mark faces with rectangles
✅ Extract individual face crops
✅ Confidence scores
✅ Identify known people
✅ Name labels on detected faces
✅ Confidence matching
✅ Handle multiple angles
✅ Batch processing
✅ Eye detection
✅ Nose detection
✅ Mouth detection
✅ Face landmarks
✅ Feature drawing
python Face\ Detection/facedetect.py --image photo.jpg --output detected.jpgOutput: New image with faces highlighted
python Face\ Detection/facedetect.py --webcam --show-featuresFeatures: Real-time detection with facial landmarks
python Face\ Detection/facedetect.py --webcam --recognize --known-faces ./people/Features: Identifies people in real-time
python Face\ Detection/facedetect.py --video my_video.mp4 --recognizeOutput: New video with faces labeled
Face-Detection/
├── Face\ Detection/
│ └── facedetect.py # Main FaceDetect class
├── cascades/ # Pre-trained detection models
├── known_faces/ # Reference images for recognition
├── resources/ # Sample images
├── output/ # Generated output files
└── README.md
import cv2
from FaceDetect import FaceDetect
# Load image
image = cv2.imread('photo.jpg')
# Initialize detector
fd = FaceDetect()
# Detect faces
faces = fd.detect_faces(image)
# Draw rectangles
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Save result
cv2.imwrite('detected_faces.jpg', image)
print(f"Found {len(faces)} faces!")from FaceDetect import FaceDetect
import cv2
# Initialize
fd = FaceDetect(source='webcam')
# Start webcam
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
# Recognize faces
identified = fd.recognize_faces(frame, 'known_faces/')
# Draw labels
for name, (x, y, w, h) in identified:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.putText(frame, name, (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 2)
cv2.imshow('Face Recognition', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()opencv-python>=4.5.0
numpy>=1.19.0
matplotlib>=3.3.0
pillow>=8.0.0
scikit-learn>=0.24.0
scipy>=1.5.0
Install all:
pip install -r requirements.txt- Use multiple clear photos of each person (different angles, lighting)
- Good lighting improves detection significantly
- Photos should be face-focused (close-ups work best)
- Use at least 3-5 photos per person
- Lower image resolution for real-time video
- Use GPU acceleration if available
- Process every 2nd frame instead of every frame
- Crop regions of interest before processing
- Use high-quality images
- Ensure good lighting conditions
- Clean up known_faces folder (remove blurry/bad photos)
- Test with multiple threshold values
✅ Security Systems — Door entry, surveillance
✅ Attendance Tracking — Automatic classroom/office attendance
✅ Photo Organization — Auto-tag people in photos
✅ Video Analysis — Count people, detect crowds
✅ Access Control — Secure building/room entry
✅ Social Media — Auto-face blur for privacy
✅ Retail Analytics — Customer counting & analysis
Q: "No faces detected in my image"
- Check image quality and lighting
- Try a closer/clearer photo
- Adjust detection threshold in code
- Ensure face is clearly visible
Q: "Recognition not working"
- Add more training images (minimum 3-5 per person)
- Use clear, well-lit photos
- Remove low-quality images from known_faces/
- Increase similarity threshold
Q: "Slow performance"
- Reduce video resolution
- Process fewer frames per second
- Use GPU acceleration (CUDA)
- Process only face regions
Q: "Wrong faces detected"
- Check cascade file is correct
- Adjust scaleFactor and minNeighbors
- Try different detection method
- Use higher resolution image
Train your own detection model:
opencv_traincascade -data cascade_data/ -vec samples.vec -bg negatives.txt -numStages 15Enable CUDA for faster processing:
cv2.cuda.setDevice(0) # Select GPU deviceProcess multiple streams simultaneously for better performance
- Deep learning-based detection (YOLO, SSD)
- Age/gender estimation
- Emotion detection
- Face beautification filters
- Real-time video streaming
- Web interface
- Mobile app
- Deploy as REST API
- Create web dashboard
- Build desktop application
- Mobile app version
- Cloud deployment
MIT License - Use freely, modify, share!
Rushitha
Computer Vision | AI | Open Source
Have feedback? Open an issue
Want to contribute? Submit a PR
Last Updated: February 2026
Status: ✅ Active & Maintained