I am trying to subscribe to the "/camera/image_color" topic which is data from my camera. I then want to do some voodoo on these images in opencv and publish them at a specific frequency. So that I can subscribe to them with another node.
I have sofar tried the below code, and many many variations thereof. At this point the code is doing nothing. No images are being published to the "/imagetimer" topic. I get an output "Timing images" then nothing happens further.
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
import cv2
import os
import numpy as np
class Nodo(object):
def __init__(self):
# Params
self.image = None
self.br = CvBridge()
# Node cycle rate (in Hz).
self.loop_rate = rospy.Rate(1)
# Publishers
self.pub = rospy.Publisher('imagetimer', Image,queue_size=10)
# Subscribers
rospy.Subscriber("/camera/image_color",Image,self.callback)
def callback(self, msg):
self.image = self.br.imgmsg_to_cv2(msg)
def start(self):
rospy.loginfo("Timing images")
rospy.spin()
br = CvBridge()
while not rospy.is_shutdown():
rospy.loginfo('publishing image')
#br = CvBridge()
self.pub.publish(br.cv2_to_imgmsg(self.image))
rate.sleep()
if __name__ == '__main__':
rospy.init_node("imagetimer111", anonymous=True)
my_node = Nodo()
my_node.start()