Giter Club home page Giter Club logo

faces's Introduction

Real-time Face Detection with Python

Overview

A Python script that uses the OpenCV library to perform real-time face detection from a webcam feed. It captures video from the default camera (index 0) and highlights detected faces with rectangles. Here's an overview of the code:

Importing Necessary Libraries

The code starts by importing two essential libraries: pathlib and cv2 (OpenCV). pathlib is used for working with file paths, and cv2 is OpenCV for computer vision tasks.

Path to Haar Cascade Classifier XML File

It determines the path to the Haar Cascade classifier XML file for face detection. This XML file contains the pre-trained model for detecting faces.

Creating a Video Capture Object

The script creates a cv2.VideoCapture object named camera to capture video from the default camera (camera index 0).

Setting Up the Full-Screen Window

The code sets up a full-screen window for displaying the video feed: It uses the cv2.namedWindow function to create a named window called "Faces." It sets the window properties to make it full-screen using cv2.setWindowProperty.

Real-Time Face Detection Loop

The main part of the code is a continuous loop that captures video frames, performs face detection, and displays the video feed with rectangles drawn around detected faces.

Inside the loop

It reads a frame from the camera using camera.read(). Converts the frame to grayscale using cv2.cvtColor for efficient face detection. Uses the detectMultiScale method of the Cascade Classifier (clf) to find faces in the grayscale frame. It specifies parameters like scaling factor, minimum neighbors, and minimum size for detected objects. It loops through the detected faces, drawing rectangles around them using cv2.rectangle. The processed frame is displayed in the full-screen window named "Faces" using cv2.imshow.

User Input and Exit Condition

The code continuously checks for user input. If the "q" key is pressed (detected by cv2.waitKey(1)), the loop breaks, and the program exits.

Releasing the Camera and Closing the Window

After breaking out of the loop, the script releases the camera capture using camera.release() to free the camera resource. It also closes all OpenCV windows using cv2.destroyAllWindows().

The result of running this code is a full-screen window displaying the live video feed from your camera, with faces highlighted by rectangles. You can exit the program by pressing the "q" key. This code provides a basic implementation of real-time face detection and can serve as a starting point for more advanced face recognition or tracking applications.

Screenshot from 2024-05-02 16-04-44

faces's People

Contributors

abhishek7h avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.