Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions vighc/OpenPose_Position_Detection_Using_Google_Colab.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "OpenPose Position Detection Using Google Colab.ipynb",
"provenance": [],
"authorship_tag": "ABX9TyNIBRPADxq8FQCMR8XJXhBq",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/vighc/GoogleColab_OpenPose/blob/master/OpenPose_Position_Detection_Using_Google_Colab.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "dZNUxOvLTS5E",
"colab_type": "text"
},
"source": [
"Build OpenPose \n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "XYPD-k9mTZU2",
"colab_type": "code",
"colab": {}
},
"source": [
"import os\n",
"from os.path import exists, join, basename, splitext\n",
"\n",
"git_repo_url = 'https://github.com/CMU-Perceptual-Computing-Lab/openpose.git'\n",
"project_name = splitext(basename(git_repo_url))[0]\n",
"if not exists(project_name):\n",
" # see: https://github.com/CMU-Perceptual-Computing-Lab/openpose/issues/949\n",
" # install new CMake becaue of CUDA10\n",
" !wget -q https://cmake.org/files/v3.13/cmake-3.13.0-Linux-x86_64.tar.gz\n",
" !tar xfz cmake-3.13.0-Linux-x86_64.tar.gz --strip-components=1 -C /usr/local\n",
" # clone openpose\n",
" !git clone -q --depth 1 $git_repo_url\n",
" !sed -i 's/execute_process(COMMAND git checkout master WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}\\/3rdparty\\/caffe)/execute_process(COMMAND git checkout f019d0dfe86f49d1140961f8c7dec22130c83154 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}\\/3rdparty\\/caffe)/g' openpose/CMakeLists.txt\n",
" # install system dependencies\n",
" !apt-get -qq install -y libatlas-base-dev libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libgflags-dev libgoogle-glog-dev liblmdb-dev opencl-headers ocl-icd-opencl-dev libviennacl-dev\n",
" # install python dependencies\n",
" !pip install -q youtube-dl\n",
" # build openpose\n",
" !cd openpose && rm -rf build || true && mkdir build && cd build && cmake .. && make -j`nproc"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "sGwXNZgHTcul",
"colab_type": "text"
},
"source": [
"Import YouTube Video"
]
},
{
"cell_type": "code",
"metadata": {
"id": "cjMlfFnhTsaP",
"colab_type": "code",
"colab": {}
},
"source": [
"from IPython.display import YouTubeVideo\n",
"\n",
"\n",
"YOUTUBE_ID = 'eDq2vE5OT2M'\n",
"YouTubeVideo(YOUTUBE_ID)"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "tXYvWBkVT9o-",
"colab_type": "text"
},
"source": [
"Download YouTube Video and save Starting 20 sec"
]
},
{
"cell_type": "code",
"metadata": {
"id": "csyMr1U3T-Cg",
"colab_type": "code",
"colab": {}
},
"source": [
"!rm -rf youtube.mp4\n",
"# download the youtube with the given ID\n",
"!youtube-dl -f 'bestvideo[ext=mp4]' --output \"youtube.%(ext)s\" https://www.youtube.com/watch?v=$YOUTUBE_ID\n",
"# cut the first 20 seconds\n",
"!ffmpeg -y -loglevel info -i youtube.mp4 -t 20 video.mp4\n",
"# detect poses on the these 20 seconds\n",
"!rm openpose.avi\n",
"!cd openpose && ./build/examples/openpose/openpose.bin --video ../video.mp4 --write_json ./output/ --display 0 --write_video ../openpose.avi\n",
"# convert the result into MP4\n",
"!ffmpeg -y -loglevel info -i openpose.avi output.mp4"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "1f9C4bX5UWWO",
"colab_type": "text"
},
"source": [
"Export the video"
]
},
{
"cell_type": "code",
"metadata": {
"id": "hSZJw82LUaDh",
"colab_type": "code",
"colab": {}
},
"source": [
"def show_local_mp4_video(file_name, width=640, height=480):\n",
" import io\n",
" import base64\n",
" from IPython.display import HTML\n",
" video_encoded = base64.b64encode(io.open(file_name, 'rb').read())\n",
" return HTML(data='''<video width=\"{0}\" height=\"{1}\" alt=\"test\" controls>\n",
" <source src=\"data:video/mp4;base64,{2}\" type=\"video/mp4\" />\n",
" </video>'''.format(width, height, video_encoded.decode('ascii')))\n",
"\n",
"show_local_mp4_video('output.mp4', width=960, height=720)"
],
"execution_count": 0,
"outputs": []
}
]
}
15 changes: 15 additions & 0 deletions vighc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# GoogleColab_OpenPose
OpenPose Position Detection Using Google Colab



Step 1 : Take time to Build the OpenPose model

Step 2 : Select Youtube Video

Step 3 : Paste the ID of a YouTube Video

Step 4 : Run the Program

![](output.gif)

Binary file added vighc/output.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.