Upload 2 files
Browse files- README.md +61 -0
- vis_cam.py +130 -0
README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: "apache-2.0"
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
# Dataset Card
|
| 8 |
+
## 📷 SynCamVideo Dataset
|
| 9 |
+
### 1. Dataset Introduction
|
| 10 |
+
The SynCamVideo Dataset is a multi-camera synchronized video dataset rendered using the Unreal Engine 5. It consists of 1,000 different scenes, each captured by 36 cameras, resulting in a total of 36,000 videos. SynCamVideo features 50 different animals as the "main subject" and utilizes 20 different locations from [Poly Haven](https://polyhaven.com/hdris) as backgrounds. In each scene, 1-2 subjects are selected from the 50 animals and move along a predefined trajectory, the background is randomly chosen from the 20 locations, the 36 cameras simultaneously record the subjects' movements.
|
| 11 |
+
|
| 12 |
+
The SynCamVideo Dataset can be used to train multi-camera synchronized video generation models, inspiring applications in areas such as filmmaking and multi-view data generation for downstream tasks.
|
| 13 |
+
|
| 14 |
+
### 2. File Structure
|
| 15 |
+
```
|
| 16 |
+
SynCamVideo
|
| 17 |
+
├── train
|
| 18 |
+
│ ├── videos # training videos
|
| 19 |
+
│ │ ├── scene1 # one scene
|
| 20 |
+
│ │ │ ├── xxx.mp4 # synchronized 100-frame videos at 480x720 resolution
|
| 21 |
+
│ │ │ └── ...
|
| 22 |
+
│ │ │ ...
|
| 23 |
+
│ │ └── scene1000
|
| 24 |
+
│ │ ├── xxx.mp4
|
| 25 |
+
│ │ └── ...
|
| 26 |
+
│ ├── cameras # training cameras
|
| 27 |
+
│ │ ├── scene1 # one scene
|
| 28 |
+
│ │ │ └── xxx.json # extrinsic parameters corresponding to the videos
|
| 29 |
+
│ │ │ ...
|
| 30 |
+
│ │ └── scene1000
|
| 31 |
+
│ │ └── xxx.json
|
| 32 |
+
│ └──caption
|
| 33 |
+
│ └── cogvideox_caption.csv # caption generated with "THUDM/cogvlm2-llama3-caption"
|
| 34 |
+
└──val
|
| 35 |
+
└── cameras # validation cameras
|
| 36 |
+
├── Hemi36_4m_0 # distance=4m, elevation=0°
|
| 37 |
+
│ └── Hemi36_4m_0.json # 36 cameras: distance=4m, elevation=0°, azimuth=i * 10°
|
| 38 |
+
│ ...
|
| 39 |
+
└── Hemi36_7m_45
|
| 40 |
+
└── Hemi36_7m_45.json
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
### 3. Useful scripts
|
| 44 |
+
- Camera Visualization
|
| 45 |
+
```python
|
| 46 |
+
python vis_cam.py --pose_file_path ./SynCamVideo-Dataset/val/cameras/Hemi36_4m_0/Hemi36_4m_0.json --num_cameras 36
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
The visualization script is modified from [CameraCtrl](https://github.com/hehao13/CameraCtrl/blob/main/tools/visualize_trajectory.py), thanks for their inspiring work.
|
| 50 |
+
|
| 51 |
+

|
| 52 |
+
|
| 53 |
+
## Citation
|
| 54 |
+
|
| 55 |
+
```bibtex
|
| 56 |
+
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
## Contact
|
| 60 |
+
|
| 61 |
+
[Jianhong Bai](https://jianhongbai.github.io/)
|
vis_cam.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib as mpl
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
from matplotlib.patches import Patch
|
| 6 |
+
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
|
| 7 |
+
import json
|
| 8 |
+
|
| 9 |
+
class CameraPoseVisualizer:
|
| 10 |
+
def __init__(self, xlim, ylim, zlim):
|
| 11 |
+
self.fig = plt.figure(figsize=(18, 7))
|
| 12 |
+
self.ax = self.fig.add_subplot(projection='3d')
|
| 13 |
+
self.plotly_data = None
|
| 14 |
+
self.ax.set_aspect("auto")
|
| 15 |
+
self.ax.set_xlim(xlim)
|
| 16 |
+
self.ax.set_ylim(ylim)
|
| 17 |
+
self.ax.set_zlim(zlim)
|
| 18 |
+
self.ax.set_xlabel('x')
|
| 19 |
+
self.ax.set_ylabel('y')
|
| 20 |
+
self.ax.set_zlabel('z')
|
| 21 |
+
print('initialize camera pose visualizer')
|
| 22 |
+
|
| 23 |
+
def extrinsic2pyramid(self, extrinsic, color_map='red', hw_ratio=9/16, base_xval=1, zval=3):
|
| 24 |
+
vertex_std = np.array([[0, 0, 0, 1],
|
| 25 |
+
[base_xval, -base_xval * hw_ratio, zval, 1],
|
| 26 |
+
[base_xval, base_xval * hw_ratio, zval, 1],
|
| 27 |
+
[-base_xval, base_xval * hw_ratio, zval, 1],
|
| 28 |
+
[-base_xval, -base_xval * hw_ratio, zval, 1]])
|
| 29 |
+
vertex_transformed = vertex_std @ extrinsic.T
|
| 30 |
+
meshes = [[vertex_transformed[0, :-1], vertex_transformed[1][:-1], vertex_transformed[2, :-1]],
|
| 31 |
+
[vertex_transformed[0, :-1], vertex_transformed[2, :-1], vertex_transformed[3, :-1]],
|
| 32 |
+
[vertex_transformed[0, :-1], vertex_transformed[3, :-1], vertex_transformed[4, :-1]],
|
| 33 |
+
[vertex_transformed[0, :-1], vertex_transformed[4, :-1], vertex_transformed[1, :-1]],
|
| 34 |
+
[vertex_transformed[1, :-1], vertex_transformed[2, :-1], vertex_transformed[3, :-1], vertex_transformed[4, :-1]]]
|
| 35 |
+
|
| 36 |
+
color = color_map if isinstance(color_map, str) else plt.cm.rainbow(color_map)
|
| 37 |
+
|
| 38 |
+
self.ax.add_collection3d(
|
| 39 |
+
Poly3DCollection(meshes, facecolors=color, linewidths=0.3, edgecolors=color, alpha=0.35))
|
| 40 |
+
|
| 41 |
+
def customize_legend(self, list_label):
|
| 42 |
+
list_handle = []
|
| 43 |
+
for idx, label in enumerate(list_label):
|
| 44 |
+
color = plt.cm.viridis(idx / len(list_label))
|
| 45 |
+
patch = Patch(color=color, label=label)
|
| 46 |
+
list_handle.append(patch)
|
| 47 |
+
plt.legend(loc='right', bbox_to_anchor=(1.8, 0.5), handles=list_handle)
|
| 48 |
+
|
| 49 |
+
def colorbar(self, max_frame_length):
|
| 50 |
+
cmap = mpl.cm.rainbow
|
| 51 |
+
norm = mpl.colors.Normalize(vmin=0, vmax=max_frame_length)
|
| 52 |
+
self.fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=cmap), ax=self.ax, orientation='vertical', label='Frame Number')
|
| 53 |
+
|
| 54 |
+
def show(self):
|
| 55 |
+
plt.title('Extrinsic Parameters')
|
| 56 |
+
plt.savefig('extrinsic_parameters.jpg', format='jpg', dpi=300)
|
| 57 |
+
plt.show()
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def get_args():
|
| 61 |
+
parser = argparse.ArgumentParser()
|
| 62 |
+
parser.add_argument('--pose_file_path', default='./SynCamVideo-Dataset/val/cameras/Hemi36_4m_0/Hemi36_4m_0.json', type=str, help='the path of the pose file')
|
| 63 |
+
parser.add_argument('--hw_ratio', default=16/16, type=float, help='the height over width of the film plane')
|
| 64 |
+
parser.add_argument('--num_cameras', type=int, default=36)
|
| 65 |
+
parser.add_argument('--base_xval', type=float, default=0.08)
|
| 66 |
+
parser.add_argument('--zval', type=float, default=0.15)
|
| 67 |
+
parser.add_argument('--x_min', type=float, default=-2)
|
| 68 |
+
parser.add_argument('--x_max', type=float, default=2)
|
| 69 |
+
parser.add_argument('--y_min', type=float, default=-2)
|
| 70 |
+
parser.add_argument('--y_max', type=float, default=2)
|
| 71 |
+
parser.add_argument('--z_min', type=float, default=-1.)
|
| 72 |
+
parser.add_argument('--z_max', type=float, default=1)
|
| 73 |
+
return parser.parse_args()
|
| 74 |
+
|
| 75 |
+
def get_c2w(w2cs, transform_matrix, relative_c2w=True):
|
| 76 |
+
if relative_c2w:
|
| 77 |
+
target_cam_c2w = np.array([
|
| 78 |
+
[1, 0, 0, 0],
|
| 79 |
+
[0, 1, 0, 0],
|
| 80 |
+
[0, 0, 1, 0],
|
| 81 |
+
[0, 0, 0, 1]
|
| 82 |
+
])
|
| 83 |
+
abs2rel = target_cam_c2w @ w2cs[0]
|
| 84 |
+
ret_poses = [target_cam_c2w, ] + [abs2rel @ np.linalg.inv(w2c) for w2c in w2cs[1:]]
|
| 85 |
+
else:
|
| 86 |
+
ret_poses = [np.linalg.inv(w2c) for w2c in w2cs]
|
| 87 |
+
ret_poses = [transform_matrix @ x for x in ret_poses]
|
| 88 |
+
return np.array(ret_poses, dtype=np.float32)
|
| 89 |
+
|
| 90 |
+
def parse_matrix(matrix_str):
|
| 91 |
+
rows = matrix_str.strip().split('] [')
|
| 92 |
+
matrix = []
|
| 93 |
+
for row in rows:
|
| 94 |
+
row = row.replace('[', '').replace(']', '')
|
| 95 |
+
if len((list(map(float, row.split())))) == 3:
|
| 96 |
+
matrix.append((list(map(float, row.split()))) +[0.])
|
| 97 |
+
else:
|
| 98 |
+
matrix.append(list(map(float, row.split())))
|
| 99 |
+
return np.array(matrix)
|
| 100 |
+
|
| 101 |
+
if __name__ == '__main__':
|
| 102 |
+
args = get_args()
|
| 103 |
+
|
| 104 |
+
with open(args.pose_file_path, 'r') as file:
|
| 105 |
+
data = json.load(file)
|
| 106 |
+
|
| 107 |
+
cameras = [parse_matrix(data[name]) for name in sorted(data.keys())]
|
| 108 |
+
cameras = np.transpose(np.stack(cameras), (0, 2, 1))
|
| 109 |
+
|
| 110 |
+
w2cs = []
|
| 111 |
+
for cam in cameras:
|
| 112 |
+
if cam.shape[0] == 3:
|
| 113 |
+
cam = np.vstack((cam, np.array([[0, 0, 0, 1]])))
|
| 114 |
+
cam = cam[:, [1, 2, 0, 3]]
|
| 115 |
+
cam[:3, 1] *= -1.
|
| 116 |
+
w2cs.append(np.linalg.inv(cam))
|
| 117 |
+
|
| 118 |
+
w2cs = w2cs[:args.num_cameras]
|
| 119 |
+
scale = max(max(abs(w2c[:3, 3])) for w2c in w2cs)
|
| 120 |
+
for w2c in w2cs:
|
| 121 |
+
w2c[:3, 3] /= scale
|
| 122 |
+
transform_matrix = np.array([[1, 0, 0, 0], [0, 0, 1, 0], [0, -1, 0, 0], [0, 0, 0, 1]])
|
| 123 |
+
c2ws = get_c2w(w2cs, transform_matrix, True)
|
| 124 |
+
|
| 125 |
+
visualizer = CameraPoseVisualizer([args.x_min, args.x_max], [args.y_min, args.y_max], [args.z_min, args.z_max])
|
| 126 |
+
for frame_idx, c2w in enumerate(c2ws):
|
| 127 |
+
visualizer.extrinsic2pyramid(c2w, frame_idx / args.num_cameras, hw_ratio=args.hw_ratio, base_xval=args.base_xval,
|
| 128 |
+
zval=(args.zval))
|
| 129 |
+
visualizer.colorbar(args.num_cameras)
|
| 130 |
+
visualizer.show()
|