{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Face detection in a couple of lines with dlib"},{"metadata":{},"cell_type":"markdown","source":"To install dlib without internet, add the dataset: https://www.kaggle.com/carlossouza/dlibpkg"},{"metadata":{"trusted":true,"collapsed":true},"cell_type":"code","source":"!pip install '/kaggle/input/dlibpkg/dlib-19.19.0'","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport cv2\nfrom matplotlib import pyplot as plt\nimport dlib","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%%time\nsample = '/kaggle/input/deepfake-detection-challenge/train_sample_videos/aagfhgtpmv.mp4'\n\nreader = cv2.VideoCapture(sample)\n_, image = reader.read()\nimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n\nface_detector = dlib.get_frontal_face_detector()\ngray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\nfaces = face_detector(gray, 1)\nif len(faces) > 0:\n    face = faces[0]\n    \nface_image = image[face.top():face.bottom(), face.left():face.right()]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 4))\nax1.imshow(image)\nax1.xaxis.set_visible(False)\nax1.yaxis.set_visible(False)\n\nax2.imshow(face_image)\nax2.xaxis.set_visible(False)\nax2.yaxis.set_visible(False)\n\nplt.grid(False)\nplt.tight_layout()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}