transfer vtk video stream to ros 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()