2

I've implemented serialization for OpenCVs Mat format as described here: Serializing OpenCV Mat_<Vec3f>

I now got the problem to serialize a shared pointer to a cv::Mat. It gives the following errors:

/usr/include/boost/serialization/shared_ptr.hpp: In function ‘void boost::serialization::serialize(Archive&, boost::shared_ptr<U>&, unsigned int) [with Archive = boost::archive::text_iarchive, T = boost::shared_ptr<cv::Mat>]’: /usr/include/boost/serialization/serialization.hpp:128:9:

instantiated from ‘void >boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = >boost::archive::text_iarchive, T = boost::shared_ptr >]’ /usr/include/boost/archive/detail/iserializer.hpp:188:5:

instantiated from ‘void >boost::archive::detail::iserializer::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::text_iarchive, T = boost::shared_ptr >]’ recognition2d3d.cpp:227:1: instantiated from here

/usr/include/boost/serialization/shared_ptr.hpp:167:5: error: static assertion failed: "boost::serialization::tracking_level< T >::value != boost::serialization::track_never"`

I tried to use BOOST_CLASS_TRACKING, but could not get it working. Actually i don't really understand what the problem is, reading the boost documentation didn't help to solve this issue.

Community
  • 1
  • 1
  • 1
    If you get this error, then maybe the tracking is disabled for this type? Look for something like `BOOST_CLASS_TRACKING(cv::Mat, boost::serialization::track_never)`. – Igor R. Feb 06 '13 at 08:56

1 Answers1

0

I think you can't serialize through a shared_ptr unless the object pointed to has a vtable. Try making the object's destructor virtual.

Edit: alternatively, wrap the object (an OpenCV matrix?) in an object that has a virtual destructor.

  • I was able to serialized `boost::shared_ptr` to a class with no virtual destructor `struct A{ double d_; A(double d = 0) : d_(d){} template void serialize(Archive& ar, unsigned = 0){ ar & boost::serialization::make_nvp("d", d_); } };` both with clang and gcc. – alfC Aug 25 '14 at 22:09