【问题标题】:stringstream to base64 encode and send it to the server iosstringstream 到 base64 编码并将其发送到服务器 ios
【发布时间】:2016-01-30 17:51:48
【问题描述】:

使用 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 编码。如何 以直接的方式使其成为可能。

【问题讨论】:

  • 我通常使用this piece of code来进行base64编码/编码。但是你不能只发送 YAML/XML 吗?
  • 另外,在您的序列化中,您应该注意图像不连续的情况。查看here 以供参考,matwrite 方法
  • 但我提到了他们提到 base 64 是最佳选择的帖子。这就是为什么要转换.. 哪个是最好的.. xml 或 yaml 或 base64 ???
  • 我只想将描述符(cv::Mat 格式)发送到网络服务器.. 请建议.. 我正在使用 opencv 3.0
  • 您好,我只是想将 stringstream 格式转换为 base64 编码.. 但您提到了从字符串到 base64 的转换..

标签: c++ ios objective-c opencv


【解决方案1】:

你可以对stringstream得到的string进行编码,比如:

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

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

【讨论】:

  • - (void) frameCaptured:(cv::Mat) frame{ cv::Mat grayMat; cv::cvtColor(frame, grayMat, CV_BGR2GRAY); // UIImage *finaleImg = [self UIImageFromCVMat:greyMat]; orb -> 检测(greyMat,keypoints1); orb -> 计算(greyMat,keypoints1,descriptors1); drawKeypoints(greyMat, keypoints1, outImage); std::string s = serialize(descriptors1).str(); std::string 编码 = base64_encode(reinterpret_cast(s.c_str()), s.length()); NSLog(@"%s",encoded.c_str()); }
  • 这里正在从相机获取数据并以 mat 格式创建描述符。现在正在序列化 mat 格式并编码为 base64 格式..
  • 这样对吗??那我怎样才能通过套接字发送它......??
  • 我无法测试您的代码。你应该知道它是否工作正常。问题是关于获取 base64 编码,这就是我的答案。套接字和网络相关的东西应该放在另一个问题中。
  • 为了序列化我使用这个方法...// 序列化一个 cv::Mat 到一个字符串流
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-19
  • 1970-01-01
  • 2015-10-13
  • 1970-01-01
  • 2014-12-07
  • 1970-01-01
相关资源
最近更新 更多