Giter Site home page Giter Site logo

ERROR in writing video about poseviz HOT 11 OPEN

isarandi avatar isarandi commented on August 25, 2024
ERROR in writing video

from poseviz.

Comments (11)

cohyun avatar cohyun commented on August 25, 2024 2

Thanks!

I tried your code and there was one error and can you help me please?

By the code you wrote
frame_batches = tfio.IODataset.from_ffmpeg(input_video_path, 'v:0').batch(8).prefetch(1)

I'm getting the error message like below
NotImplementedError: ('could not find ffmpeg after search through ', ['libtensorflow_io_ffmpeg_4.2.so', 'libtensorflow_io_ffmpeg_3.4.so', 'libtensorflow_io_ffmpeg_2.8.so'])

I checked that I've installed the ffmpeg but the error is popping.
Do you know anyway to solve this problem?

from poseviz.

isarandi avatar isarandi commented on August 25, 2024

Thanks for the question! I'm planning to write a how-to, so reports like this are helpful.

For writing videos, you need to call new_sequence_output at the start of the desired video, and you need to specify a file extension.

Here's a complete self-contained example:

import tensorflow_hub as tfhub
import tensorflow_io as tfio
import imageio

import poseviz
import cameralib


def main():
    model = tfhub.load('https://bit.ly/metrabs_l')
    skeleton = 'smpl+head_30'
    joint_names = model.per_skeleton_joint_names[skeleton].numpy().astype(str)
    joint_edges = model.per_skeleton_joint_edges[skeleton].numpy()

    input_video_path = 'YOUR_INPUT_VIDEO_PATH'
    frame_batches = tfio.IODataset.from_ffmpeg(input_video_path, 'v:0').batch(8).prefetch(1)

    camera = cameralib.Camera.from_fov(
        fov_degrees=55, imshape=frame_batches.element_spec.shape[1:3])

    with imageio.get_reader(input_video_path) as reader:
        fps = reader.get_meta_data()['fps']

    with poseviz.PoseViz(joint_names, joint_edges) as viz:
        viz.new_sequence_output('YOUR_OUTPUT_VIDEO_PATH.mp4', fps=fps)
        for frame_batch in frame_batches:
            pred = model.detect_poses_batched(
                frame_batch, intrinsic_matrix=camera.intrinsic_matrix[tf.newaxis],
                skeleton=skeleton)

            for frame, boxes, poses in zip(frame_batch, pred['boxes'], pred['poses3d']):
                viz.update(frame=frame, boxes=boxes, poses=poses, camera=camera)

if __name__ == '__main__':
    main()

from poseviz.

michaelyfu avatar michaelyfu commented on August 25, 2024

Hi! I've been trying out poseviz as well and got the same error. Did you end up finding a solution?

from poseviz.

levineuwirth avatar levineuwirth commented on August 25, 2024

I can confirm I'm also getting that error while looking into this as an alternative to other libraries. Will update if I can find any solution.

from poseviz.

isarandi avatar isarandi commented on August 25, 2024

You have to call new_sequence_output with a video file path string (ending in eg. mp4). And you have to do this not at the end but when you want to start recording a video. I.e. the content of the next update() call will be shown in the first frame of the resulting video.

from poseviz.

geokosto avatar geokosto commented on August 25, 2024

Hello, i am trying all the aforementioned suggestion but i get the same error. I am using wsl. any suggestions? Thanks in advance.

from poseviz.

isarandi avatar isarandi commented on August 25, 2024

Hello, i am trying all the aforementioned suggestion but i get the same error. I am using wsl. any suggestions? Thanks in advance.

Can you paste the code you're trying?

from poseviz.

geokosto avatar geokosto commented on August 25, 2024

Of course, thanks a lot. I slightly modified the demo_video.py of the metrabs repo.

import sys
import urllib.request

import tensorflow as tf
import tensorflow_hub as tfhub
import tensorflow_io as tfio

import cameralib
import poseviz
import imageio


