Open cohyun opened 1 year ago
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()
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?
Hi! I've been trying out poseviz as well and got the same error. Did you end up finding a solution?
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.
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.
Hello, i am trying all the aforementioned suggestion but i get the same error. I am using wsl. any suggestions? Thanks in advance.
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?
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.
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.
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.
Thanks a lot. I will dive deep there. Meanwhile a simple pip freeze could be helpfull.
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
Hi! Thanks for the excellent job. I read closed issue and knew that I can save the output of poseviz as video by "new_sequence_output()".
So I Wrote the source code in demo_video_batched.py located at the metrabs folder.
`def main(): model = tf.saved_model.load(download_model('metrabs_eff2l_y4_360')) skeleton = 'smpl+head_30' joint_names = model.per_skeleton_joint_names[skeleton].numpy().astype(str) joint_edges = model.per_skeleton_joint_edges[skeleton].numpy() viz = poseviz.PoseViz(joint_names, joint_edges) frame_batches = tf.data.Dataset.from_generator( frames_from_video, tf.uint8, [None, None, 3]).batch(32).prefetch(1)
But Error like below is keep occuring.
ValueError: ImageIO does not generally support reading folders. Limited support may be available via specific plugins. Specify the plugin explicitly using the
pluginkwarg, e.g.
plugin='DICOM'``Is it possible to save the ouput as video by the 'new_sequence_output'?