Skip to content

Instantly share code, notes, and snippets.

@aymericdelab
Last active October 16, 2019 17:32
Show Gist options
  • Save aymericdelab/3af3e6ae0a3cb51069c4611b7520dfce to your computer and use it in GitHub Desktop.
Save aymericdelab/3af3e6ae0a3cb51069c4611b7520dfce to your computer and use it in GitHub Desktop.
import cv2
import requests
key1, Key2 = service.get_keys()
def get_founder(image_directory):
image=cv2.imread(image_directory)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=4,
minSize=(100, 100)
)
try:
if faces.shape[0]>1:
return print('too many faces on the picture')
except:
return print('no face detected in the picture')
for (x, y, w, h) in faces:
crop_img = gray[y:y+h, x:x+w]
resized_img=cv2.resize(crop_img,(28,28))
# send a random row from the test set to score
input_data = "{\"data\": [" + str(resized_img.tolist()) + "]}"
headers = {'Content-Type':'application/json', 'Authorization': 'Bearer ' + key1}
resp = requests.post(service.scoring_uri, input_data, headers=headers)
return print("prediction:", resp.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment