【发布时间】:2012-11-30 04:07:54
【问题描述】:
我正在使用一个数据集,其中包含图像,其中每个像素都是一个 16 位无符号整数,以毫米为单位存储该像素的深度值。我试图通过执行以下操作将其可视化为灰度深度图像:
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 的范围内 + 显示为黑色的小值(见下文)。
有没有办法对这些数据进行归一化,使其显示各种灰度以突出这些小的深度差异?
【问题讨论】:
标签: c++ opencv visualization kinect depth