- Read Image File
%%
% replace `PATH_TO_IMAGE` with actual image file path
%
impath = 'PATH_TO_IMAGE';
import argparse | |
import datetime | |
import imutils | |
import math | |
import cv2 | |
import numpy as np | |
width = 800 | |
textIn = 0 | |
textOut = 0 |
# import libraries here | |
import dlib | |
import face_recognition | |
# print the version of library | |
print(dlib.__version__) | |
print(face_recognition.__version__) |
# import required packages | |
import dlib | |
import cv2 | |
# only for google colab | |
# from google.colab.patches import cv2_imshow | |
# load the image to be detected | |
image = cv2.imread('images/modi-obama-1.jpg') |
# import required packages | |
import dlib | |
import cv2 | |
# only for google colab | |
# from google.colab.patches import cv2_imshow | |
# for using your inbuilt webcam | |
# Get the webcam #0 ( the default one, 1, 2 and so on) | |
# video_stream = cv2.VideoCapture(0) |
# load the image to be detected | |
image = cv2.imread('test/family.jpg') | |
# find all face locations using face_locations() function | |
# model can be "cnn" or "hog" | |
# number_of_times_to_upsample = 1 higher and detect more smaller faces from the image | |
all_face_locations = face_recognition.face_locations(image, model="hog") | |
#printing the number of faces in the array | |
print("There are {} face(s) in this image".format(len(all_face_locations))) |
•
├── test
│ ├── modi-obama-1.jpg
│ ├── modi-obama-2.jpg
│ └── face-demographics-walking.mp4
├── models
│ ├── facial_expression_model_weights.h5
│ └── facial_expression_model_structure.json
├── facial-expression-recognition-from-image.py
# capture the video from default camera | |
# video_stream = cv2.VideoCapture(0) | |
# read video from video file | |
video_file_path = 'test/face-demographics-walking.mp4' | |
video_stream = cv2.VideoCapture(video_file_path) | |
# initialize the number of frame needed to be skipped | |
skip = 0 |