ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

transfer vtk video stream to ros image

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

Poseidonius gravatar image

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

ngrennan gravatar image

Hi,

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

Poseidonius

import vtk

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


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

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

 #Create a mapper and actor
     mapper = vtk.vtkPolyDataMapper()
     mapper.SetInputConnection(sphereSource.GetOutputPort())
     actor = vtk.vtkActor()
     actor.SetMapper(mapper)
     prop = actor.GetProperty()

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

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

 #Render and interact
    renderWindow.Render()

 # Initialize must be called prior to creating timer events.
    renderWindowInteractor.Initialize()

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

 # start the interaction and timer
    renderWindowInteractor.Start()


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

1 Answer

Sort by ยป oldest newest most voted
0

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

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

Question Tools

Stats

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

Seen: 791 times

Last updated: Dec 20 '11