-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding control for metric computation selection
- Loading branch information
Showing
7 changed files
with
161 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,102 @@ | ||
import os | ||
import argparse | ||
from os.path import join | ||
from easymocap.mytools.camera_utils import read_camera | ||
import cv2 | ||
|
||
# fmt: off | ||
import sys | ||
sys.path.append('.') | ||
from easyvolcap.utils.console_utils import * | ||
from easymocap.mytools.camera_utils import read_camera | ||
from easyvolcap.utils.colmap_utils import write_cameras_binary, write_images_binary, Camera, Image, rotmat2qvec, qvec2rotmat, write_cameras_text, write_images_text | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--data_root', default='data/my_zjumocap/my_313/bkgd') | ||
parser.add_argument('--output_dir', default='text') | ||
parser.add_argument('-i', '--intri', default='intri.yml') | ||
parser.add_argument('-e', '--extri', default='extri.yml') | ||
parser.add_argument('--height', default=1024) | ||
parser.add_argument('--width', default=1024) | ||
args = parser.parse_args() | ||
args.output_dir = join(args.data_root, args.output_dir) | ||
args.intri = join(args.data_root, args.intri) | ||
args.extri = join(args.data_root, args.extri) | ||
# fmt: on | ||
|
||
cams = read_camera(args.intri, args.extri) | ||
assert 'basenames' in cams and len(cams['basenames']) | ||
basenames = sorted(cams['basenames']) | ||
os.makedirs(args.output_dir, exist_ok=True) | ||
@catch_throw | ||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--data_root', default='data/my_zjumocap/my_313/bkgd') | ||
parser.add_argument('--output_dir', default='colmap') | ||
parser.add_argument('--image_dir', default='images_calib') | ||
parser.add_argument('--image_ext', default='.jpg') | ||
parser.add_argument('--mask_dir', default='masks') | ||
parser.add_argument('--mask_ext', default='.jpg') | ||
parser.add_argument('-i', '--intri', default='intri.yml') | ||
parser.add_argument('-e', '--extri', default='extri.yml') | ||
args = parser.parse_args() | ||
args.output_dir = join(args.data_root, args.output_dir) | ||
args.intri = join(args.data_root, args.intri) | ||
args.extri = join(args.data_root, args.extri) | ||
|
||
cams = read_camera(args.intri, args.extri) | ||
assert 'basenames' in cams and len(cams['basenames']) | ||
basenames = sorted(cams['basenames']) | ||
os.makedirs(args.output_dir, exist_ok=True) | ||
|
||
cameras = {} | ||
images = {} | ||
sizes = {} | ||
frames = os.listdir(join(args.data_root, args.image_dir, basenames[0])) | ||
frames = sorted([x.split('.')[0] for x in frames]) | ||
for frame in frames: | ||
output_dir = join(args.output_dir, frame) | ||
os.makedirs(output_dir, exist_ok=True) | ||
os.makedirs(join(output_dir, 'images'), exist_ok=True) | ||
os.makedirs(join(output_dir, 'masks'), exist_ok=True) | ||
os.makedirs(join(output_dir, 'sparse'), exist_ok=True) | ||
for cam_id, cam_name in enumerate(basenames): | ||
cam_id = cam_id + 1 | ||
# write images | ||
# if os.path.exists(join(output_dir, 'images', f'{cam_id:02d}{args.image_ext}')): | ||
os.remove(join(output_dir, 'images', f'{cam_id:02d}{args.image_ext}')) | ||
# if os.path.exists(join(output_dir, 'masks', f'{cam_id:02d}{args.mask_ext}')): | ||
os.remove(join(output_dir, 'masks', f'{cam_id:02d}{args.mask_ext}')) | ||
os.symlink(join('../../..', args.image_dir, cam_name, f'{frame}{args.image_ext}'), join(output_dir, 'images', f'{cam_id:02d}{args.image_ext}')) | ||
os.symlink(join('../../..', args.mask_dir, cam_name, f'{frame}{args.mask_ext}'), join(output_dir, 'masks', f'{cam_id:02d}{args.mask_ext}')) | ||
# read image | ||
if cam_name not in sizes.keys(): | ||
img = cv2.imread(join(output_dir, 'images', f'{cam_id:02d}{args.image_ext}')) | ||
sizes[cam_name] = img.shape[:2] | ||
# read camera | ||
print(f'reading image and camera from: {cam_name}') | ||
cam_dict = cams[cam_name] | ||
K = cam_dict['K'] | ||
R = cam_dict['R'] | ||
T = cam_dict['T'] | ||
D = cam_dict['dist'] # !: losing k3 parameter | ||
if 'H' in cam_dict.keys() or 'W' in cam_dict.keys(): | ||
cam_dict['H'] = sizes[cam_name][0] | ||
cam_dict['W'] = sizes[cam_name][1] | ||
if D.shape[0] == 1: | ||
fx, fy, cx, cy, k1, k2, p1, p2, k3 = K[0, 0], K[1, 1], K[0, 2], K[1, 2], D[0, 0], D[0, 1], D[0, 2], D[0, 3], D[0, 4] | ||
else: | ||
fx, fy, cx, cy, k1, k2, p1, p2, k3 = K[0, 0], K[1, 1], K[0, 2], K[1, 2], D[0, 0], D[1, 0], D[2, 0], D[3, 0], D[4, 0] | ||
|
||
params = [fx, fy, cx, cy, k1, k2, p1, p2] | ||
camera = Camera( | ||
id=cam_id, | ||
model='OPENCV', | ||
width=cam_dict['W'], | ||
height=cam_dict['H'], | ||
params=params | ||
) | ||
|
||
cameras = {} | ||
images = {} | ||
for cam_id, cam_name in enumerate(basenames): | ||
print(f'reading image and camera from: {cam_name}') | ||
cam_dict = cams[cam_name] | ||
K = cam_dict['K'] | ||
R = cam_dict['R'] | ||
T = cam_dict['T'] | ||
D = cam_dict['dist'] # !: losing k3 parameter | ||
if D.shape[0] == 1: | ||
fx, fy, cx, cy, k1, k2, p1, p2, k3 = K[0, 0], K[1, 1], K[0, 2], K[1, 2], D[0, 0], D[0, 1], D[0, 2], D[0, 3], D[0, 4] | ||
else: | ||
fx, fy, cx, cy, k1, k2, p1, p2, k3 = K[0, 0], K[1, 1], K[0, 2], K[1, 2], D[0, 0], D[1, 0], D[2, 0], D[3, 0], D[4, 0] | ||
qvec = rotmat2qvec(R) | ||
tvec = T.T[0] | ||
name = f"{cam_id:02d}.jpg" | ||
|
||
params = [fx, fy, cx, cy, k1, k2, p1, p2] | ||
camera = Camera( | ||
id=cam_id, | ||
model='OPENCV', | ||
width=args.width, | ||
height=args.height, | ||
params=params | ||
) | ||
image = Image( | ||
id=cam_id, | ||
qvec=qvec, | ||
tvec=tvec, | ||
camera_id=cam_id, | ||
name=name, | ||
xys=[], | ||
point3D_ids=[] | ||
) | ||
|
||
qvec = rotmat2qvec(R) | ||
tvec = T.T[0] | ||
name = f"{cam_id:02d}.jpg" | ||
cameras[cam_id] = camera | ||
images[cam_id] = image | ||
|
||
image = Image( | ||
id=cam_id, | ||
qvec=qvec, | ||
tvec=tvec, | ||
camera_id=cam_id, | ||
name=name, | ||
xys=[], | ||
point3D_ids=[] | ||
) | ||
write_cameras_text(cameras, join(output_dir, 'sparse', 'cameras.txt')) | ||
write_images_text(images, join(output_dir, 'sparse', 'images.txt')) | ||
with open(join(output_dir, 'sparse', 'points3D.txt'), 'w') as f: | ||
f.writelines(['# 3D point list with one line of data per point:\n']) | ||
|
||
cameras[cam_id] = camera | ||
images[cam_id] = image | ||
|
||
write_cameras_text(cameras, join(args.output_dir, 'cameras.txt')) | ||
write_images_text(images, join(args.output_dir, 'images.txt')) | ||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Copy as list of files (folders), preserving directory structure | ||
""" | ||
from easyvolcap.utils.console_utils import * | ||
|
||
|
||
@catch_throw | ||
def main(): | ||
args = dotdict( | ||
files=[ | ||
'easyvolcap/runners/evaluators/volumetric_video_evaluator.py', | ||
'easyvolcap/runners/optimizers.py', | ||
'easyvolcap/runners/schedulers.py', | ||
'easyvolcap/utils/loss_utils.py', | ||
'scripts/colmap/easymocap_to_colmap.py', | ||
'scripts/preprocess/neural3dv_to_easyvolcap.py', | ||
'scripts/tools/copy_list_of_files.py', | ||
], | ||
source='.', | ||
target='../easyvolcap-zju3dv', | ||
) | ||
args = dotdict(vars(build_parser(args, description=__doc__).parse_args())) | ||
|
||
for f in tqdm(args.files): | ||
src = join(args.source, f) | ||
tar = join(args.target, f) | ||
os.makedirs(dirname(tar), exist_ok=True) | ||
if isfile(src): | ||
shutil.copy(src, tar) | ||
else: | ||
shutil.copytree(src, tar) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |