OpenCV:如何可视化深度图像 [英] OpenCV: How to visualize a depth image

查看:3044
本文介绍了OpenCV:如何可视化深度图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的数据集,其中有图像,其中每个像素是一个16位无符号整数存储该像素的深度值,以毫米为单位。我试图通过执行以下操作将其形象化为灰度深度图像:

I am using a dataset in which it has images where each pixel is a 16 bit unsigned int storing the depth value of that pixel in mm. I am trying to visualize this as a greyscale depth image by doing the following:

cv::Mat depthImage; 
depthImage = cv::imread("coffee_mug_1_1_1_depthcrop.png", CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR ); // Read the file 
depthImage.convertTo(depthImage, CV_32F); // convert the image data to float type   
namedWindow("window");
float max = 0;
for(int i = 0; i < depthImage.rows; i++){
    for(int j = 0; j < depthImage.cols; j++){
        if(depthImage.at<float>(i,j) > max){
            max = depthImage.at<float>(i,j);
        }
    }   
}
cout << max << endl;


float divisor = max / 255.0;
cout << divisor << endl;
for(int i = 0; i < depthImage.rows; i++){
    for(int j = 0; j < depthImage.cols; j++){
        cout << depthImage.at<float>(i,j) << ", ";
        max = depthImage.at<float>(i,j) /= divisor;
        cout << depthImage.at<float>(i,j) << endl;
    }   
}


imshow("window", depthImage);
waitKey(0);

但是,它只显示两种颜色,这是因为所有的值都在一起,范围150-175 +显示黑色的小值(见下文)。

However, it is only showing two colours this is because all of the values are close together i.e. in the range of 150-175 + the small values which show up black (see below).


有没有办法规范化这些数据,使它显示各种灰度级来突出这些小的深度差异?

Is there a way to normalize this data such that it will show various grey levels to highlight these small depth differences?

推荐答案

根据文档,imshow函数可以用于各种图像类型。它支持16位无符号图片,因此可以使用

According to the documentation, the function imshow can be used with a variety of image types. It support 16-bit unsigned images, so you can display your image using

cv::Mat map = cv::imread("image", CV_LOAD_IMAGE_ANYCOLOR | CV_LOAD_IMAGE_ANYDEPTH);
cv::imshow("window", map);

在这种情况下,图像值范围从范围[0,255 * 256]范围[0,255]。

In this case, the image value range is mapped from the range [0, 255*256] to the range [0, 255].

如果您的图像只包含此范围低部分的值,您将观察到一个模糊的图像。如果要使用完整的显示范围(从黑色到白色),您应该调整图像以覆盖预期的动态范围,一种方法是

If your image only contains values on the low part of this range, you will observe an obscure image. If you want to use the full display range (from black to white), you should adjust the image to cover the expected dynamic range, one way to do it is

double min;
double max;
cv::minMaxIdx(map, &min, &max);
cv::Mat adjMap;
cv::convertScaleAbs(map, adjMap, 255 / max);
cv::imshow("Out", adjMap);

这篇关于OpenCV:如何可视化深度图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