opencv图像深度显示

通过SFM重建后的三维点,想把它的深度图显示出来

原来是

double minVal,maxVal;
minMaxLoc(depths, &minVal, &maxVal);
Mat tmp(768,1024,CV_8UC3,Scalar(0,0,0)); 
for (unsigned int i=0; i<pointcloud.size(); i++)
{
    double _d = MAX(MIN((pointcloud[i].pt.z-minVal)/(maxVal-minVal),1.0),0.0);
    circle(tmp, correspImg1Pt[i].pt, 1, Scalar(255*(1-_d), (255), (255)), CV_FILLED);
}
cvtColor(tmp, tmp, CV_HSV2BGR);

我发现有点问题,按照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<Vec3b>(kf, j)[0] = 255 * (kf / 500.00);
				image1.at<Vec3b>(kf, j)[1] = 255;
				image1.at<Vec3b>(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<Vec3f>(i, 0)[0] = rr.at<float>(i, 0);
		pts.at<Vec3f>(i, 0)[1] = gg.at<float>(i, 0);
		pts.at<Vec3f>(i, 0)[2] = bb.at<float>(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<Vec3b>(kf, j)[0] = 255 * pts.at<Vec3f>(kf, 0)[0];
			image3.at<Vec3b>(kf, j)[1] = 255 * pts.at<Vec3f>(kf, 0)[1];
			image3.at<Vec3b>(kf, j)[2] = 255 * pts.at<Vec3f>(kf, 0)[2];
		}

	}
	imshow("Depth Map5", image3);
	waitKey();

测试了一下,效果不错,颜色越深,代表近,颜色越浅代表远,这就有点深度学习特征图热力图的感觉了

测试一下:

效果对了

最后附上原图(没有附上序列,只上一个就行)

猜你喜欢

转载自blog.csdn.net/baidu_40840693/article/details/83650159