memory leak in imgmsg_to_cv2?

asked 2014-03-06 03:29:47 -0500

Xu gravatar image

updated 2016-10-24 08:36:02 -0500

ngrennan gravatar image

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):
      #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()
  except KeyboardInterrupt:
    print "Shutting down"

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