OpenCV and Riksdag
Incomplete notebook
%%capture
!pip install opencv-python
!pip install dlib
!pip install face_recognition
%%capture
!wget https://mhdownload.riksdagen.se/VOD1/188373_20000_965995.mp4
SAMPLE = "188373_20000_965995.mp4"
import face_recognition
import cv2
video = cv2.VideoCapture(SAMPLE)
frameno = 1
detections = []
while True:
ret, frame = video.read()
try:
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
except:
frameno += 1
continue
face_locations = face_recognition.face_locations(small_frame, model="cnn")
locations = []
for top, right, bottom, left in face_locations:
current = {}
current["top"] = top * 4
current["right"] = right * 4
current["bottom"] = bottom * 4
current["left"] = left * 4
locations.append(current)
# skip empty output
if len(locations) != 0:
current_frame = {}
current_frame["frame"] = frameno
current_frame["detections"] = locations
detections.append(current_frame)
frameno += 1
detections