def main():
    model = tfhub.load("https://bit.ly/metrabs_l")
    skeleton = "smpl_24"
    joint_names = model.per_skeleton_joint_names[skeleton].numpy().astype(str)
    joint_edges = model.per_skeleton_joint_edges[skeleton].numpy()

    video_filepath = get_video(
        sys.argv[1]
    )  # You can also specify the filepath directly here.
    frame_batches = (
        tfio.IODataset.from_ffmpeg(video_filepath, "v:0").batch(8).prefetch(1)
    )

    camera = cameralib.Camera.from_fov(
        fov_degrees=55, imshape=frame_batches.element_spec.shape[1:3]
    )

    with imageio.get_reader(video_filepath) as reader:
        fps = reader.get_meta_data()["fps"]
    with poseviz.PoseViz(joint_names, joint_edges) as viz:
        viz.new_sequence_output("../YOUR_OUTPUT_VIDEO_PATH.mp4", fps=fps)
        for frame_batch in frame_batches:
            pred = model.detect_poses_batched(
                frame_batch,
                intrinsic_matrix=camera.intrinsic_matrix[tf.newaxis],
                skeleton=skeleton,
            )

            for frame, boxes, poses in zip(frame_batch, pred["boxes"], pred["poses3d"]):
                viz.update(frame=frame, boxes=boxes, poses=poses, camera=camera)


def get_video(source, temppath="/tmp/video.mp4"):
    if not source.startswith("http"):
        return source

    opener = urllib.request.build_opener()
    opener.addheaders = [("User-agent", "Mozilla/5.0")]
    urllib.request.install_opener(opener)
    urllib.request.urlretrieve(source, temppath)
    return temppath


if __name__ == "__main__":
    main()

and I call it via the following command.

(metrabs) ubuntu@DESKTOP:~/metrabs/demos$ python demo_video.py ../change_direction_fast_sync.mp4 

Also, despite that maybe that's an issue on the metrabs repo not here, when running the `demo.py i get a qt window of a black screen.

image

Maybe this is a wsl related issue, i am not sure.

Either way, i want to mention that i find the job you did amazing and i am willing to incorporate it on my workflow, possible extending and adding some capabilities. Thanks in advance.

from poseviz.

isarandi avatar isarandi commented on August 25, 2024

The black screen is an issue with Mayavi and VTK and other library version compatibility, unrelated to PoseViz code. I'll try setting better version requirements. Meanwhile you can search github issues on the mayavi repo, there are discussions there.

from poseviz.

geokosto avatar geokosto commented on August 25, 2024

Thanks a lot. I will dive deep there. Meanwhile a simple pip freeze could be helpfull.

from poseviz.

geokosto avatar geokosto commented on August 25, 2024

Hi, i manage to resolve some of the issues.
Regarding the black screen, apparently it was an issue with the wsl set up. Setting up the conda environment on Windows resolved this issue. In order to build the environment on Windows, i had to clone the rlemasklib repo locally and build it by modifying the setup.py as follows:

# Conditional compilation flags
extra_compile_args = []
if sys.platform != "win32":
    extra_compile_args = ["-Wno-cpp", "-Wno-unused-function", "-std=c99"]

Regarding the video error, i wasnt able to solve the afformention error of the ffmpeg so i fixed the issue using imageio and by replacing the

frame_batches = (
        tfio.IODataset.from_ffmpeg(video_filepath, "v:0").batch(8).prefetch(1)
    )

with the following code block

def get_frame_batches(video_filepath, batch_size=8):
    reader = imageio.get_reader(video_filepath)
    frames = []
    for frame in reader:
        frames.append(frame)
        if len(frames) == batch_size:
            yield np.array(frames)
            frames = []
    if frames:
        yield np.array(frames)

frame_batches = get_frame_batches(video_filepath, batch_size=8)

# Get the first batch to determine the shape
first_batch = next(frame_batches)
imshape = first_batch.shape[1:3]

# Create a new generator including the first batch
frame_batches = chain([first_batch], frame_batches)

Thanks

from poseviz.

Related Issues (9)

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.