summaryrefslogtreecommitdiffstats
path: root/data/face-detect.py
diff options
context:
space:
mode:
Diffstat (limited to 'data/face-detect.py')
-rwxr-xr-xdata/face-detect.py36
1 files changed, 29 insertions, 7 deletions
diff --git a/data/face-detect.py b/data/face-detect.py
index dfc4256..78591d1 100755
--- a/data/face-detect.py
+++ b/data/face-detect.py
@@ -1,8 +1,10 @@
#!/usr/bin/python
import os
import sys
-from face_client import FaceClient
+from face_client import FaceClient, FaceError
import time
+from httplib import HTTPException
+from urllib2 import HTTPError
api_key = '34a84a7835bf24df2d84b4bded84e838'
api_secret = '5bc9e8c5a9e3a2d916abbe3659a1b3f8'
@@ -10,14 +12,18 @@ api_secret = '5bc9e8c5a9e3a2d916abbe3659a1b3f8'
client = FaceClient(api_key, api_secret)
runs = []
-for arg in sys.argv[2:]:
- runs += [[open(arg), sys.argv[1].rstrip('/') + '/' + arg.split('/')[-2] + '/']]
+runs += [[open(sys.argv[2]), sys.argv[1].rstrip('/') + '/' + sys.argv[2].split('/')[-2] + '/']]
def limits(client):
response = client.account_limits()
return response['remaining'],response['reset_time']
remaining,reset_time = limits(client)
+sframe = 0
+try:
+ sframe = int(sys.argv[3])
+except:
+ sframe = 0
for lines, pic_dir in runs:
for line in lines:
@@ -26,20 +32,36 @@ for lines, pic_dir in runs:
while remaining == 0:
time.sleep(max(reset_time - time.time(),0) + 10)
remaining,reset_time = limits(client)
- if frame != 'frame':
+ if frame != 'frame' and int(frame) > sframe:
img = open(pic_dir + frame + '.jpg')
- response = client.faces_detect(file=img)
- img.close()
+ response = None
+ while response == None:
+ try:
+ img = open(pic_dir + frame + '.jpg')
+ response = client.faces_detect(file=img)
+ img.close()
+ except (HTTPException, HTTPError):
+ sys.stderr.write("HTTP Exception\n")
+ time.sleep(5)
+ except FaceError:
+ sys.stderr.write("Face Exception\n")
+ sys.stderr.write(str(img))
+ time.sleep(5)
out = line[0:4]
+ tags = []
try:
+ sys.stderr.write(frame)
+ sys.stderr.write(str(response['photos'][0]['tags'])+"\n")
photo = response['photos'][0]
out += [str(len(photo['tags']))]
for tag in photo['tags']:
- out += [str(tag['width']),str(tag['height']),str(tag['center']['x']),str(tag['center']['y'])]
+ out += [str(tag['recognizable']),str(tag['width']),str(tag['height']),str(tag['center']['x']),str(tag['center']['y'])]
+ tags += [tag['tid']]
except:
sys.stderr.write("Unexpexted error:"+str(sys.exc_info()[0])+" "+frame)
out = line[0:4] + ['0']
print ','.join(out)
+ #client.tags_remove(tids=','.join(tags))
remaining -= 1
time.sleep(0.3)