Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edges of instance_segmentation mask #383

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions infinigen/core/rendering/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import os
import time
from pathlib import Path
import shutil

import bpy
import gin
import numpy as np
from imageio import imwrite
import cv2

from infinigen.core import init, surface
from infinigen.core.nodes.node_wrangler import Nodes, NodeWrangler
Expand Down Expand Up @@ -278,7 +280,7 @@ def global_flat_shading():
nw.links.remove(link)


def postprocess_blendergt_outputs(frames_folder, output_stem):
def postprocess_blendergt_outputs(frames_folder, output_stem, frame, tmp_dir):
# Save flow visualization
flow_dst_path = frames_folder / f"Vector{output_stem}.exr"
flow_array = load_flow(flow_dst_path)
Expand Down Expand Up @@ -325,15 +327,11 @@ def postprocess_blendergt_outputs(frames_folder, output_stem):

# Save unique instances visualization
uniq_inst_path = frames_folder / f"UniqueInstances{output_stem}.exr"
uniq_inst_array = load_uniq_inst(uniq_inst_path)
np.save(
flow_dst_path.with_name(f"InstanceSegmentation{output_stem}.npy"),
uniq_inst_array,
)
imwrite(
uniq_inst_path.with_name(f"InstanceSegmentation{output_stem}.png"),
colorize_int_array(uniq_inst_array),
)
#uniq_inst_array = load_uniq_inst(uniq_inst_path)
uniq_inst_tmp_path = f"{tmp_dir}/{frame:04d}.png"
uniq_inst_array = cv2.imread(uniq_inst_tmp_path)
np.save(flow_dst_path.with_name(f"InstanceSegmentation{output_stem}.npy"), uniq_inst_array)
shutil.copy(uniq_inst_tmp_path, str(flow_dst_path.with_name(f"InstanceSegmentation{output_stem}.png")))
uniq_inst_path.unlink()


Expand Down Expand Up @@ -475,7 +473,7 @@ def render_image(
if flat_shading:
bpy.context.scene.frame_set(frame)
suffix = get_suffix(dict(frame=frame, **indices))
postprocess_blendergt_outputs(frames_folder, suffix)
postprocess_blendergt_outputs(frames_folder, suffix, frame, tmp_dir)
else:
cam_util.save_camera_parameters(
camera,
Expand Down