예제 #1
0
파일: main.py 프로젝트: gutorc92/unb
def main(argv=sys.argv):
	f = Face()
	n = Net()
	o = Output()
	if(len(argv) >= 2):
		argv.pop(0)
		for arg in argv:
			print(arg)
			d = Input(arg)
			o.outFaces(f.detect(d.getImage(Input.FACES)))
			dogs,cats = n.result(d.getImage(Input.PREDICTION))
			o.outAnimals(dogs,cats)
예제 #2
0
 def get_detected_faces(self, bounding_boxes, points):
     detected_faces = []
     # the number of boxes indicates the number of faces detected
     for i in range(len(bounding_boxes)):
         bbox = bounding_boxes[i][:4]
         score = bounding_boxes[i][4:]
         detected_face = Face()
         detected_face.face_rectangle = bbox.tolist()
         landmarks = []
         for p in range(len(points)):
             landmarks.append(float(points[p][i]))
         detected_face.face_landmarks = landmarks
         detected_face.confidence = score[0]
         detected_faces.append(detected_face)
     return detected_faces
예제 #3
0
def get_faces(photo):
    import Algorithmia
    import base64
    Algorithmia.apiKey = os.environ.get('ALGORITHMIA_KEY')

    with default_storage.open(photo.img.name, 'rb') as img:
        b64 = base64.b64encode(img.read())

    rectangles = Algorithmia.algo("/ANaimi/FaceDetection/0.1.2").pipe(b64)

    faces = []
    for rect in rectangles:
        face = Face()
        face.photo = photo
        face.name = '?'
        face.x = rect['x']
        face.y = rect['y']
        face.width = rect['width']
        face.height = rect['height']
        face.save()
        faces.append(face)
    return faces
예제 #4
0
def get_faces(path):
    print "getting faces"
    path = MEDIA_ROOT + "/" + path
    with open(path, 'rb') as img:
        bimage = base64.b64encode(img.read())

    Algorithmia.apiKey = 'Simple totally_real_api_key'
    result = Algorithmia.algo('/ANaimi/FaceDetection').pipe(bimage)

    faces = []
    for rect in result:
        print "found face"
        face = Face()
        face.name = "Anon"
        face.x = rect['x']
        face.y = rect['y']
        face.width = rect['width']
        face.height = rect['height']
        faces.append(face)
        Face.save(face)
    return faces
예제 #5
0
def get_frames(user_id):
    """Video streaming generator function."""
    video = cv2.VideoCapture(0)
    while True:
        rval, frame = video.read()
        if not rval:
            load_faces()
            break
        else:
            new_frame = frame[:, :, ::-1]
            locations, face_encodings = get_face(new_frame)
            print(locations)
            f = pickle.dumps(face_encodings)
            if face_encodings is not None:
                face = Face(user_id, f)
                db.session.add(face)
                db.session.commit()
                top, right, bottom, left = locations
                cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255),
                              2)
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' +
               cv2.imencode('.jpg', frame)[1].tostring() + b'\r\n')