forked from MrBents/senior_design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFE_branch.py
81 lines (65 loc) · 2.04 KB
/
FE_branch.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import numpy
import urllib3
import urllib
import time
import cv2
from datetime import datetime, timedelta
import base64
import json
import requests
import os, os.path
class FeatureExtraction:
def __init__(self):
self.fpp = Facepp()
self.frame_counter = 1
self.start_time = self.now()
self.delta = timedelta(seconds=1.2)
self.block = False
self.counter = len(
[name for name in os.listdir("./imgs/") if os.path.isfile(name)]
)
def now(self):
return datetime.now()
def parse_frame(self, frame):
# if self.now() - self.start_time > self.delta and not self.block:
self.block = True
self.counter += 1
path = "./imgs/mmegg " + str(self.counter) + ".jpeg"
cv2.imwrite(path, frame)
try:
data = self.fpp.parse_frame(path)
print(data)
return data
except Exception as e:
print(e)
self.start_time = self.now()
self.block = False
class Facepp:
def __init__(self):
self.http_url = "https://api-us.faceplusplus.com/facepp/v3/detect"
self.key = "LX2oRHchELnqIswcEGQMCpMslc05lE7m"
self.secret = "4sK29DKX4gJrJ-wv9l4RQyR0VlQQS9Mw"
self.http = urllib3.PoolManager()
def getBaseFormat(self):
data_dict = {}
data_dict["api_key"] = self.key
data_dict["return_attributes"] = "gender,age,ethnicity"
data_dict["api_secret"] = self.secret
return data_dict
def parse_frame(self, path):
querystring = self.getBaseFormat()
files = {
"image_file": ("whatever.jpg", open(path, "rb")),
"Content-Type": "image/jpeg",
}
try:
# post data to server
resp = requests.request(
"POST", self.http_url, files=files, params=querystring
)
qrcont = resp.text
jason = json.loads(qrcont)
print(jason)
return jason["faces"]
except Exception as e:
print(e)