1

I am trying to serialize an object which has a cv::Mat as a member, I've found this SO page but when I try it I get the following error:

usr/include/boost/archive/basic_xml_iarchive.hpp:70:9: error: no matching function for call to ‘assertion_failed(mpl_::failed************ boost::serialization::is_wrapper::************) note: template int mpl_::assertion_failed(typename mpl_::assert::type) /usr/include/boost/archive/basic_xml_iarchive.hpp: In member function ‘void boost::archive::basic_xml_iarchive::load_override(T&, int) [with T = unsigned char, Archive = boost::archive::xml_iarchive]’:’

In the example on the linked page they use a binary archive, whereas I'm using an xml one, could this be causing the problem?

1 Answer 1

4

Need to add this somewhere in a included header:

namespace boost {
  namespace serialization {


    template<class Archive>
    inline void serialize(Archive & ar, cv::Mat& m, const unsigned int version) {
      int cols = m.cols;
      int rows = m.rows;
      size_t elemSize = m.elemSize();
      size_t elemType = m.type();

      ar & BOOST_SERIALIZATION_NVP(cols);
      ar & BOOST_SERIALIZATION_NVP(rows);
      ar & BOOST_SERIALIZATION_NVP(elemSize);
      ar & BOOST_SERIALIZATION_NVP(elemType); // element type.

      if(m.type() != elemType || m.rows != rows || m.cols != cols) {
        m = cv::Mat(rows, cols, elemType, cv::Scalar(0));
      }

      size_t dataSize = cols * rows * elemSize;
      cout << " datasize is " << dataSize;


      for (size_t dc = 0; dc < dataSize; dc++) {
        std::stringstream ss;
        ss << "elem_"<<dc;
        ar & boost::serialization::make_nvp(ss.str().c_str(), m.data[dc]);
      }

    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.