owl-project / NVISII

Apache License 2.0
327 stars 28 forks source link

render data on segmentation (entity id) does not include the background #114

Open TontonTremblay opened 3 years ago

TontonTremblay commented 3 years ago

I have loaded a scene from an obj with about 217 entities. There is a discrempency between render_data vs. render_data_to_file. He is a snippet of code and its output.

        segmentation_array = visii.render_data(
            width=int(cfg.width), 
            height=int(cfg.height), 
            start_frame=0,
            frame_count=1,
            bounce=int(0),
            options="entity_id",
        )
        segmentation_array2 = np.array(segmentation_array).reshape(cfg.height,cfg.width,4)
        print(len(entity_visii_name_list))
        print('min',np.min(segmentation_array2))
        print('max',np.max(segmentation_array2))

        visii.render_data_to_file(
            width=int(cfg.width), 
            height=int(cfg.height), 
            start_frame=0,
            frame_count=1,
            bounce=int(0),
            options="entity_id",
            file_path=f"{cfg.outf}/{str(i_frame).zfill(5)}.seg.exr"
        )

        import cv2 
        im = cv2.imread(f"{cfg.outf}/{str(i_frame).zfill(5)}.seg.exr",cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
        im[im > 3.4028235e+37] = 0
        print(np.min(im))
        print(np.max(im))

output:

217
min 0.0
max 0.0
0.0
216.0
natevm commented 2 years ago

Have you tried specifying a common seed for both of these functions?

Neburski commented 2 years ago

Understanding the depth returned by render_data

He didn't specify a seed, but according to the documentation (and in the header include/nvisii/nvisii.h it should be 0 for both cases.

However, when you look at the renderDataToFile implementation in src/nvisii/nvisii.cpp, you see that the seed which is passed into renderDataToFile is not passed on to renderData. That could lead to issues in the future.

image

Given that @TontonTremblay is doing two sequential calls to renderData and my findings in #125 where the results depend on the order of calling these functions. Could these two issue be related?

natevm commented 2 years ago

good catch, could be related yeah. That seed should definitely be forwarded in that function.

natevm commented 2 years ago

@Neburski do you think you could open a pull request that fixes this seed bug?

caixiaoniweimar commented 2 years ago

@natevm Hi, I have followed your discussions, and found I have the same issue as @TontonTremblay, after using the methodsegmentation_array = nvisii.render_data, the max and min of segmentation_array are always zero. I have tried to add seed argument, however, it shows the same results as zero.

But when I tried the suggestion of coloring the segmentation image presented by @TontonTremblay in the Issue. #149 , it works, It can generate the segmentation map correctly. But I have to use the method nvisii.render_data_to_file to save the seg.exr file locally.

Could you please tell me how to solve the issues of zero outputs of the segmentation_array without saving the additional seg.exr file? I want to check where there are objects and where there are not, so that I can generate random positions of objects without collisions. Thanks in advance!

Best Regards, Cai