opencv图片内存占用过大优化
// 读取图片文件到内存 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());