def __init__(self, window_title='Depth Image', scale=1): self.scale = scale depthImageColorByRange = [0.0, 4.0] lut = vtk.vtkLookupTable() lut.SetNumberOfColors(256) lut.SetHueRange(0, 0.667) # red to blue lut.SetRange(depthImageColorByRange) # map red (near) to blue (far) lut.SetRampToLinear() lut.Build() self.depthScaleFilter = vtk.vtkImageShiftScale() self.depthScaleFilter.SetScale(scale) self.depthScaleFilter.SetOutputScalarTypeToUnsignedShort() self.depthImageLookupTable = lut self.imageMapToColors = vtk.vtkImageMapToColors() self.imageMapToColors.SetLookupTable(self.depthImageLookupTable) self.imageMapToColors.SetInputConnection( self.depthScaleFilter.GetOutputPort()) self.imageView = imageview.ImageView() self.imageView.view.setWindowTitle(window_title) self.imageView.setImage(self.imageMapToColors.GetOutput())
def __init__(self, window_title='Depth Image', scale=1): self.scale = scale depthImageColorByRange = [0.0, 4.0] lut = vtk.vtkLookupTable() lut.SetNumberOfColors(256) lut.SetHueRange(0, 0.667) # red to blue lut.SetRange(depthImageColorByRange) # map red (near) to blue (far) lut.SetRampToLinear() lut.Build() self.depthScaleFilter = vtk.vtkImageShiftScale() self.depthScaleFilter.SetScale(scale) self.depthScaleFilter.SetOutputScalarTypeToUnsignedShort() self.depthImageLookupTable = lut self.imageMapToColors = vtk.vtkImageMapToColors() self.imageMapToColors.SetLookupTable(self.depthImageLookupTable) self.imageMapToColors.SetInputConnection(self.depthScaleFilter.GetOutputPort()) self.imageView = imageview.ImageView() self.imageView.view.setWindowTitle(window_title) self.imageView.setImage(self.imageMapToColors.GetOutput())
def render_depth(renWin, renderer, camera, data_dir, data_dir_name, num_im, out_dir, use_mesh, object_dir, mesh='meshed_scene.ply', keyword=None): actor = vtk.vtkActor() filter1 = vtk.vtkWindowToImageFilter() imageWriter = vtk.vtkPNGWriter() scale = vtk.vtkImageShiftScale() if use_mesh: #use meshed version of scene if not glob.glob(data_dir + "/" + mesh): out = None if glob.glob(data_dir + "/original_log.lcmlog.ply"): out = "original_log.lcmlog.ply" elif glob.glob(data_dir + "/trimmed_log.lcmlog.ply"): out = "trimmed_log.lcmlog.ply" elif glob.glob('*.ply'): out = glob.glob('*.ply')[0] else: return mesher = mesh_wrapper.Mesh(out_dir=data_dir) status = mesher.mesh_cloud(out) print status #blocks until done mapper = vtk.vtkPolyDataMapper() fileReader = vtk.vtkPLYReader() fileReader.SetFileName(data_dir + "/" + mesh) mapper.SetInputConnection(fileReader.GetOutputPort()) actor.SetMapper(mapper) renderer.AddActor(actor) else: #import just the objects objects = common.Objects(data_dir, object_dir) objects.loadObjectMeshes("/registration_result.yaml", renderer, keyword=keyword) #setup filters filter1.SetInput(renWin) filter1.SetMagnification(1) filter1.SetInputBufferTypeToZBuffer() windowToColorBuffer = vtk.vtkWindowToImageFilter() windowToColorBuffer.SetInput(renWin) windowToColorBuffer.SetInputBufferTypeToRGB() scale.SetOutputScalarTypeToUnsignedShort() scale.SetScale(1000) poses = common.CameraPoses(data_dir + "/posegraph.posegraph") for i in range(1, num_im + 1): try: utimeFile = open( data_dir + "/images/" + str(i).zfill(10) + "_utime.txt", 'r') utime = int(utimeFile.read()) #update camera transform cameraToCameraStart = poses.getCameraPoseAtUTime(utime) t = cameraToCameraStart common.setCameraTransform(camera, t) renWin.Render() #update filters filter1.Modified() filter1.Update() windowToColorBuffer.Modified() windowToColorBuffer.Update() #extract depth image depthImage = vtk.vtkImageData() pts = vtk.vtkPoints() ptColors = vtk.vtkUnsignedCharArray() vtk.vtkDepthImageUtils.DepthBufferToDepthImage( filter1.GetOutput(), windowToColorBuffer.GetOutput(), camera, depthImage, pts, ptColors) scale.SetInputData(depthImage) scale.Update() #write out depth image imageWriter.SetFileName(out_dir + str(i).zfill(10) + "_" + data_dir_name + "_depth_ground_truth.png") imageWriter.SetInputConnection(scale.GetOutputPort()) imageWriter.Write() except (IOError): break renderer.RemoveAllViewProps() renWin.Render()
def render_normals(renWin, renderer, camera, data_dir, data_dir_name, num_im, out_dir, use_mesh, object_dir, mesh='meshed_scene.ply', keyword=None): #setup rendering enviornment actor = vtk.vtkActor() filter1 = vtk.vtkWindowToImageFilter() imageWriter = vtk.vtkPNGWriter() scale = vtk.vtkImageShiftScale() if use_mesh: #use meshed version of scene if not glob.glob(data_dir + "/" + mesh): out = "original_log.lcmlog.ply" if glob.glob( data_dir + "/original_log.lcmlog.ply") else "trimmed_log.lcmlog.ply" mesher = mesh_wrapper.Mesh(out_dir=data_dir) status = mesher.mesh_cloud(out) print status #blocks until done mapper = vtk.vtkPolyDataMapper() #shading #set_material_prop(actor) set_shader_input(mapper) fileReader = vtk.vtkPLYReader() fileReader.SetFileName(data_dir + "/" + mesh) mapper.SetInputConnection(fileReader.GetOutputPort()) actor.SetMapper(mapper) renderer.AddActor(actor) else: #import just the objects objects = common.Objects(data_dir, object_dir) objects.loadObjectMeshes("/registration_result.yaml", renderer, keyword=keyword, shader=set_shader_input) #setup rendering enviornment windowToColorBuffer = vtk.vtkWindowToImageFilter() windowToColorBuffer.SetInput(renWin) windowToColorBuffer.SetInputBufferTypeToRGB() #setup camera calibration common.set_up_camera_params(camera) poses = common.CameraPoses(data_dir + "/posegraph.posegraph") for i in range(1, num_im + 1): try: utimeFile = open( data_dir + "/images/" + str(i).zfill(10) + "_utime.txt", 'r') utime = int(utimeFile.read()) #update camera transform cameraToCameraStart = poses.getCameraPoseAtUTime(utime) t = cameraToCameraStart common.setCameraTransform(camera, t) renWin.Render() windowToColorBuffer.Modified() windowToColorBuffer.Update() #write out depth image imageWriter.SetFileName(out_dir + str(i).zfill(10) + "_" + data_dir_name + "_normal_ground_truth.png") imageWriter.SetInputConnection(windowToColorBuffer.GetOutputPort()) imageWriter.Write() except (IOError): break renderer.RemoveAllViewProps() renWin.Render()
#setup view_height = 640 view_width = 480 data_dir = sys.argv[1] num_im = int(sys.argv[2]) mesh = sys.argv[3] mapper = vtk.vtkPolyDataMapper() actor = vtk.vtkActor() renderer = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() interactor = vtk.vtkRenderWindowInteractor() fileReader = vtk.vtkPLYReader() filter1 = vtk.vtkWindowToImageFilter() imageWriter = vtk.vtkBMPWriter() scale = vtk.vtkImageShiftScale() fileReader.SetFileName(sys.argv[1] + "/" + sys.argv[3]) renWin.SetSize(view_height, view_width) camera = vtk.vtkCamera() renderer.SetActiveCamera(camera) mapper.SetInputConnection(fileReader.GetOutputPort()) actor.SetMapper(mapper) renderer.AddActor(actor) renWin.AddRenderer(renderer) interactor.SetRenderWindow(renWin) setCameraInstrinsicsAsus(camera) setCameraTransform(camera, vtk.vtkTransform())