IplImage* dispImg =
bridge[2].imgMsgToCv(&(disparity_msg->image), "passthrough");

and let boost::shared_ptr do its magic.

Or, is there something more subtle I just missed?


shared_ptr will not (and cannot) autoconvert from a pointer.  Explicitly creating a shared_ptr naively from image in this case will cause shared_ptr to try and delete that pointer, which will crash since that pointer is not valid for deletion.

I believe you can do something like the following (untested):

sensor_msgs::ImageConstPtr image_ptr(disparity_msg, &disparity_msgs->image);

This will share the reference count with disparity_msg, but act like a pointer to an Image.

Josh