vendredi 4 décembre 2015

Unable to deserialize with boost from sqlite blob

i am trying to read blob data from sqlite and deserialize it my code

   int init_search(std::string db_path, cv::Mat *voc1, std::list<std::string> *desc_lst)
    {
    sqlite3 *sqdb;
    int rc;
    unsigned char  *bow_data;
    const char *bow_key ;
int bow_size;

cv::Mat bow_desc,desc_tmp;
//const size_t data_size_bow;
rc = sqlite3_open("C:\\aa\\cvdb\\dna.db", &sqdb);
sqlite3_stmt *stmt = NULL;

do 
{
    rc = sqlite3_prepare_v2(sqdb, "SELECT * FROM dna_tab", -1, &stmt, NULL);
    //sqlite3_bind_text(stmt, 3, bow_key, -1, SQLITE_STATIC);
    rc = sqlite3_step(stmt);
    if (rc == SQLITE_ROW)
    {
        bow_size = sqlite3_column_bytes(stmt, 3);
        bow_data = (unsigned char *)malloc(bow_size);
        //memcpy(bow_data, sqlite3_column_blob(stmt, 3), bow_size);
        //std::stringstream s(bow_key,std::ios_base::in |std::ios_base::binary);
        std::stringstream s((const char *)sqlite3_column_blob(stmt, 3), std::ios_base::binary);


        boost::archive::binary_iarchive  oa(s, std::ios_base::binary);
        oa >> bow_desc;

        cout << bow_desc;
    }
    rc = sqlite3_finalize(stmt);


} while (rc == SQLITE_SCHEMA);
sqlite3_close(sqdb);
return 0;
}

and here is mat object load and save code, i am able to save it to sqlite blob but getting unhandled exception while trying to deserialize

     BOOST_SERIALIZATION_SPLIT_FREE(::cv::Mat)
 namespace boost {
   namespace serialization {

    /** Serialization support for cv::Mat */
    template <class Archive>
        void save(Archive& ar, const ::cv::Mat& m, const unsigned int version)
        {
        size_t elem_size = m.elemSize();
        size_t elem_type = m.type();

        ar & m.cols;
        ar & m.rows;
        ar & elem_size;
        ar & elem_type;

        const size_t data_size = m.cols * m.rows * elem_size;
        ar & boost::serialization::make_array(m.ptr(), data_size);
        }

    /** Serialization support for cv::Mat */
    template <class Archive>
        void load(Archive& ar, ::cv::Mat& m, const unsigned int version)
        {
        int cols, rows;
        size_t elem_size, elem_type;

        ar & cols;
        ar & rows;
        ar & elem_size;
        ar & elem_type;

        m.create(rows, cols, elem_type);

        size_t data_size = m.cols * m.rows * elem_size;
        ar & boost::serialization::make_array(m.ptr(), data_size);
        }

      }
   };

Please help...

Aucun commentaire:

Enregistrer un commentaire