diff --git a/python/tasks/mlb_player.py b/python/tasks/mlb_player.py index b870f88..cd0e836 100644 --- a/python/tasks/mlb_player.py +++ b/python/tasks/mlb_player.py @@ -2192,3 +2192,103 @@ def kernel_35(): 8. https://github.com/CMU-Perceptual-Computing-Lab/openpose https://github.com/CMU-Perceptual-Computing-Lab/openpose/issues/1736#issuecomment-736846794 ''' + +def kernel_36(): + # -*- coding: utf-8 -*- + """OpenPose.ipynb + + Automatically generated by Colaboratory. + + Original file is located at + https://colab.research.google.com/drive/1VDjRLKAu9KLQky0gv4RLJjeH6NRPiWXy + """ + + assert os.system(r''' + cd openpose && rm -rf build || true && mkdir build && cd build && cmake .. && make -j`nproc` + ''') == 0 + + """# Pose Detection with OpenPose + + This notebook uses an open source project [CMU-Perceptual-Computing-Lab/openpose](https://github.com/CMU-Perceptual-Computing-Lab/openpose.git) to detect/track multi person poses on a video from your Google Drive + + @dinatih update base on https://colab.research.google.com/github/tugstugi/dl-colab-notebooks/blob/master/notebooks/OpenPose.ipynb + + ## Choose a video from your Google Drive + """ + + from google.colab import drive + drive.mount('/content/drive') + + """## Install OpenPose on Google Colab + + """ + + import os + from os.path import exists, join, basename, splitext + + git_repo_url = 'https://github.com/CMU-Perceptual-Computing-Lab/openpose.git' + project_name = splitext(basename(git_repo_url))[0] + + if 1 or not exists(project_name): + assert os.system(r'''!rm -rf openpose''') == 0 + # see: https://github.com/CMU-Perceptual-Computing-Lab/openpose/issues/949 + print("install new CMake becaue of CUDA10") + cmake_version = 'cmake-3.20.2-linux-x86_64.tar.gz' + if not exists(cmake_version): + assert os.system(r'''!wget -q 'https://cmake.org/files/v3.20/{cmake_version}' ''') == 0 + assert os.system(r'''!tar xfz {cmake_version} --strip-components=1 -C /usr/local ''') == 0 + + print("clone openpose") + assert os.system(r'''!git clone -q --depth 1 $git_repo_url ''') == 0 + print("install system dependencies") + assert os.system(r'''!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 ''') == 0 + print("build openpose") + assert os.system(r'''!cd openpose && rm -rf build || true && mkdir build && cd build && cmake .. && make -j`nproc` ''') == 0 + + """## From a Google Drive's folder""" + + import os + from os.path import exists, join, basename, splitext + + folder_path = '/content/drive/My Drive/openpose/' + files = os.listdir(folder_path) + files.reverse() + for filename in files: + if filename.endswith('.mp4') and not filename.endswith('-openpose.mp4'): + print(filename) + colab_video_path = folder_path + filename + print(colab_video_path) + colab_openpose_video_path = colab_video_path.replace('.mp4', '') + '-openpose.mp4' + print(colab_openpose_video_path) + if not exists(colab_openpose_video_path): + !cd openpose && ./build/examples/openpose/openpose.bin --hand --face --number_people_max 12 --video '{colab_video_path}' --display 0 --write_video_with_audio --write_video '{colab_openpose_video_path}' # --net_resolution "-1x736" --scale_number 4 --scale_gap 0.25 + + """## From Youtube (Downloaded to your Drive)""" + + !pip install youtube-dl + + youtube_id = '2021-05-07_22-00-55_UTC' + !youtube-dl -f mp4 -o '/content/drive/My Drive/openpose/%(id)s.mp4' {youtube_id} + colab_video_path = '/content/drive/My Drive/openpose/' + youtube_id + '.mp4' + colab_openpose_video_path = colab_video_path.replace('.mp4', '') + '-openpose.mp4' + + !cd openpose && ./build/examples/openpose/openpose.bin --number_people_max 12 --video '{colab_video_path}' --display 0 --write_video_with_audio --write_video '{colab_openpose_video_path}' # --net_resolution "-1x736" --scale_number 4 --scale_gap 0.25 + + + + """## Run OpenPose""" + + assert os.system(r'''!wget 'https://cdn-eu-hz-4.ufile.io/get/z5yes0he?token=ZWUyZjMyNDBmNTRlMWY0NjRkZTUzYzQzNjg2OWY4ODgzMzA1ODFjNzY0YzYxYWFjNzM1ZTU2OWYwNzQyNzVkOWUwYjY3MjdiZmI1MDg0NmIyMzA3ODhiZmQ2YmI3ZWYyOTE3NDBlNDEwY2JlZTc5N2MwMmIxYjYzZGJjYTZjYzl3K3dtK25xdXE2M1ZUZXZMUU5CYzI0WjBtUEk4OTJQYzFvaTJXa1huRkdtNlhjZGxlTHkvTEJVNVlucnBOZFdHMXBiVkszeHBKWEFaTzRKK1h4Zy9BRDNvbkttNDhJVXRKZjJuSUIyTDVaR0UydjM3amtVdE93aFQ4ZXFGTlZYeVZiTXQwT3pkOEdLTklQRUhZNmR1MHRPeVdMb3ZHRWV3R3BYWStQcElkeUdDTkVvUU1IRTUxaE1acDlCM3htRDBaS2ZjWEpLMXlpNXRWUWdLWEoreld3N3VvLy9ocXE2RUxPS2pDdENtVjB0Zi9qWGh3WEIwK3RzU0xZekloK3k2' -O output.mp4 ''') == 0 + + # video_folder = os.path.dirname(colab_video_path) + # video_base_name = os.path.basename(colab_video_path) + # print(video_base_name) + import os + from os.path import exists, join, basename, splitext + #colab_video_path = '/content/drive/My Drive/bachata.mp4' + colab_video_path = '/content/output.mp4' + colab_openpose_video_path = colab_video_path.replace('.mp4', '') + '-openpose.mp4' + + assert os.system(r'''!cd openpose && ./build/examples/openpose/openpose.bin --number_people_max 12 --video '{colab_video_path}' --display 0 --write_video_with_audio --write_video '{colab_openpose_video_path}' # --net_resolution "-1x736" --scale_number 4 --scale_gap 0.25 ''') == 0 + + assert os.system(r'''!cmake -version ''') == 0