stringstream到base64编码并将其发送到服务器ios

时间:2015-10-30 10:23:19

标签: c++ ios objective-c opencv

使用open cv我以cv::Mat格式获取描述符。转换 cv::Matstringstream正在使用此方法:

/// Serialize a cv::Mat to a stringstream
stringstream serialize(Mat input)
{
    // We will need to also serialize the width, height, type and size of the matrix
    int width = input.cols;
    int height = input.rows;
    int type = input.type();
    size_t size = input.total() * input.elemSize();

    // Initialize a stringstream and write the data
    stringstream ss;
    ss.write((char*)(&width), sizeof(int));
    ss.write((char*)(&height), sizeof(int));
    ss.write((char*)(&type), sizeof(int));
    ss.write((char*)(&size), sizeof(size_t));

    // Write the whole image data
    ss.write((char*)input.data, size);

    return ss;
}

现在我想将此stringstream转换为base64编码。如何 使用直接方法成为可能。

1 个答案:

答案 0 :(得分:0)

您可以对string获得的stringstream进行编码,如:

Mat m;
...
std::string s = serialize(m).str();
std::string encoded = base64_encode(s.c_str());
// send "encoded" to server

可以找到base64_encode的代码,例如here