Mat mat(pCodecCtx->height, pCodecCtx->width, CV_8UC3, pFrameYUV->data[0], pFrameYUV->linesize[0]);
imshow("frame", mat);
if (!mat.empty()) {
std::vector<uchar> data_encode;
int res = imencode(".jpg", mat, data_encode);
std::string str_encode(data_encode.begin(), data_encode.end());
//char *char_r = new char[str_encode.size()];
char* char_r=(char *)malloc(sizeof(char) * (str_encode.size()));
memcpy(char_r, str_encode.data(), sizeof(char) * (str_encode.size()));
//strcpy(char_r, str_encode.data());
//char_r = const_cast<char*>(str_encode.data());
//char_r[str_encode.size() - 1] = '\0';
Mat img_decode;
std::string str_tmp(char_r, str_encode.size());
if (str_tmp.compare(str_encode) == 0) {
printf("ok");
}
std::vector<uchar> data(str_tmp.begin(), str_tmp.end());
img_decode = imdecode(data, CV_LOAD_IMAGE_COLOR);
imshow("pic", img_decode);
waitKey(10);
c++ opencv imencode imdecode string转换
于 2018-02-13 15:16:23 首次发布