ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

transfer vtk video stream to ros image

asked 2011-12-19 17:42:08 -0600

Poseidonius gravatar image

updated 2014-01-28 17:11:01 -0600

ngrennan gravatar image


I use python and vtk to integrate diagrams and AR-stuff into video streams. It works fine, I get a augmented video on my screen. Now I want to transfer this output into a stream of ROS image messages, but I did not find a suitable solution.

For an illustration I adapted a vtk standard example for animations, a moving spere. How to publish the current image during a timer callback?

Best wishes from Germany


import vtk

class vtkTimerCallback():
   def __init__(self):
       self.timer_count = 0 = rospy.Publisher('chatter', image)

   def execute(self,obj,event):
       print self.timer_count, self.timer_count,0);
       iren = obj
       self.timer_count += 1
       if self.timer_count > 10:
       self.timer_count = -10
       # here I want to do something like 

 def main():
 #Create a sphere
     sphereSource = vtk.vtkSphereSource()
     sphereSource.SetCenter(0.0, 0.0, 0.0)

 #Create a mapper and actor
     mapper = vtk.vtkPolyDataMapper()
     actor = vtk.vtkActor()
     prop = actor.GetProperty()

 # Setup a renderer, render window, and interactor
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow() 
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()

 #Add the actor to the scene
    renderer.SetBackground(1,1,1) # Background color white

 #Render and interact

 # Initialize must be called prior to creating timer events.

 # Sign up to receive TimerEvent
    cb = vtkTimerCallback() = actor
    renderWindowInteractor.AddObserver('TimerEvent', cb.execute)
    timerId = renderWindowInteractor.CreateRepeatingTimer(100);

 # start the interaction and timer

if __name__ == '__main__':
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-12-20 00:48:59 -0600

DimitriProsser gravatar image

I'm not sure of any ROS method to convert the VTK datatypes to ROS images. You might have to make a converter for yourself. I'd take a look here to figure out the datatypes in VTK streams. Here is the ROS datatype for images.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-12-19 17:42:08 -0600

Seen: 596 times

Last updated: Dec 20 '11