<commit_before>from picamera.array import PiRGBArray
from picamera import picamera
import numpy as np
import cv2
import time

# Loads haar cascades for facial detection reference.\
face_cascade = cv2.CascadeClassifier(
    '/Users/ariveralee/opencv/data/lbpcascades/lbpcascade_frontalface.xml')


camera = PiCamera()						# initialize camera
camera.resolution = (320, 240)
camera.framerate = 30
rawCapture = PiRGBArray(camera, size=(320, 240))


count = 0 								# counter for face detection


time.sleep(0.1)							# allow camera to initialize

# Takes in each frame from the camera and converts it to OpenCv's BGR format
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True)
	img = frame.array
	gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
	faces = face_cascade.detectMultiScale(gray, 1.5, 3)
	
	if len(faces) != 0:					# not zero if a face is detected
		count += 1
	
	# Draws the rectangle around the face
	for (x, y, w, h) in faces:
		cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)



	cv2.imshow("Camera Feed", img)		# Uses a GUI to display each frame
	key = cv2.waitKey(1) & 0xFF			# Wait key to keep the video streaming
	rawCapture.truncate(0)				# removes each frame after it's displayed

	if count == 30:						# if the face was visible in 30 frames
		count = 0 						# reset the count
		print("Found a human")
	
	if key == ord("q"):					# Pressing q quits the program			
		break

print(count) 							# for Testing
cv2.destroyAllWindows() <commit_msg>created continuous loops, works as expected.<commit_after>from picamera.array import PiRGBArray
from gpiozero import MotionSensor
import picamera
import numpy as np
import cv2
import time

# Loads haar cascades for facial detection reference
face_cascade = cv2.CascadeClassifier(
    '/home/pi/opencv-3.1.0/data/lbpcascades/lbpcascade_frontalface.xml')

MIN_FACE_COUNT = 15                 # min frames before we detected a person
MIN_FRAMES = 450                    # frames needed w.o a face before we stop searching
FACE_COUNTER = 0                    # increments for each frame a face is found
NO_FACE = MIN_FRAMES                # when zero, shuts off camera.
EXIT_PROGRAM = 0                    # When 1, program quits
WINDOW_NAME = "Security feed"       # Window name for feed
MOTION_SENSOR = MotionSensor(4)     # motion sensor sends output to pin 4


def skynet():
    # runs indefinitely until we quit.
while True:
    print("Waiting for motion")
    # pauses program until motion is detected
    MOTION_SENSOR.wait_for_motion()
    print("Motion detected!")

    if MOTION_SENSOR.motion_detected == True:
        # create the camera object
        camera = picamera.PiCamera()
        camera.resolution = (640, 480)
        camera.framerate = 30
        rawCapture = PiRGBArray(camera, size=(640, 480))
        # allows camera to initialize
        time.sleep(0.1)

        # Takes in each frame from the camera and converts it to OpenCv's BGR
        # format. When a face is found in each frame, a rectangle is drawn.
        for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
            img = frame.array
            gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
            cv2.namedWindow(WINDOW_NAME)
            faces = face_cascade.detectMultiScale(gray, 1.5, 3)

            if len(faces) != 0:			# not zero if a face is detected
                FACE_COUNTER += 1
            elif len(faces) == 0:       # no face is found in current frame
                NO_FACE -= 1

            # Draws the rectangle around the face
            for (x, y, w, h) in faces:
                cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)

            # Uses a GUI to display each frame
            cv2.imshow(WINDOW_NAME, img)
            # Wait key to keep the video streaming
            key = cv2.waitKey(1) & 0xFF
            # removes each frame after it's displayed
            rawCapture.truncate(0)

            if FACE_COUNTER == MIN_FACE_COUNT:          # if the face was visible in 15 frames
                FACE_COUNTER = 0 			            # reset the FACE_COUNTER
                print("Found a human")

            # if we have not found a face in MIN_FRAMES, then the camera will
            # shut off and the program will begin looking for motion again.
            if NO_FACE == 0:
                print("False alarm")
                NO_FACE = MIN_FRAMES    # resets to original value
                cv2.destroyAllWindows()  # destroys gui window
                cv2.waitKey(10)         # waits forframes to be destroyed
                break                   # break from inner loop

            if key == ord("q"):			# Pressing q quits the program
                EXIT_PROGRAM = 1
                break                   # break from inner loop
    camera.close()                      # closes camera to reduce resources.

    if EXIT_PROGRAM == 1:               # if we pressed q, we want to exit.
        break

cv2.destroyAllWindows()                 # destroys gui window
return                                  # exit function
{'fraction_non_alphanumeric': 0.07651663405088063, 'fraction_numerical': 0.021526418786692758, 'mean_word_length': 2.1510480887792847, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '728577', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1482, 'n_words': 535}