Michael-BJ / Face-recognation-using-opencv

The program that can recognize the face using the OpenCV library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How it's works

  1. First dowload library opencv and numpy
pip install opencv-python
pip install numpy
  1. Make the program to connect to the webcam
import cv2
import numpy as np

cap = cv2.VideoCapture(0)
while True:
    _, frame = cap.read()
    cv2.imshow('just face', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

cap.release()
cv2.destroyAllWindows()
  1. Download the model for face, that is haarcascade_frontalface_default.xml
  2. Write the code to translate the model
face_detect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
  1. Load the image in grayscale
frame = cv2.imread('', cv2.IMREAD_GRAYSCALE)

By changing to gray, the program will be easier to learn

  1. Turn the picture to gray color
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  1. To make a rectangle, use this code
    for (x, y, w, h) in faces :
        cv2.rectangle(frame,(x,y), (x+w,y+h),(0,255,0),2)

Demo

Clik the picture to see the Video Watch the video

About

The program that can recognize the face using the OpenCV library


Languages

Language:Python 100.0%