[ros-users] cvBridge + opencv memory leak problem
bradski at willowgarage.com
Sun May 23 01:17:21 UTC 2010
I'm at home not on a computer with code, but I believe you can use Mat in
the old cv functions as follows
Mat planes = ... from bridge or wherever. (whereever an IplImage is
produced, you can just assign it to a Mat).
. . .
IplImage cv_planes_0 = planes;
Then use IplImage as normal in the old cv functions. The memory will do the
On Sat, May 22, 2010 at 5:20 PM, Patrick Mihelich <mihelich at willowgarage.com
> In your example, im_left is owned by left_bridge and should not be
> released. However any images you create yourself do need to be released. The
> memory leak is from not releasing "test".
> The original OpenCV C API<http://opencv.willowgarage.com/documentation/c/index.html>works with IplImage's. The new C++
> API <http://opencv.willowgarage.com/documentation/cpp/index.html> cv::Mat
> is easier to use and avoids having to release memory manually.
> cv_bridge only uses IplImage because it predates the OpenCV C++ API. The
> next revision of cv_bridge will likely use cv::Mat, precisely to avoid this
> sort of confusion.
> On Sat, May 22, 2010 at 4:54 PM, chriss lei <lei.chriss at gmail.com> wrote:
>> Hello Radu,
>> I'm well aware of using cvReleaseImage..
>> Memory leak happens even if I use a single function on IplImage converted
>> from sensor_msgs.
>> Here's my callback function to illustrate. Usage of cvCopy here introduces
>> memory blowup problem.
>> void callback(const sensor_msgs::CameraInfo::ConstPtr& info,
>> const sensor_msgs::ImageConstPtr& left,
>> const stereo_msgs::DisparityImageConstPtr&
>> im_left = left_bridge.imgMsgToCv(left, "passthrough");
>> disp_bridge.fromImage(disparity_msg->image, "passthrough");
>> dispImg = disp_bridge.toIpl();
>> cvShowImage("left", im_left);
>> IplImage* test = NULL;
>> test = cvCreateImage(cvGetSize(dispImg), dispImg->depth,
>> cvCopy(dispImg, test);
>> cvShowImage("disp", test);
>> Also, I'm not supposed to deallocate any IplImages that are converted from
>> sensor_msgs as described in cvBridge tutorial.
>> Is there a way to use opencv functions on IplImages and not use cv::Mat ?
>> View this message in context:
>> Sent from the ROS-Users mailing list archive at Nabble.com.
>> ros-users mailing list
>> ros-users at lists.sourceforge.net
>> ros-users mailing list
>> ros-users at code.ros.org
> ros-users mailing list
> ros-users at code.ros.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the ros-users