通过SFM重建后的三维点,想把它的深度图显示出来
原来是
double minVal,maxVal;
minMaxLoc(depths, &minVal, &maxVal);
Mat tmp(768,1024,CV_8UC3,Scalar(0,0,0));
for (unsigned int i=0; i
我发现有点问题,按照HSV理论大致应该是 红橙黄绿青蓝紫
我测试了一下:
Mat image1(500, 500, CV_8UC3, Scalar(0, 0, 0));
for (int kf = 0; kf < image1.rows; kf++)
{
for (int j = 0; j < image1.cols; j++)
{
float a = 255 * (kf / 500.00);
image1.at(kf, j)[0] = 255 * (kf / 500.00);
image1.at(kf, j)[1] = 255;
image1.at(kf, j)[2] = 255;
}
}
cvtColor(image1, image1, CV_HSV2BGR);
imshow("Depth Map1", image1);
系数从0到1,发现会有颜色会有回转
这个感觉无法做到表示深度
后来就想jet表示深度,不用HSV模型
写了一个代码
Mat pts(256, 1, CV_32FC3);
float r[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00588235294117645f, 0.02156862745098032f, 0.03725490196078418f, 0.05294117647058827f, 0.06862745098039214f, 0.084313725490196f, 0.1000000000000001f, 0.115686274509804f, 0.1313725490196078f, 0.1470588235294117f, 0.1627450980392156f, 0.1784313725490196f, 0.1941176470588235f, 0.2098039215686274f, 0.2254901960784315f, 0.2411764705882353f, 0.2568627450980392f, 0.2725490196078431f, 0.2882352941176469f, 0.303921568627451f, 0.3196078431372549f, 0.3352941176470587f, 0.3509803921568628f, 0.3666666666666667f, 0.3823529411764706f, 0.3980392156862744f, 0.4137254901960783f, 0.4294117647058824f, 0.4450980392156862f, 0.4607843137254901f, 0.4764705882352942f, 0.4921568627450981f, 0.5078431372549019f, 0.5235294117647058f, 0.5392156862745097f, 0.5549019607843135f, 0.5705882352941174f, 0.5862745098039217f, 0.6019607843137256f, 0.6176470588235294f, 0.6333333333333333f, 0.6490196078431372f, 0.664705882352941f, 0.6803921568627449f, 0.6960784313725492f, 0.7117647058823531f, 0.7274509803921569f, 0.7431372549019608f, 0.7588235294117647f, 0.7745098039215685f, 0.7901960784313724f, 0.8058823529411763f, 0.8215686274509801f, 0.8372549019607844f, 0.8529411764705883f, 0.8686274509803922f, 0.884313725490196f, 0.8999999999999999f, 0.9156862745098038f, 0.9313725490196076f, 0.947058823529412f, 0.9627450980392158f, 0.9784313725490197f, 0.9941176470588236f, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9862745098039216f, 0.9705882352941178f, 0.9549019607843139f, 0.93921568627451f, 0.9235294117647062f, 0.9078431372549018f, 0.892156862745098f, 0.8764705882352941f, 0.8607843137254902f, 0.8450980392156864f, 0.8294117647058825f, 0.8137254901960786f, 0.7980392156862743f, 0.7823529411764705f, 0.7666666666666666f, 0.7509803921568627f, 0.7352941176470589f, 0.719607843137255f, 0.7039215686274511f, 0.6882352941176473f, 0.6725490196078434f, 0.6568627450980391f, 0.6411764705882352f, 0.6254901960784314f, 0.6098039215686275f, 0.5941176470588236f, 0.5784313725490198f, 0.5627450980392159f, 0.5470588235294116f, 0.5313725490196077f, 0.5156862745098039f, 0.5f };
float g[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.001960784313725483f, 0.01764705882352935f, 0.03333333333333333f, 0.0490196078431373f, 0.06470588235294117f, 0.08039215686274503f, 0.09607843137254901f, 0.111764705882353f, 0.1274509803921569f, 0.1431372549019607f, 0.1588235294117647f, 0.1745098039215687f, 0.1901960784313725f, 0.2058823529411764f, 0.2215686274509804f, 0.2372549019607844f, 0.2529411764705882f, 0.2686274509803921f, 0.2843137254901961f, 0.3f, 0.3156862745098039f, 0.3313725490196078f, 0.3470588235294118f, 0.3627450980392157f, 0.3784313725490196f, 0.3941176470588235f, 0.4098039215686274f, 0.4254901960784314f, 0.4411764705882353f, 0.4568627450980391f, 0.4725490196078431f, 0.4882352941176471f, 0.503921568627451f, 0.5196078431372548f, 0.5352941176470587f, 0.5509803921568628f, 0.5666666666666667f, 0.5823529411764705f, 0.5980392156862746f, 0.6137254901960785f, 0.6294117647058823f, 0.6450980392156862f, 0.6607843137254901f, 0.6764705882352942f, 0.692156862745098f, 0.7078431372549019f, 0.723529411764706f, 0.7392156862745098f, 0.7549019607843137f, 0.7705882352941176f, 0.7862745098039214f, 0.8019607843137255f, 0.8176470588235294f, 0.8333333333333333f, 0.8490196078431373f, 0.8647058823529412f, 0.8803921568627451f, 0.8960784313725489f, 0.9117647058823528f, 0.9274509803921569f, 0.9431372549019608f, 0.9588235294117646f, 0.9745098039215687f, 0.9901960784313726f, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9901960784313726f, 0.9745098039215687f, 0.9588235294117649f, 0.943137254901961f, 0.9274509803921571f, 0.9117647058823528f, 0.8960784313725489f, 0.8803921568627451f, 0.8647058823529412f, 0.8490196078431373f, 0.8333333333333335f, 0.8176470588235296f, 0.8019607843137253f, 0.7862745098039214f, 0.7705882352941176f, 0.7549019607843137f, 0.7392156862745098f, 0.723529411764706f, 0.7078431372549021f, 0.6921568627450982f, 0.6764705882352944f, 0.6607843137254901f, 0.6450980392156862f, 0.6294117647058823f, 0.6137254901960785f, 0.5980392156862746f, 0.5823529411764707f, 0.5666666666666669f, 0.5509803921568626f, 0.5352941176470587f, 0.5196078431372548f, 0.503921568627451f, 0.4882352941176471f, 0.4725490196078432f, 0.4568627450980394f, 0.4411764705882355f, 0.4254901960784316f, 0.4098039215686273f, 0.3941176470588235f, 0.3784313725490196f, 0.3627450980392157f, 0.3470588235294119f, 0.331372549019608f, 0.3156862745098041f, 0.2999999999999998f, 0.284313725490196f, 0.2686274509803921f, 0.2529411764705882f, 0.2372549019607844f, 0.2215686274509805f, 0.2058823529411766f, 0.1901960784313728f, 0.1745098039215689f, 0.1588235294117646f, 0.1431372549019607f, 0.1274509803921569f, 0.111764705882353f, 0.09607843137254912f, 0.08039215686274526f, 0.06470588235294139f, 0.04901960784313708f, 0.03333333333333321f, 0.01764705882352935f, 0.001960784313725483f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
float b[] = { 0.5f, 0.5156862745098039f, 0.5313725490196078f, 0.5470588235294118f, 0.5627450980392157f, 0.5784313725490196f, 0.5941176470588235f, 0.6098039215686275f, 0.6254901960784314f, 0.6411764705882352f, 0.6568627450980392f, 0.6725490196078432f, 0.6882352941176471f, 0.7039215686274509f, 0.7196078431372549f, 0.7352941176470589f, 0.7509803921568627f, 0.7666666666666666f, 0.7823529411764706f, 0.7980392156862746f, 0.8137254901960784f, 0.8294117647058823f, 0.8450980392156863f, 0.8607843137254902f, 0.8764705882352941f, 0.892156862745098f, 0.907843137254902f, 0.9235294117647059f, 0.9392156862745098f, 0.9549019607843137f, 0.9705882352941176f, 0.9862745098039216f, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9941176470588236f, 0.9784313725490197f, 0.9627450980392158f, 0.9470588235294117f, 0.9313725490196079f, 0.915686274509804f, 0.8999999999999999f, 0.884313725490196f, 0.8686274509803922f, 0.8529411764705883f, 0.8372549019607844f, 0.8215686274509804f, 0.8058823529411765f, 0.7901960784313726f, 0.7745098039215685f, 0.7588235294117647f, 0.7431372549019608f, 0.7274509803921569f, 0.7117647058823531f, 0.696078431372549f, 0.6803921568627451f, 0.6647058823529413f, 0.6490196078431372f, 0.6333333333333333f, 0.6176470588235294f, 0.6019607843137256f, 0.5862745098039217f, 0.5705882352941176f, 0.5549019607843138f, 0.5392156862745099f, 0.5235294117647058f, 0.5078431372549019f, 0.4921568627450981f, 0.4764705882352942f, 0.4607843137254903f, 0.4450980392156865f, 0.4294117647058826f, 0.4137254901960783f, 0.3980392156862744f, 0.3823529411764706f, 0.3666666666666667f, 0.3509803921568628f, 0.335294117647059f, 0.3196078431372551f, 0.3039215686274508f, 0.2882352941176469f, 0.2725490196078431f, 0.2568627450980392f, 0.2411764705882353f, 0.2254901960784315f, 0.2098039215686276f, 0.1941176470588237f, 0.1784313725490199f, 0.1627450980392156f, 0.1470588235294117f, 0.1313725490196078f, 0.115686274509804f, 0.1000000000000001f, 0.08431372549019622f, 0.06862745098039236f, 0.05294117647058805f, 0.03725490196078418f, 0.02156862745098032f, 0.00588235294117645f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Mat rr(256, 1, CV_32FC1, r); // red
Mat gg(256, 1, CV_32FC1, g); // green
Mat bb(256, 1, CV_32FC1, b); // blue
for (int i = 0; i < pts.rows; i++)
{
pts.at(i, 0)[0] = rr.at(i, 0);
pts.at(i, 0)[1] = gg.at(i, 0);
pts.at(i, 0)[2] = bb.at(i, 0);
}
Mat image3(256, 500, CV_8UC3, Scalar(0, 0, 0));
for (int kf = 0; kf < image3.rows; kf++)
{
for (int j = 0; j < image3.cols; j++)
{
image3.at(kf, j)[0] = 255 * pts.at(kf, 0)[0];
image3.at(kf, j)[1] = 255 * pts.at(kf, 0)[1];
image3.at(kf, j)[2] = 255 * pts.at(kf, 0)[2];
}
}
imshow("Depth Map5", image3);
waitKey();
Mat test1 = cv::imread("5_IMG_DepthMap.tif", -1);
double min;
double max;
cv::minMaxIdx(test1, &min, &max);
cv::Mat adjMap;
// expand your range to 0..255. Similar to histEq();
test1.convertTo(adjMap,CV_8UC1, 255 / (max-min), -min* (255/(max-min)) );
//test1.convertTo(adjMap,CV_8UC1, 255 / (max-min));
// this is great. It converts your grayscale image into a tone-mapped one,
// much more pleasing for the eye
// function is found in contrib module, so include contrib.hpp
// and link accordingly
cv::Mat falseColorsMap;
// enum
// {
// COLORMAP_AUTUMN = 0,
// COLORMAP_BONE = 1,
// COLORMAP_JET = 2,
// COLORMAP_WINTER = 3,
// COLORMAP_RAINBOW = 4,
// COLORMAP_OCEAN = 5,
// COLORMAP_SUMMER = 6,
// COLORMAP_SPRING = 7,
// COLORMAP_COOL = 8,
// COLORMAP_HSV = 9,
// COLORMAP_PINK = 10,
// COLORMAP_HOT = 11
// }
applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_JET);
cv::imwrite("depthNormalize_1.jpg", falseColorsMap);
测试了一下,效果不错,颜色越深,代表近,颜色越浅代表远,这就有点深度学习特征图热力图的感觉了
测试一下:
float r[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.00588235294117645f, 0.02156862745098032f, 0.03725490196078418f, 0.05294117647058827f, 0.06862745098039214f, 0.084313725490196f, 0.1000000000000001f, 0.115686274509804f, 0.1313725490196078f, 0.1470588235294117f, 0.1627450980392156f, 0.1784313725490196f, 0.1941176470588235f, 0.2098039215686274f, 0.2254901960784315f, 0.2411764705882353f, 0.2568627450980392f, 0.2725490196078431f, 0.2882352941176469f, 0.303921568627451f, 0.3196078431372549f, 0.3352941176470587f, 0.3509803921568628f, 0.3666666666666667f, 0.3823529411764706f, 0.3980392156862744f, 0.4137254901960783f, 0.4294117647058824f, 0.4450980392156862f, 0.4607843137254901f, 0.4764705882352942f, 0.4921568627450981f, 0.5078431372549019f, 0.5235294117647058f, 0.5392156862745097f, 0.5549019607843135f, 0.5705882352941174f, 0.5862745098039217f, 0.6019607843137256f, 0.6176470588235294f, 0.6333333333333333f, 0.6490196078431372f, 0.664705882352941f, 0.6803921568627449f, 0.6960784313725492f, 0.7117647058823531f, 0.7274509803921569f, 0.7431372549019608f, 0.7588235294117647f, 0.7745098039215685f, 0.7901960784313724f, 0.8058823529411763f, 0.8215686274509801f, 0.8372549019607844f, 0.8529411764705883f, 0.8686274509803922f, 0.884313725490196f, 0.8999999999999999f, 0.9156862745098038f, 0.9313725490196076f, 0.947058823529412f, 0.9627450980392158f, 0.9784313725490197f, 0.9941176470588236f, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9862745098039216f, 0.9705882352941178f, 0.9549019607843139f, 0.93921568627451f, 0.9235294117647062f, 0.9078431372549018f, 0.892156862745098f, 0.8764705882352941f, 0.8607843137254902f, 0.8450980392156864f, 0.8294117647058825f, 0.8137254901960786f, 0.7980392156862743f, 0.7823529411764705f, 0.7666666666666666f, 0.7509803921568627f, 0.7352941176470589f, 0.719607843137255f, 0.7039215686274511f, 0.6882352941176473f, 0.6725490196078434f, 0.6568627450980391f, 0.6411764705882352f, 0.6254901960784314f, 0.6098039215686275f, 0.5941176470588236f, 0.5784313725490198f, 0.5627450980392159f, 0.5470588235294116f, 0.5313725490196077f, 0.5156862745098039f, 0.5f };
float g[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.001960784313725483f, 0.01764705882352935f, 0.03333333333333333f, 0.0490196078431373f, 0.06470588235294117f, 0.08039215686274503f, 0.09607843137254901f, 0.111764705882353f, 0.1274509803921569f, 0.1431372549019607f, 0.1588235294117647f, 0.1745098039215687f, 0.1901960784313725f, 0.2058823529411764f, 0.2215686274509804f, 0.2372549019607844f, 0.2529411764705882f, 0.2686274509803921f, 0.2843137254901961f, 0.3f, 0.3156862745098039f, 0.3313725490196078f, 0.3470588235294118f, 0.3627450980392157f, 0.3784313725490196f, 0.3941176470588235f, 0.4098039215686274f, 0.4254901960784314f, 0.4411764705882353f, 0.4568627450980391f, 0.4725490196078431f, 0.4882352941176471f, 0.503921568627451f, 0.5196078431372548f, 0.5352941176470587f, 0.5509803921568628f, 0.5666666666666667f, 0.5823529411764705f, 0.5980392156862746f, 0.6137254901960785f, 0.6294117647058823f, 0.6450980392156862f, 0.6607843137254901f, 0.6764705882352942f, 0.692156862745098f, 0.7078431372549019f, 0.723529411764706f, 0.7392156862745098f, 0.7549019607843137f, 0.7705882352941176f, 0.7862745098039214f, 0.8019607843137255f, 0.8176470588235294f, 0.8333333333333333f, 0.8490196078431373f, 0.8647058823529412f, 0.8803921568627451f, 0.8960784313725489f, 0.9117647058823528f, 0.9274509803921569f, 0.9431372549019608f, 0.9588235294117646f, 0.9745098039215687f, 0.9901960784313726f, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9901960784313726f, 0.9745098039215687f, 0.9588235294117649f, 0.943137254901961f, 0.9274509803921571f, 0.9117647058823528f, 0.8960784313725489f, 0.8803921568627451f, 0.8647058823529412f, 0.8490196078431373f, 0.8333333333333335f, 0.8176470588235296f, 0.8019607843137253f, 0.7862745098039214f, 0.7705882352941176f, 0.7549019607843137f, 0.7392156862745098f, 0.723529411764706f, 0.7078431372549021f, 0.6921568627450982f, 0.6764705882352944f, 0.6607843137254901f, 0.6450980392156862f, 0.6294117647058823f, 0.6137254901960785f, 0.5980392156862746f, 0.5823529411764707f, 0.5666666666666669f, 0.5509803921568626f, 0.5352941176470587f, 0.5196078431372548f, 0.503921568627451f, 0.4882352941176471f, 0.4725490196078432f, 0.4568627450980394f, 0.4411764705882355f, 0.4254901960784316f, 0.4098039215686273f, 0.3941176470588235f, 0.3784313725490196f, 0.3627450980392157f, 0.3470588235294119f, 0.331372549019608f, 0.3156862745098041f, 0.2999999999999998f, 0.284313725490196f, 0.2686274509803921f, 0.2529411764705882f, 0.2372549019607844f, 0.2215686274509805f, 0.2058823529411766f, 0.1901960784313728f, 0.1745098039215689f, 0.1588235294117646f, 0.1431372549019607f, 0.1274509803921569f, 0.111764705882353f, 0.09607843137254912f, 0.08039215686274526f, 0.06470588235294139f, 0.04901960784313708f, 0.03333333333333321f, 0.01764705882352935f, 0.001960784313725483f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
float b[] = { 0.5f, 0.5156862745098039f, 0.5313725490196078f, 0.5470588235294118f, 0.5627450980392157f, 0.5784313725490196f, 0.5941176470588235f, 0.6098039215686275f, 0.6254901960784314f, 0.6411764705882352f, 0.6568627450980392f, 0.6725490196078432f, 0.6882352941176471f, 0.7039215686274509f, 0.7196078431372549f, 0.7352941176470589f, 0.7509803921568627f, 0.7666666666666666f, 0.7823529411764706f, 0.7980392156862746f, 0.8137254901960784f, 0.8294117647058823f, 0.8450980392156863f, 0.8607843137254902f, 0.8764705882352941f, 0.892156862745098f, 0.907843137254902f, 0.9235294117647059f, 0.9392156862745098f, 0.9549019607843137f, 0.9705882352941176f, 0.9862745098039216f, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9941176470588236f, 0.9784313725490197f, 0.9627450980392158f, 0.9470588235294117f, 0.9313725490196079f, 0.915686274509804f, 0.8999999999999999f, 0.884313725490196f, 0.8686274509803922f, 0.8529411764705883f, 0.8372549019607844f, 0.8215686274509804f, 0.8058823529411765f, 0.7901960784313726f, 0.7745098039215685f, 0.7588235294117647f, 0.7431372549019608f, 0.7274509803921569f, 0.7117647058823531f, 0.696078431372549f, 0.6803921568627451f, 0.6647058823529413f, 0.6490196078431372f, 0.6333333333333333f, 0.6176470588235294f, 0.6019607843137256f, 0.5862745098039217f, 0.5705882352941176f, 0.5549019607843138f, 0.5392156862745099f, 0.5235294117647058f, 0.5078431372549019f, 0.4921568627450981f, 0.4764705882352942f, 0.4607843137254903f, 0.4450980392156865f, 0.4294117647058826f, 0.4137254901960783f, 0.3980392156862744f, 0.3823529411764706f, 0.3666666666666667f, 0.3509803921568628f, 0.335294117647059f, 0.3196078431372551f, 0.3039215686274508f, 0.2882352941176469f, 0.2725490196078431f, 0.2568627450980392f, 0.2411764705882353f, 0.2254901960784315f, 0.2098039215686276f, 0.1941176470588237f, 0.1784313725490199f, 0.1627450980392156f, 0.1470588235294117f, 0.1313725490196078f, 0.115686274509804f, 0.1000000000000001f, 0.08431372549019622f, 0.06862745098039236f, 0.05294117647058805f, 0.03725490196078418f, 0.02156862745098032f, 0.00588235294117645f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Mat rr(256, 1, CV_32FC1, r); // red
Mat gg(256, 1, CV_32FC1, g); // green
Mat bb(256, 1, CV_32FC1, b); // blue
for (int i = 0; i < pts.rows; i++)
{
pts.at(i, 0)[2] = rr.at(i, 0);
pts.at(i, 0)[1] = gg.at(i, 0);
pts.at(i, 0)[0] = bb.at(i, 0);
}
double minVal,maxVal;
Mat test = cv::imread("OtherSampleFrame_IMG_DepthMap.tif", -1);
minMaxLoc(test, &minVal, &maxVal);
Mat image3(test.rows, test.cols, CV_8UC3, Scalar(0, 0, 0));
for (int m = 0; m < image3.rows; m++)
{
for (int n = 0; n < image3.cols; n++)
{
float depth = test.ptr(m)[n];
if (depth == 0)
continue;
// 颜色越深(红),代表近,颜色越浅(蓝色)代表远,黑色代表无深度
double depthNormalize = MAX(MIN((depth-minVal)/(maxVal-minVal),1.0),0.0);
image3.at(m, n)[0] = 255 * pts.at(255*(1-depthNormalize), 0)[0];
image3.at(m, n)[1] = 255 * pts.at(255*(1-depthNormalize), 0)[1];
image3.at(m, n)[2] = 255 * pts.at(255*(1-depthNormalize), 0)[2];
}
}
cv::imwrite("depthNormalize.jpg", image3);
Mat imgimg(256, 100, CV_32FC3, cv::Scalar(0,0,0));
for (int i = 0; i < imgimg.rows; i++)
{
rectangle(imgimg, cv::Point(0,i), cv::Point(imgimg.cols-1,i+1), cv::Scalar(255*pts.at(255-i, 0)[0], 255*pts.at(255-i, 0)[1], 255*pts.at(255-i, 0)[2]),1);
}
cv::imwrite("depthNormalize_3.jpg", imgimg);
Mat imgimgimg(test.rows, 100, CV_32FC3, cv::Scalar(0,0,0));
double mmin = 0;
double mmax = test.rows;
for (int i = 0; i < imgimgimg.rows; i++)
{
double dddd = 255 * MAX(MIN((i-mmin)/(mmax-mmin),1.0),0.0);
rectangle(imgimgimg, cv::Point(0,i), cv::Point(imgimgimg.cols-1,i+1), cv::Scalar(255*pts.at(255-dddd, 0)[0], 255*pts.at(255-dddd, 0)[1], 255*pts.at(255-dddd, 0)[2]),1);
}
cv::imwrite("depthNormalize_4.jpg", imgimgimg);
Mat imgimgimg(test.rows, 200, CV_32FC3, cv::Scalar(255,255,255));
double mmin = 50;
double mmax = imgimgimg.rows-50;
for (int i = 50; i < imgimgimg.rows-50; i++)
{
//0-255 256->2001mm(0-2000mm)
double dddd = 255 * MAX(MIN((i-mmin)/(mmax-mmin),1.0),0.0);
rectangle(imgimgimg, cv::Point(0,i), cv::Point(100-1,i+1), cv::Scalar(255*pts.at(dddd, 0)[0], 255*pts.at(dddd, 0)[1], 255*pts.at(dddd, 0)[2]),1);
if (i==50)
{
line(imgimgimg, Point(100, i), Point(119, i), Scalar(0, 0, 0), 1);
std::string text = to_string(2000);
int font_face = cv::FONT_HERSHEY_COMPLEX;
double font_scale = 0.8;
int thickness = 1.5;
cv::putText(imgimgimg, text, Point(120, i+10), font_face, font_scale, cv::Scalar(0, 0, 0), thickness, 8, 0);
} else if (i==imgimgimg.rows-50-1) {
line(imgimgimg, Point(100, i), Point(119, i), Scalar(0, 0, 0), 1);
std::string text = to_string(0);
int font_face = cv::FONT_HERSHEY_COMPLEX;
double font_scale = 0.8;
int thickness = 1.5;
cv::putText(imgimgimg, text, Point(120, i + 10), font_face, font_scale, cv::Scalar(0, 0, 0), thickness, 8,
0);
} else if (i > 50+30 and i < imgimgimg.rows-50-30-1) {
if (i % ( (imgimgimg.rows-50-50-30-2) /30) == 0) {
line(imgimgimg, Point(100, i), Point(119, i), Scalar(0, 0, 0), 1);
std::string text = to_string(int((255-dddd)/255 * 2000) );
int font_face = cv::FONT_HERSHEY_COMPLEX;
double font_scale = 0.8;
int thickness = 1.5;
cv::putText(imgimgimg, text, Point(120, i+10), font_face, font_scale, cv::Scalar(0, 0, 0), thickness, 8, 0);
}
}
}
cv::imwrite("depthNormalize_4.jpg", imgimgimg);
效果对了
最后附上原图(没有附上序列,只上一个就行)