@@ -511,7 +511,7 @@ def fit_single_frame(img,
511511
512512 material = pyrender .MetallicRoughnessMaterial (
513513 metallicFactor = 0.0 ,
514- alphaMode = 'BLEND ' ,
514+ alphaMode = 'OPAQUE ' ,
515515 baseColorFactor = (1.0 , 1.0 , 0.9 , 1.0 ))
516516 mesh = pyrender .Mesh .from_trimesh (
517517 out_mesh ,
@@ -523,6 +523,9 @@ def fit_single_frame(img,
523523
524524 camera_center = camera .center .detach ().cpu ().numpy ().squeeze ()
525525 camera_transl = camera .translation .detach ().cpu ().numpy ().squeeze ()
526+ # Equivalent to 180 degrees around the y-axis. Transforms the fit to
527+ # OpenGL compatible coordinate system.
528+ camera_transl [0 ] *= - 1.0
526529
527530 camera_pose = np .eye (4 )
528531 camera_pose [:3 , 3 ] = camera_transl
@@ -532,26 +535,21 @@ def fit_single_frame(img,
532535 cx = camera_center [0 ], cy = camera_center [1 ])
533536 scene .add (camera , pose = camera_pose )
534537
535- light = pyrender .PointLight (color = [1.0 , 1.0 , 1.0 ], intensity = 1 )
536-
537- light_pose = np .eye (4 )
538- light_pose [:3 , 3 ] = [0 , - 1 , 1 ]
539- scene .add (light , pose = light_pose )
540-
541- light_pose [:3 , 3 ] = [0 , 1 , 1 ]
542- scene .add (light , pose = light_pose )
543-
544- light_pose [:3 , 3 ] = [1 , 1 , 2 ]
545- scene .add (light , pose = light_pose )
538+ # Get the lights from the viewer
539+ light_nodes = monitor .mv .viewer ._create_raymond_lights ()
540+ for node in light_nodes :
541+ scene .add_node (node )
546542
547543 r = pyrender .OffscreenRenderer (viewport_width = W ,
548544 viewport_height = H ,
549545 point_size = 1.0 )
550- color , _ = r .render (scene )
551-
552- color = color .astype (np .float32 ) / 255
546+ color , _ = r .render (scene , flags = pyrender .RenderFlags .RGBA )
547+ color = color .astype (np .float32 ) / 255.0
553548
554- output_img = color .copy ()
549+ valid_mask = (color [:, :, - 1 ] > 0 )[:, :, np .newaxis ]
550+ input_img = img .detach ().cpu ().numpy ()
551+ output_img = (color [:, :, :- 1 ] * valid_mask +
552+ (1 - valid_mask ) * input_img )
555553
556554 img = pil_img .fromarray ((output_img * 255 ).astype (np .uint8 ))
557555 img .save (out_img_fn )
0 commit comments