Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python face recognition

import cv2

video_capture = cv2.VideoCapture(0)

# Loading the required haar-cascade xml classifier file, classifies face from non face
haar_cascade = cv2.CascadeClassifier('Haarcascade_frontalface_default.xml')
print(haar_cascade)
while True:
    # Capture frame-by-frame
    ret, img = video_capture.read()

    # Converting image to grayscale, detection model sees it as grayscale
    gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    
    # Applying the face detection method on the grayscale image
    faces_rect = haar_cascade.detectMultiScale(gray_img, 1.1, 9)
    
    # Iterating through rectangles of detected faces, displaying the rectangle
    for (x, y, w, h) in faces_rect:
        cv2.rectangle(img, (x, y), (x+w, y+h), (70, 0, 255), 2)

    # Display the resulting frame
    cv2.imshow('Video', img)

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

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
Comment

python face recognition

# simple python code: face recognition
import cv2
import numpy as np

detect = cv2.CascadeClassifier(cv2.data.haarcascades +'haarcascade_frontalface_default.xml')

cam = cv2.VideoCapture('image.jpg')
check, img = cam.read()

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detect.detectMultiScale(gray,1.2,5)

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

cv2.imshow('Face Detect', img)
cv2.waitKey(600000)

cam.release()
cv2.destroyAllWindows()
Comment

PREVIOUS NEXT
Code Example
Python :: isinstance python 
Python :: access first element of dictionary python 
Python :: dummy variables pandas 
Python :: checking if a string contains a substring python 
Python :: how to know the python pip module version 
Python :: python array extend 
Python :: pythob password generator 
Python :: how to append items to a list in python 
Python :: read a file with pandas 
Python :: python open file for reading and writing 
Python :: how to run terminal commands in python 
Python :: add place in certain index python string 
Python :: python count occurrences of an item in a list 
Python :: tqdm range python 
Python :: fasttext python 
Python :: How to join two dataframes by 2 columns so they have only the common rows? 
Python :: fibonacci series list comphrehension in python 
Python :: discord py check if user has permission return message if not 
Python :: value_counts with nan 
Python :: Get Time from timestamp in python 
Python :: unique values in dataframe column count 
Python :: sqlalchemy filter between dates 
Python :: play video in colab 
Python :: pow python 
Python :: NumPy unique Example Get the unique rows and columns 
Python :: new dataframe based on certain row conditions 
Python :: write a file python 
Python :: Python NumPy swapaxis Function Example 
Python :: python for/else 
Python :: use python dotenv 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =