Skip to content

Commit

Permalink
[update] update video capture example and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
yzqin committed Aug 27, 2023
1 parent eec9f8f commit f562287
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pip3 install -e ".[example]"

## Examples

### Test retargeting with our supplied human video
### Retargeting from human video

1. **Generate the robot joint pose trajectory from a pre-existing video.**
1. **Generate the robot joint pose trajectory from our pre-recorded video.**

```shell
python3 example/detect_from_video.py \
Expand All @@ -37,7 +37,9 @@ python3 example/detect_from_video.py \

This command will output the joint trajectory as a pickle file at the `output_path`.

The pickle file is a python dictionary with two keys: `meta_data` and `data`. `meta_data`, a dictionary, includes details about the robot, while `data`, a list, contains the robotic joint positions for each frame. For additional options, refer to the help information.
The pickle file is a python dictionary with two keys: `meta_data` and `data`. `meta_data`, a dictionary, includes
details about the robot, while `data`, a list, contains the robotic joint positions for each frame. For additional
options, refer to the help information.

```shell
python3 example/detect_from_video.py --help
Expand All @@ -53,3 +55,12 @@ python3 example/render_robot_hand.py \
```

This command uses the data saved from the previous step to create a rendered video.

3. **Record a video of your own hand**

```bash
python3 example/capture_webcam.py --video-path example/data/my_human_hand_video.mp4
```

This command will access your webcam (which should be connected to your computer) and record the video stream in mp4
format. To end video recording, press `q` on the keyboard.
39 changes: 39 additions & 0 deletions example/capture_webcam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from pathlib import Path

from typing import Union
import cv2
import tyro


def main(video_path: str, video_capture_device: Union[str, int] = 0):
"""
Capture video with the camera connected to your computer. Press `q` to end the recording.
Args:
video_path: The file path for the output video in .mp4 format.
video_capture_device: the device id for your camera connected to the computer in OpenCV format.
"""
cap = cv2.VideoCapture(video_capture_device)

width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

path = Path(video_path)
path.parent.mkdir(parents=True, exist_ok=True)
writer = cv2.VideoWriter(str(video_path), cv2.VideoWriter_fourcc(*"mp4v"), 30.0, (width, height))

while True:
ret, frame = cap.read()
writer.write(frame)
cv2.imshow("frame", frame)
if cv2.waitKey(1) & 0xFF == 27:
break

cap.release()
writer.release()
cv2.destroyAllWindows()


if __name__ == "__main__":
tyro.cli(main)

0 comments on commit f562287

Please sign in to comment.