Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

opencv face detection code python webcam

import cv2
import sys

cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(0)

while True:
    # Capture frame-by-frame
    ret, frame = video_capture.read()

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

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

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

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

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

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

PREVIOUS NEXT
Code Example
Python :: python split dict into chunks 
Python :: browser refresh selenium python 
Python :: pil image from numpy 
Python :: delete row from dataframe python 
Python :: virtual env 
Python :: remove consecutive duplicates python 
Python :: how to add scrollbar to listbox in tkinter 
Python :: adaptive thresholding 
Python :: python endswith list 
Python :: standard module 
Python :: pandas column not in list 
Python :: convert letters to numbers in python 
Python :: update python in cmd 
Python :: read all text file python 
Python :: how to save a dictionary as a file in python 
Python :: django import timezone 
Python :: df to np array 
Python :: jupyter notebook extensions 
Python :: rotatable list python 
Python :: how to empty a text file in python 
Python :: cv2.GaussianBlur() 
Python :: python intersection of two lists 
Python :: python class tostring 
Python :: normalize = true pandas 
Python :: discord.py check if user has role 
Python :: kivy window size 
Python :: convert hex to decimal python 
Python :: remove whitespace in keys from dictionary 
Python :: array search with regex python 
Python :: comparing file content in python 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =