mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-03 01:50:24 +08:00
UCv2Qt: fixed min/max of depth to grayscale conversion for CV_32FC1 type
This commit is contained in:
@@ -78,15 +78,30 @@ inline QImage uCvMat2QImage(const cv::Mat & image, bool isBgr = true)
|
|||||||
{
|
{
|
||||||
// Assume depth image (float in meters)
|
// Assume depth image (float in meters)
|
||||||
const float * data = (const float *)image.data;
|
const float * data = (const float *)image.data;
|
||||||
float min=0, max=0;
|
float min=data[0], max=data[0];
|
||||||
uMinMax(data, image.rows*image.cols, min, max);
|
for(unsigned int i=1; i<image.total(); ++i)
|
||||||
|
{
|
||||||
|
if(!uIsNan(data[i]) && data[i] > 0)
|
||||||
|
{
|
||||||
|
if((uIsNan(min) && data[i] > 0) ||
|
||||||
|
(data[i] > 0 && data[i]<min))
|
||||||
|
{
|
||||||
|
min = data[i];
|
||||||
|
}
|
||||||
|
if((uIsNan(max) && data[i] > 0) ||
|
||||||
|
(data[i] > 0 && data[i]>max))
|
||||||
|
{
|
||||||
|
max = data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
qtemp = QImage(image.cols, image.rows, QImage::Format_Indexed8);
|
qtemp = QImage(image.cols, image.rows, QImage::Format_Indexed8);
|
||||||
for(int y = 0; y < image.rows; ++y, data += image.cols)
|
for(int y = 0; y < image.rows; ++y, data += image.cols)
|
||||||
{
|
{
|
||||||
for(int x = 0; x < image.cols; ++x)
|
for(int x = 0; x < image.cols; ++x)
|
||||||
{
|
{
|
||||||
uchar * p = qtemp.scanLine (y) + x;
|
uchar * p = qtemp.scanLine (y) + x;
|
||||||
if(data[x] < min || data[x] > max || uIsNan(data[x]))
|
if(data[x] < min || data[x] > max || uIsNan(data[x]) || max == min)
|
||||||
{
|
{
|
||||||
*p = 0;
|
*p = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user