Exemple #1
0
    def __init__(self):
        self.size = (640, 480)

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

        # construct the face detector and allow the camera to warm
        # up
        self.fd = FaceDetector("cascades/haarcascade_frontalface_default.xml")
        time.sleep(0.1)
import os
from subprocess import call

setproctitle.setproctitle("FacialDetectProcess")
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-f", "--face", required = True,
	help = "path to where the face cascade resides")
args = vars(ap.parse_args())

faceimg = "/dev/shm/face.jpg"
facetext = "/dev/shm/face_text"
facelocation = "/dev/shm/face.txt"
faceframe = "/dev/shm/face_frame"
# construct the face detector
fd = FaceDetector(args["face"])

# keep looping
while True:
	if (os.path.exists(faceframe)):
		fX = 0
		fY = 0
		fW = 0
		fH = 0

		# grab the current frame
		print "reading image"
		gray = cv2.imread('/dev/shm/face.jpg',0)
		height, width = gray.shape #get resolution for plotting location to screen thirds in facedetect.py
		# detect faces in the image and then clone the frame
		# so that we can draw on it
Exemple #3
0
import numpy as np
import cv2
from pyimagesearch.facedetector import FaceDetector

fd = FaceDetector('cascades/haarcascade_frontalface_default.xml')

cap = cv2.VideoCapture(0)
scaling_factor = 0.5

# Load our overlay image: hat.png
hat_default = cv2.imread('images/crown.png', -1)

# Create the mask for the hat
orig_mask = hat_default[:, :, 3]

# Create the inverted mask for the hat
orig_mask_inv = cv2.bitwise_not(orig_mask)

# Convert hat image to BGR
# and save the original image size (used later when re-sizing the image)
hat = hat_default[:, :, 0:3]

orighatHeight, origHatWidth = hat.shape[:2]

while True:
    ret, frame = cap.read()
    frame = cv2.resize(frame,
                       None,
                       fx=scaling_factor,
                       fy=scaling_factor,
                       interpolation=cv2.INTER_AREA)
from __future__ import print_function
from pyimagesearch.facedetector import FaceDetector
import argparse
import cv2

ap = argparse.ArgumentParser()
ap.add_argument("-f",
                "face",
                required=True,
                help='path to where the face cascade resides')
ap.add_argument("-i",
                "image",
                required=True,
                help='path to where the image file resides')
args = vars(ap.parse_arg())

image = cv2.imread(args["image"])
gray = cv2.cvtColor(image, cv2.COLOER_BGR2GRAY)

fd = FaceDetector(args['face'])
faceRects = fd.detect(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
print("I found {} face(s)".format(len(faceRects)))

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

cv2.imshow('face', image)