<jupyter_start><jupyter_text>Check the generated image:<jupyter_code>image_paths = list((rgb_dir / '1x').iterdir())
Image.open(image_paths[0])<jupyter_output><empty_output><jupyter_text>Write ground truth camera<jupyter_code>from scipy.spatial.transform import Rotation as R

for i, rgb in enumerate(rgb_list):
    meta = {}
    quat = k_meta['camera']['quaternions'][i]
    # change quaternion format from [w,x,y,z] to [x,y,z,w]
    quat = [quat[1],quat[2],quat[3],quat[0]]
    rot = R.from_quat(quat)
    # orientation is the world to camera rotation matrix!!!
    matrix = rot.as_matrix()
    # rotate camera -- seems to be needed for some reason
    matrix = matrix @ np.array([[ 1, 0, 0],
                                [ 0,-1, 0],
                                [ 0, 0,-1]])
    meta['orientation'] = matrix.T.tolist()
    meta['position'] = k_meta['camera']['positions'][i]
    meta['focal_length'] = k_meta['camera']['focal_length'] * image_size[0] / k_meta['camera']['sensor_width']  # k_meta['camera']['focal_length']  # 428.4225158691406  
    meta['principal_point'] = [image_size[0]/2, image_size[1]/2] # check
    meta['skew'] = 0.
    meta['pixel_aspect_ratio'] = 1. # check
    meta['radial_distortion'] = [0., 0., 0.] # check
    meta['tangential_distortion'] = [0., 0.] # check
    meta['image_size'] = image_size

    with open(str(camera_gt_dir / rgb.stem) + '.json', 'w') as f:
        json.dump(meta, f, indent=2)
# far_new / scale_new : far_old / scale_old = focal_new : focal_old 
focal_old = 428.4225158691406  
focal_new = k_meta['camera']['focal_length']
scale_old = 0.008968276182351506
near_old = 0.00235102334
far_old = 0.7829355594501517

far_old_real = far_old / scale_old
far_old_real

scale_new = scale_old * focal_old / focal_new # because scale is an inverse amount
scale_new
far_new_real = far_old_real / focal_old * focal_new
far_new_real
far_new_real * scale_new
near_old_real = near_old / scale_old
near_new_real = near_old_real / focal_old * focal_new
near_new_real * scale_new<jupyter_output><empty_output><jupyter_text>Write dataset split<jupyter_code># @title Save dataset split to `dataset.json`.

VAL_RATIO = 0.1

all_ids = list(map(lambda x: x.stem,rgb_list))
val_ids = all_ids[::int(1 / VAL_RATIO)]
train_ids = sorted(set(all_ids) - set(val_ids))

print(f'Num of train: {len(train_ids)}')
print(f'Num of val: {len(val_ids)}')

dataset_json = {
    'count': len(all_ids),
    'num_exemplars': len(train_ids),
    'ids': all_ids,
    'train_ids': train_ids,
    'val_ids': val_ids,
}

dataset_json_path = root_dir / 'dataset.json'
with dataset_json_path.open('w') as f:
    json.dump(dataset_json, f, indent=2)

print(f'Saved dataset information to {dataset_json_path}')<jupyter_output>Num of train: 90
Num of val: 10
Saved dataset information to data/kubric_car_static_360_gt/dataset.json<jupyter_text>Save metadata info<jupyter_code># @title Save metadata information to `metadata.json`.
import bisect

metadata_json = {}
for i, image_id in enumerate(train_ids):
  metadata_json[image_id] = {
      'warp_id': i,
      'appearance_id': i,
      'camera_id': 0,
  }
for i, image_id in enumerate(val_ids):
  i = bisect.bisect_left(train_ids, image_id)
  metadata_json[image_id] = {
      'warp_id': i,
      'appearance_id': i,
      'camera_id': 0,
  }

metadata_json_path = root_dir / 'metadata.json'
with metadata_json_path.open('w') as f:
    json.dump(metadata_json, f, indent=2)

print(f'Saved metadata information to {metadata_json_path}')<jupyter_output>Saved metadata information to data/kubric_car_static_360_gt/metadata.json<jupyter_text>Write scene info<jupyter_code>def get_bbox_corners(points):
  lower = points.min(axis=0)
  upper = points.max(axis=0)
  return np.stack([lower, upper])

bbox_corners = get_bbox_corners(np.array(k_meta['instances'][0]['bboxes_3d'])[0])
bbox_corners = np.array([[0,   0,  0],
                         [50, 50, 10]])

# scene_center = np.mean(bbox_corners, axis=0)
scene_scale = 1.0 / np.sqrt(np.sum((bbox_corners[1] - bbox_corners[0]) ** 2))
scene_center = np.array([0., 0., 0.])
# scene_scale = 0.01

print(f'Scene Center: {scene_center}')
print(f'Scene Scale: {scene_scale}')

# @title Save scene information to `scene.json`.

scene_json_path = root_dir /  'scene.json'
with scene_json_path.open('w') as f:
  json.dump({
      'scale': scene_scale,
      'center': scene_center.tolist(),
      'bbox': bbox_corners.tolist(),
      'near': 0.,
      'far': 1. # bbox_corners[1].max() * scene_scale,
  }, f, indent=2)

print(f'Saved scene information to {scene_json_path}')<jupyter_output>Scene Center: [0. 0. 0.]
Scene Scale: 0.0140028008402801
Saved scene information to data/kubric_car_static_360_gt/scene.json
{'fraction_non_alphanumeric': 0.14464740866610026, 'fraction_numerical': 0.037807986406117246, 'mean_word_length': 4.387871853546911, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '141445', 'license': 'Apache-2.0', 'n_tokens_mistral': 1928, 'n_tokens_neox': 1794, 'n_words': 357, 'path': 'kubric_meta_parser.ipynb', 'repo_name': 'ChikaYan/hypernerf', 'size': '4708'}