def checkface_online(filename):
i=0
img = cv2.imread(filename)
result_d=FaceAPI.detect(image_file=filename)
time.sleep(2)
if len(result_d)==3:
print result_d
if len(result_d)>3:
for i in range(0,len(result_d["faces"])):
face_token=result_d["faces"][i]["face_token"]
gender=result_d["faces"][i]["attributes"]["gender"]["value"]
age=result_d["faces"][i]["attributes"]["age"]["value"]
face_rectangle=result_d["faces"][i]["face_rectangle"]
x=face_rectangle["left"]
y=face_rectangle["top"]
w=face_rectangle["width"]
h=face_rectangle["height"]
img=cv2.rectangle(img,(x,y),(x+w,y+h),(0,225,225),2)
# cv2.imwrite('./img/shutter/{}.jpg'.format(filelist),img)
result_s=FaceAPI.searchTtoI(face_token=face_token)
time.sleep(1)
# print result_s
if len(result_s)==3:
print "result_s==3"
if i==0:
checkbody_n('./img/shutter/{}.jpg'.format(filelist))
if len(result_s)>3:
face_token=result_s["results"][0]["face_token"]
confidence=result_s["results"][0]["confidence"]
if confidence >= 80.00:
detail=detailface(face_token)
cur.execute("insert into io_data values('%s',%s,'%s','%s','%s','%s','%s')"%(filelist,detail[0],detail[1],confidence,gender,face_token,fileLists))
conn.commit()
ft=cv2.freetype.createFreeType2()
ft.loadFontData(fontFileName='./data/font/simhei.ttf',id =0)
ft.putText(img=img,text=detail[1], org=(x, y - 10), fontHeight=30,line_type=cv2.LINE_AA, color=(0,255,165), thickness=1, bottomLeftOrigin=True)
cv2.imwrite('./img/shutter/{}.jpg'.format(filelist),img)
if i==1:
checkbody_y('./img/shutter/{}.jpg'.format(filelist),face_token)
else:
print"Unknow face"
face_token=result_s["results"][0]["face_token"]
confidence=result_s["results"][0]["confidence"]
# random_ID=random.randint(100000000000,100000999999)
cv2.putText(img,"Unknow", (x, y - 10), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0,0,225), 2)
cur.execute("insert into io_data values('%s','None','None','%s','%s','%s','%s')"%(filelist,confidence,gender,face_token,fileLists))
conn.commit()
cv2.imwrite('./img/shutter/{}.jpg'.format(filelist),img)
if i==1:
checkbody_n('./img/shutter/{}.jpg'.format(filelist))
i=i+1
评论列表
文章目录