Unable to return updated variable

I am trying to feed in and return a variable that is updated within a function. The program works and will update within the class, however I need the updated variable to return to the main program as the rest relies on this variable. It says that data is not defined globally, however I have tried defining data and setting it to different things. I'm unsure what I would globally define data as for the program to work the same.

class image_converter:
  def __init__(self):

    topic_base_name = "/" + os.getenv("ROBOT_NAME")
    
    self.last_frame = None
    self.bridge = CvBridge()
    
    self.sub_camr = rospy.Subscriber(topic_base_name + "/sensors/camr/compressed",
          CompressedImage, self.callback, queue_size=1, tcp_nodelay=True)
    
  
  def callback(self,data,count):

    self.image_converter = CvBridge()
        
    # silently (ish) handle corrupted JPEG frames
    try:

            # convert compressed ROS image to raw CV image
      image = self.image_converter.compressed_imgmsg_to_cv2(data, "rgb8")

 # detect movement
 # increment count by 1 when movement detected

return count

def main():
  count = 0
  ic = image_converter()
  counter = ic.callback(data,counter)

if __name__ == '__main__':
    main()'''


Read more here: https://stackoverflow.com/questions/66266433/unable-to-return-updated-variable

Content Attribution

This content was originally published by ncurn at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: