// 读取图片文件到内存 std::ifstream file(img.toStdString(), std::ios::binary); std::vector<char> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); cv::Mat image = cv::imdecode(cv::Mat(buffer), cv::IMREAD_COLOR); std::vector<uchar> result; cv::imencode(".png", image, result); std::ofstream os("test.png", std::ios::binary); os.write(reinterpret_cast<char*>(buffer.data()), buffer.size());
标签:std,iterator,buffer,占用,opencv,内存,file,cv From: https://www.cnblogs.com/zach0812/p/17384080.html