In [27]:
from PIL import Image
import face_recognition
import matplotlib.pyplot as plt
import cv2
import numpy as np
%matplotlib inline
In [2]:
image = face_recognition.load_image_file('biden.jpg')
In [3]:
type(image)
Out[3]:
In [4]:
face_locations = face_recognition.face_locations(image)
In [5]:
len(face_locations)
Out[5]:
In [7]:
plt.imshow(image)
Out[7]:
In [21]:
cv2.rectangle?
In [63]:
img = np.ones((750, 970, 3), dtype=np.uint8)
top, right, bottom, left = (243, 740, 562, 419)
cv2.rectangle(img, (left, top), (right,bottom), (0, 255, 0), 2)
# cv2.rectangle(img, (200, 500), (600, 750), (0, 255, 0), 5)
plt.imshow(img)
img = Image.fromarray(img)
img.save('test.jpg')
In [59]:
# Create a black image
img = np.zeros((512,512,3), np.uint8)
# Draw a diagonal blue line with thickness of 5 px
cv2.line(img,(0,0),(511,511),(255,0,0),5)
cv2.rectangle(img,(384,0),(510,128),(0,255,0),3)
cv2.circle(img,(447,63), 63, (0,0,255), -1)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img,'OpenCV',(10,500), font, 4,(255,255,255),2,cv2.LINE_AA)
plt.imshow(img)
Out[59]:
In [34]:
image = face_recognition.load_image_file('biden.jpg')
print('image shape', image.shape)
for face_location in face_locations:
top, right, bottom, left = face_location
print(face_location)
face_image = image[top:bottom, left:right]
f = plt.figure()
plt.imshow(face_image)
cv2.rectangle(image, (left, top), (right, bottom), (0, 0, 255), 5)
# cv2.rectangle(image, (top,left), (bottom, right), (0, 0, 255), 5)
# (x,y), (x+w, y+h)
f = plt.figure()
plt.imshow(image)
In [26]:
biden_face_encoding = face_recognition.face_encodings(image)[0]
In [11]:
biden_face_encoding.shape
Out[11]:
In [12]:
obama_image = face_recognition.load_image_file("obama.jpg")
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
print(obama_face_encoding.shape)
In [14]:
face_recognition.compare_faces([biden_face_encoding], obama_face_encoding)
Out[14]:
In [ ]: