Skip to content

Instantly share code, notes, and snippets.

@Nevin243
Created May 12, 2020 15:21
Show Gist options
  • Save Nevin243/c00b1d4622933394ea2280636e5a05de to your computer and use it in GitHub Desktop.
Save Nevin243/c00b1d4622933394ea2280636e5a05de to your computer and use it in GitHub Desktop.
OpenCV and Rekognition
import numpy as np
import cv2
import boto3
import json
# Rekognition Detect faces
def detect_faces(photo):
client=boto3.client('rekognition')
response = client.detect_faces(
Image={
'Bytes': photo
},
Attributes=[
'ALL'
]
)
return response
cam = cv2.VideoCapture(0)
cv2.namedWindow("test")
while True:
ret, frame = cam.read()
cv2.imshow("test", frame)
if not ret:
break
k = cv2.waitKey(1)
if k%256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
elif k%256 == 32:
# SPACE pressed
print(detect_faces(cv2.imencode('.jpg', frame)[1].tostring()))
# Release control of the webcam and close window
cam.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment