Skip to content

Commit

Permalink
Customize the GUI resolution via --width and --height
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom94 committed Jan 18, 2022
1 parent ada8342 commit 3cf5fba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
29 changes: 15 additions & 14 deletions scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@ def parse_args():
parser.add_argument("--save_snapshot", default="", help="Save this snapshot after training. recommended extension: .msgpack")

parser.add_argument("--nerf_compatibility", action="store_true", help="Matches parameters with original NeRF. Can cause slowness and worse results on some scenes.")
parser.add_argument("--test_transforms", default="", help="Path to a nerf style transforms json from which we will compute PSNR")
parser.add_argument("--test_transforms", default="", help="Path to a nerf style transforms json from which we will compute PSNR.")

parser.add_argument("--screenshot_transforms", default="", help="Path to a nerf style transforms json from which to save a screenshot.")
parser.add_argument("--screenshot_frames", nargs="*", help="Which frame(s) to take a screenshot of")
parser.add_argument("--screenshot_dir", default="", help="which directory to output screenshots to")
parser.add_argument("--screenshot_w", type=int, default=0, help="screenshot res width")
parser.add_argument("--screenshot_h", type=int, default=0, help="screenshot res height")
parser.add_argument("--screenshot_spp", type=int, default=16, help="screenshot spp")
parser.add_argument("--screenshot_transforms", default="", help="Path to a nerf style transforms.json from which to save screenshots.")
parser.add_argument("--screenshot_frames", nargs="*", help="Which frame(s) to take screenshots of.")
parser.add_argument("--screenshot_dir", default="", help="Which directory to output screenshots to.")
parser.add_argument("--screenshot_spp", type=int, default=16, help="Number of samples per pixel in screenshots.")

parser.add_argument("--width", "--screenshot_w", type=int, default=0, help="Resolution width of GUI and screenshots.")
parser.add_argument("--height", "--screenshot_h", type=int, default=0, help="Resolution height of GUI and screenshots.")

parser.add_argument("--gui", action="store_true", help="Run the testbed GUI interactively.")
parser.add_argument("--train", action="store_true", help="If the GUI is enabled, controls whether training starts immediately.")
parser.add_argument("--n_steps", type=int, default=-1, help="Number of steps to train for before quitting.")

parser.add_argument("--sharpen", default=0, help="Set amount of sharpening applied to NeRF training images")
parser.add_argument("--sharpen", default=0, help="Set amount of sharpening applied to NeRF training images.")

args = parser.parse_args()
return args
Expand Down Expand Up @@ -122,8 +123,8 @@ def parse_args():

if args.gui:
# Pick a sensible GUI resolution depending on arguments.
sw = args.screenshot_w or 1920
sh = args.screenshot_h or 1080
sw = args.width or 1920
sh = args.height or 1080
while sw*sh > 1920*1080*4:
sw = int(sw / 2)
sh = int(sh / 2)
Expand Down Expand Up @@ -277,7 +278,7 @@ def parse_args():
ssim = totssim/(totcount or 1)
print(f"PSNR={psnr} [min={minpsnr} max={maxpsnr}] SSIM={ssim}")

if args.screenshot_w:
if args.width:
if ref_transforms:
testbed.fov_axis = 0
testbed.fov = ref_transforms["camera_angle_x"] * 180 / np.pi
Expand All @@ -295,13 +296,13 @@ def parse_args():
outname = outname + ".png"

print(f"rendering {outname}")
image = testbed.render(args.screenshot_w or int(ref_transforms["w"]), args.screenshot_h or int(ref_transforms["h"]), args.screenshot_spp, True)
image = testbed.render(args.width or int(ref_transforms["w"]), args.height or int(ref_transforms["h"]), args.screenshot_spp, True)
os.makedirs(os.path.dirname(outname), exist_ok=True)
write_image(outname, image)
else:
elif args.screenshot_dir:
outname = os.path.join(args.screenshot_dir, args.scene + "_" + network_stem)
print(f"Rendering {outname}.png")
image = testbed.render(args.screenshot_w, args.screenshot_h, args.screenshot_spp, True)
image = testbed.render(args.width, args.height, args.screenshot_spp, True)
if os.path.dirname(outname) != "":
os.makedirs(os.path.dirname(outname), exist_ok=True)
write_image(outname + ".png", image)
Expand Down
16 changes: 15 additions & 1 deletion src/main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ int main(int argc, char** argv) {
{"snapshot"},
};

ValueFlag<uint32_t> width_flag{
parser,
"WIDTH",
"Resolution width of the GUI.",
{"width"},
};

ValueFlag<uint32_t> height_flag{
parser,
"HEIGHT",
"Resolution height of the GUI.",
{"height"},
};

Flag version_flag{
parser,
"VERSION",
Expand Down Expand Up @@ -211,7 +225,7 @@ int main(int argc, char** argv) {
#endif

if (gui) {
testbed.init_window(1920, 1080);
testbed.init_window(width_flag ? get(width_flag) : 1920, height_flag ? get(height_flag) : 1080);
}

// Render/training loop
Expand Down

1 comment on commit 3cf5fba

@aabho
Copy link

@aabho aabho commented on 3cf5fba Jan 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

Please sign in to comment.