OpenCV将Mat数据保存成伪彩色的PNG影像

void SaveDepthPNG(const cv::Mat_<float> depth, std::string& depth_png_path)
{
    
    
    std::vector<int> compression_params;
    compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
    compression_params.push_back(0);    // 无压缩png.
    compression_params.push_back(cv::IMWRITE_PNG_STRATEGY);
    compression_params.push_back(cv::IMWRITE_PNG_STRATEGY_DEFAULT);

    cv::Mat_<float> color_depth;

    double min;
    double max;
    cv::minMaxIdx(depth, &min, &max);
    cv::Mat adjMap;
    float scale = 255 / (max - min);

    depth.convertTo(adjMap, CV_8UC1, scale, -min * scale);  // beta = -min *scale
    cv::Mat falseColorsMap;
    cv::applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_JET);
    cv::imwrite(depth_png_path, falseColorsMap, compression_params);
    //cv::imshow("Out", falseColorsMap);
    //cv::waitKey(0);
}

猜你喜欢

转载自blog.csdn.net/rdw1246010462/article/details/123117292
今日推荐