Exemplo n.º 1
0
cascPath = 'Haar/haarcascade_frontalcatface.xml'

# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (160, 120)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(160, 120))

# allow the camera to warmup
time.sleep(0.1)
lastTime = time.time() * 1000.0
num = 0
id = Id.AddName()
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture,
                                       format="bgr",
                                       use_video_port=True):
    # grab the raw NumPy array representing the image, then initialize the timestamp
    # and occupied/unoccupied text
    image = frame.array
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    if (num > 200):
        break
    # Detect faces in the image
    faces = faceCascade.detectMultiScale(gray,
                                         scaleFactor=1.1,
                                         minNeighbors=5,
                                         minSize=(30, 30),
Exemplo n.º 2
0
from picamera.array import PiRGBArray
from picamera import PiCamera
import cv2
import numpy as np
import Id

camera = PiCamera()
camera.resolution = (160, 128)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(160, 128))
face_detector = cv2.CascadeClassifier('Haar/haarcascade_frontalcatface.xml')
eye_cascade = cv2.CascadeClassifier('Haar/haarcascade_eye.xml')
face_id = Id.AddName()
count = 0
WHITE = [255, 255, 255]
while (count < 200):
    ret, img = camera.capture_continuous(rawCapture,
                                         format="bgr",
                                         use_video_port=True)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    if np.average(gray) > 110:
        faces = face_detector.detectMultiScale(gray, 1.3, 5)
        for (x, y, w, h) in faces:
            Face = gray[y - int(h / 2):y + int(h * 1.5),
                        x - int(x / 2):x + int(w * 1.5)]
            eyes = (Id.DetectEyes(Face))
            cv2.putText(gray, "Face Detected", (x + (w / 2), y - 5),
                        cv2.FONT_HERSHEY_DUPLEX, .4, WHITE)
            if eyes is not None:
                frame = eyes
            else: