sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential cmake gfortran git wget curl graphicsmagick libgraphicsmagick1-dev libatlas-dev libavcodec-dev libavformat-dev libboost-all-dev libgtk2.0-dev libjpeg-dev liblapack-dev libswscale-dev pkg-config python3-dev python3-numpy python3-pip zip
sudo apt-get clean
# import the necessary packagesfrom imutils import face_utilsimport dlibimport cv2import urllib.request
# initialize dlib's face detector (HOG-based) and then create# the facial landmark predictorurllib.request.urlretrieve("http://mgt.tmu.edu.tw/~TMU_MGT/files/archive/491_11d37e36.jpg", "face.jpg")p = "shape_predictor_68_face_landmarks.dat"detector = dlib.get_frontal_face_detector()predictor = dlib.shape_predictor(p)
# load the input image and convert it to grayscaleimage = cv2.imread("face.jpg")gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# detect faces in the grayscale imagerects = detector(gray, 0)
# loop over the face detectionsfor (i, rect) in enumerate(rects): # determine the facial landmarks for the face region, then # convert the facial landmark (x, y)-coordinates to a NumPy # array shape = predictor(gray, rect) shape = face_utils.shape_to_np(shape)
# loop over the (x, y)-coordinates for the facial landmarks # and draw them on the image for (x, y) in shape: cv2.circle(image, (x, y), 2, (0, 255, 0), -1)
# show the output image with the face detections + facial landmarkscv2.imshow("Output", image)cv2.waitKey(0)https://beta.deepnote.org/launch?template=face_recognition Jupyter User Interface
import face_recognitionfrom matplotlib.pyplot import imshowimport matplotlib.pyplot as plt
import urllib.request
urllib.request.urlretrieve("https://images.unsplash.com/photo-1534559529872-1a83a6cbc03d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1924&q=80", "face.jpg")image = face_recognition.load_image_file("face.jpg")f, [ax1, ax2] = plt.subplots(nrows=1, ncols=2, figsize=(15,15))
ax1.imshow(image)
imageface_locations = face_recognition.face_locations(image)imageface_locations
face_landmarks_list = face_recognition.face_landmarks(image)face_landmarks_list
from PIL import Image, ImageDraw# import face_recognition
# Load the jpg file into a numpy array# image = face_recognition.load_image_file("face.jpg")
# Find all facial features in all the faces in the imageface_landmarks_list = face_recognition.face_landmarks(image)
pil_image = Image.fromarray(image)for face_landmarks in face_landmarks_list: d = ImageDraw.Draw(pil_image, 'RGBA')
# Make the eyebrows into a nightmare d.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128)) d.polygon(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 128)) d.line(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 150), width=5) d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=5)
# Gloss the lips d.polygon(face_landmarks['top_lip'], fill=(150, 0, 0, 128)) d.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128)) d.line(face_landmarks['top_lip'], fill=(150, 0, 0, 64), width=8) d.line(face_landmarks['bottom_lip'], fill=(150, 0, 0, 64), width=8)
# Sparkle the eyes d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30)) d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30))
# Apply some eyeliner d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=6) d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110), width=6)
ax2.imshow(pil_image)