1

我正在尝试序列化一个具有 cv::Mat 作为成员的对象,我找到了这个SO 页面,但是当我尝试它时,我收到以下错误:

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 ::************) 注意:模板 int mpl_::assertion_failed(typename mpl_::assert::type) /usr/include/boost/archive/basic_xml_iarchive.hpp: 在成员函数' void boost::archive::basic_xml_iarchive::load_override(T&, int) [with T = unsigned char, Archive = boost::archive::xml_iarchive]':'</p>

在链接页面上的示例中,他们使用二进制存档,而我使用的是 xml 存档,这会导致问题吗?

4

1 回答 1

4

需要在包含的标题中的某处添加它:

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]);
      }

    }
  }
}
于 2013-09-27T11:39:20.710 回答