当前位置:   article > 正文

c++ opencv imencode imdecode string转换

c++ opencv imencode

  1. Mat mat(pCodecCtx->height, pCodecCtx->width, CV_8UC3, pFrameYUV->data[0], pFrameYUV->linesize[0]);
  2. imshow("frame", mat);
  3. if (!mat.empty()) {
  4. std::vector<uchar> data_encode;
  5. int res = imencode(".jpg", mat, data_encode);
  6. std::string str_encode(data_encode.begin(), data_encode.end());
  7. //char *char_r = new char[str_encode.size()];
  8.  
  9. char* char_r=(char *)malloc(sizeof(char) * (str_encode.size()));
  10. memcpy(char_r, str_encode.data(), sizeof(char) * (str_encode.size()));
  11. //strcpy(char_r, str_encode.data());
  12. //char_r = const_cast<char*>(str_encode.data());
  13. //char_r[str_encode.size() - 1] = '\0';
  14. Mat img_decode;
  15. std::string str_tmp(char_r, str_encode.size());
  16. if (str_tmp.compare(str_encode) == 0) {
  17. printf("ok");
  18. }
  19. std::vector<uchar> data(str_tmp.begin(), str_tmp.end());
  20. img_decode = imdecode(data, CV_LOAD_IMAGE_COLOR);
  21. imshow("pic", img_decode);
  22. waitKey(10);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/523027
推荐阅读
相关标签
  

闽ICP备14008679号