Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
microsoft face api face_verification.py
import cv2
from os import system
import cognitive_face as CF
from utils import *
import config as CFG
CF.Key.set(CFG.KEY)
BASE_URL = 'https://canadacentral.api.cognitive.microsoft.com/face/v1.0'
CF.BaseUrl.set(BASE_URL)
def show_webcam(mirror=False):
cam = cv2.VideoCapture(0)
while True:
ret_val, frame = cam.read()
if mirror:
frame = cv2.flip(frame, 1)
cv2.imshow('mirrorMIRRORonTHEwall', frame)
if cv2.waitKey(1) == 27:
break # esc to take photo
img_counter = 0
img_name = "webcam_{}.jpeg".format(img_counter)
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name))
#img_counter += 1
with open('webcam_0.jpeg', 'rb') as f:
data = f.read()
reference_target = 'https://snowplowanalytics.com/assets/img/team/vincent.png'
img_urls = [reference_target,data]
faces = [CF.face.detect(img_url) for img_url in img_urls]
similarity = CF.face.verify(faces[0][0]['faceId'], faces[1][0]['faceId'])
if similarity['confidence'] > 0.60:
text = get_fortune(compliments, moar)
system('say '+text.replace("'",""))
def main():
show_webcam(mirror=True)
cv2.destroyAllWindows()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.