forked from mrhwick/redcarpet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recognition.py
51 lines (38 loc) · 1.4 KB
/
recognition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from audio import Audio
import os
from facepp import File, API
SERVER = 'http://api.us.faceplusplus.com/'
API_KEY = '83512035a89abd3721230e94caea54c4'
API_SECRET = 'Mv2y5KogIgHyvtv9vj2fn9BawJCNkj_-'
class Recognize(object):
def __init__(self):
self.audio = Audio()
self.people={
'Anthony Blardo': 'downfall.wav',
'Matt Hardwick': 'fall.wav',
'Daniel Hawkins': 'media.wav',
'Allan Davis': 'vader.wav',
'Tiffanie Robinson': 'girl.wav',
}
def is_person(self, image_file):
path = 'media/image/face.png'
# path = os.path.join('media/image/', image_file.filename)
image_file.save(path)
# import ipdb; ipdb.set_trace()
f = File(path)
api = API(API_KEY, API_SECRET, SERVER)
print("Sending face to api")
response = api.recognition.identify(group_name='Hackathoners', img=f)
print(response)
faces = response['face']
if len(faces) > 0:
face = faces[0]
name = face['candidate'][0]['person_name']
if name in self.people.keys():
print("Found " + name)
self.audio.add_to_playlist(self.people[name])
self.audio.play()
else:
self.audio.add_to_playlist('run.wav')
self.audio.play()
print("Did not match a person.")