Giter VIP home page Giter VIP logo

video-depthify's Introduction

Video-Depthify

Collection of scripts for generating depth maps for videos using machine learning.

Running on Google Colab

You can run the whole process directly from your browser without setting anything up locally, thanks to Google Colab.

Open In Colab

June 2021 update

Use the following Colab notebook to use BoostingMonocularDepth instead of MiDaS for even more detailed (and slower) depth maps.

Open In Colab

Running locally

Requirements

  • Python/Conda 3 environment (virtualenv recommended)

pip3 install torch torchvision opencv-python timm Pillow numpy

  • ffmpeg
  • Unix system recommended (WSL on Windows)

Setup

  1. Copy depth.py, average.py and merge.py into a folder with the video you wish to depthify. In our case we are using a short, royalty-free video of an elephant.
  2. In the same folder, create empty folders rgb, depth, averaged, and merged.

Your folder structure should look like this:

.
├── averaged
├── average.py
├── depth
├── depth.py
├── Elephant.mp4
├── merged
├── merge.py
└── rgb

Steps

  1. Get the FPS of the source video. We will need this to put the video back together.

ffmpeg -i Elephant.mp4 2>&1 | sed -n "s/.*, \(.*\) fp.*/\1/p"

  1. Split the video into individual frames (this will populate the rgb folder).

ffmpeg -i Elephant.mp4 -qmin 1 -qscale:v 1 ./rgb/%06d.jpg

  1. Run the depth inferrence (this will populate the depth folder).

For faster (but lower quality) depth map generation you can switch to a lighter model by changing line 13 to False.

python3 depth.py

  1. [Optional step] Run the frame average to reduce the flicker betweeen individual frames (this will populate the averaged folder).

See Elephant_depth_averaged_sound.mp4 vs. Elephant_depth_sound.mp4 to see the effect of this step.

python3 average.py

  1. Merge the depthmaps with the original frames (this will populate the merged folder).

python3 merge.py

  1. Combine the merged frames into a video file. (substitute 25 fps with the number you got from step 1).

ffmpeg -framerate 25 -i ./merged/%06d.jpg -vcodec libx264 -pix_fmt yuv420p Elephant_depth.mp4

  1. Copy the audio track from the original video.

ffmpeg -i Elephant_depth.mp4 -i ./Elephant.mp4 -c copy -map 0:0 -map 1:1 -shortest Elephant_depth_sound.mp4

  1. Voilà

MiDaS result:

Demo MiDaS

BoostingMonocularDepth result:

Demo Boosting

BoostingMonocularDepth does not always provide better results compared to vanilla MiDaS, as you can see on the following example.

MiDaS result:

Demo MiDaS

BoostingMonocularDepth result:

Demo Boosting

video-depthify's People

Contributors

jankais3r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

video-depthify's Issues

Optimal setup to run this

Hello,

What would you say is the optimal setup for this work? Better CPU, RAM, GPU? We processed a small video and it took approximately 2 hours to produce the depth map, but the machine we run it was pretty low in capabilities. So we were wondering what is the recommended or optimal setup for this script to run as efficiently as possible.

Thanks!

average.py throws an error

Hello,

When I try to run the average.py script I get the following error:

arr = arr + prev / 3
ValueError: operands could not be broadcast together with shapes (1080,1920,3) (1080,1920)

Best regards.

Setup script can't download the model

This part of the colaboratory setup script:

!gdown https://drive.google.com/uc?id=1nqW_Hwj86kslfsXR7EnXpEWdO2csz1cC

Returns:

Permission denied: https://drive.google.com/0/uc?id=1nqW_Hwj86kslfsXR7EnXpEWdO2csz1cC
Maybe you need to change permission over 'Anyone with the link'?

Oddly enough, i can download it just fine manually from google drive.
Any ideas?

average.py throwing numpy error

Hello,

I running into an error every time Im running the average.py and get this callback.

line 284, in getattr
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'float'

Am I missing something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.