Git Product home page Git Product logo

face-detection's Introduction

Face-detection

Detect human face with live feeds from Webcam.

You will need,

 PyCharm IDE 2018.2

 OpenCV-python 3.2.0.8

 Python 3.6

Code Explanation

import can load the modules into the current namespace so that you can access the functions and anything else defined within the module using the module name.

import cv2
import sys

cv2 OpenCV-Python is a library of Python bindings designed to solve computer vision problems.
sys provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter.

haarcascade is basically a classifier which is used to detect the object for which it has been trained for, from the source.

cascPath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)

haarcascade_frontalface_default.xml is a haar cascade designed by OpenCV to detect the frontal face.

define a video capture object

video_capture = cv2.VideoCapture(0)

0 is for default camera.

capturing frame by frame

ret, frame = video_capture.read()

Covert frames to gray scale

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

Detecting face

faces = faceCascade.detectMultiScale(
        gray,   
        scaleFactor=1.1,    
        minNeighbors=5,     
        minSize=(30, 30),   
        flags=cv2.CASCADE_SCALE_IMAGE
    )

faces = faceCascade.detectMultiScaledetecting related object
gray, gray scale
scaleFactor=1.1, scale the face
minNeighbors=5, number of objects
minSize=(30, 30), window size

Drawing the rectangle around the detacted face.

for (x, y, w, h) in faces:
 cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

Displaying the results

cv2.imshow('Video', frame)

Adding command to stop running the program

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

waiting to q key to pressed to exit.

When everything is done, release the capture

video_capture.release()
cv2.destroyAllWindows()

face-detection's People

Contributors

sumudu1st 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.