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

Xu's profile - activity

2021-01-13 17:33:34 -0500 received badge  Good Question (source)
2019-08-02 15:15:05 -0500 received badge  Nice Question (source)
2018-01-13 07:25:10 -0500 received badge  Student (source)
2016-11-06 02:34:17 -0500 received badge  Famous Question (source)
2015-11-04 13:37:03 -0500 received badge  Notable Question (source)
2015-03-30 13:06:46 -0500 received badge  Popular Question (source)
2014-09-17 03:56:47 -0500 received badge  Enthusiast
2014-09-05 16:04:35 -0500 received badge  Famous Question (source)
2014-06-12 07:09:06 -0500 received badge  Notable Question (source)
2014-03-10 23:37:19 -0500 received badge  Popular Question (source)
2014-03-06 03:29:47 -0500 asked a question memory leak in imgmsg_to_cv2?

Hi, I have a problem related to CvBridge. When I subscribe a sensor_msgs/Image message and convert to opencv2 format with the function:

cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")

The memory will be eaten up within a few minutes, but problem solved if I try to convert to the old cv format first and then to numpy based cv2 format.

cv_image = np.asarray(self.bridge.imgmsg_to_cv(data, "bgr8"))

cv_bridge version: 1.10.15 & opencv: 2.4.6. Could anyone help me explain where the problem is? Thanks a lot! Here's my test node:

#!/usr/bin/env python   
import sys
import rospy
import cv2
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import numpy as np

class image_converter:

  def __init__(self):
    rospy.init_node('image_converter', anonymous=True)
    self.bridge = CvBridge()
    self.image_sub = rospy.Subscriber("/image_raw", Image, self.callback)

  def callback(self,data):
    try:
      #cv_image = np.asarray(self.bridge.imgmsg_to_cv(data, "bgr8"))
      cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
    except CvBridgeError, e:
      print e

def main(args):
  ic = image_converter()
  try:
    rospy.spin()
  except KeyboardInterrupt:
    print "Shutting down"

if __name__ == '__main__':
    main(sys.argv)