Created
December 2, 2016 18:03
-
-
Save grigorisg9gr/55015fcc8718592e1451ff6177558ec5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# Imports a video, acquires some frames and \n", | |
"# performs (face) detection in those." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"from os.path import isdir, isfile\n", | |
"from functools import partial\n", | |
"from numpy.random import randint\n", | |
"import menpo.io as mio\n", | |
"from menpo.visualize import print_progress\n", | |
"from menpodetect.dlib import load_dlib_frontal_face_detector\n", | |
"\n", | |
"try:\n", | |
" %matplotlib inline\n", | |
" from menpowidgets import visualize_images\n", | |
"except NameError:\n", | |
" print('Maybe this is a terminal.')\n", | |
" pass" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Parse the video" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"p = '/vol/atlas/homes/grigoris/videos_external/5_2016_kollias_dimitris/part_c/450_500/mp4/453BeatDropVines3Reaction.avi'\n", | |
"assert isfile(p)\n", | |
"v = mio.import_video(p, landmark_resolver=None, normalize=False)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Import video frames" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"max_frames = 20\n", | |
"ims = []\n", | |
"for i in range(min(max_frames, len(v))):\n", | |
" idx = randint(0, high=len(v))\n", | |
" ims.append(v[idx])" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Detect and visualise the results" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"detector = partial(load_dlib_frontal_face_detector())\n", | |
"for im in print_progress(ims):\n", | |
" detector(im)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"visualize_images(ims)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.4.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment