import cv2

face_cascade = cv2.CascadeClassifier('/home/pi/opencv/data/haarcascades/haarcascade_frontalface_default.xml')

class VideoCamera(object):
	def __init__(self):
		self.video = cv2.VideoCapture(0)
	
	def __del__(self):
		self.video.release()
    
	def get_frame(self):
		success, image = self.video.read()
		faces = face_cascade.detectMultiScale(image, 1.3, 5)
		for (x, y, w, h) in faces:
			cv2.rectangle(image, (x, y), (x + w, y + h), (255, 0, 0), 2)
		
		ret, jpeg = cv2.imencode('.jpg', image)
		return jpeg.tobytes()
