您的位置:首页 > 其它

全景影像转点云——只有鱼才能看见的真实

2017-08-22 15:12 204 查看
子非鱼,安知鱼之乐。呵呵呵呵呵呵.....
最近做车载影像贴图,看到PTGui有个很炫的全景影像浏览功能,客户仿佛置身其中一样。
于是想做一个一样的出来。

当然啦,就是普通的全景影像。
不过每天用这样的眼睛看世界,没过多久就崩溃了吧。
所以说做鱼也不容易啊。
吾非鱼,安知鱼之乐,这种话也说不出来了吧。。。

好了进入主题,公式如下:
 
 上代码:
//将全景影像用球面投影尝试进行弄成三维球形
void IMG2BallCloud(std::string in_IMGFileName, std::string out_OutClouFileName, bool ifDownSample)
{
cout << "2Dimage to 3DBallCloud...";
cv::Mat PanoramaIMG = imread(in_IMGFileName);
if (PanoramaIMG.empty())
{
cout << "open IMG Fail!" << endl;
return;
}
int nr = PanoramaIMG.rows; // number of rows
int nc = PanoramaIMG.cols; // number of columns
double R = (double)nc / (2 * CV_PI);//利用“R*theta=周长”这一公式反算半径
cout << "R Active:" << R << endl;
ofstream  outFile(out_OutClouFileName);
int PtNum = nr*nc;
cout << "Origion Point Cloud Num:" << PtNum << endl;
PtNum = 0;
for (int r = 0; r < nr; r++)
{
//进行1/4采样,
if (ifDownSample)
{
if (r % 2 == 1)continue;
}
for (int c = 0; c < nc; c++)
{
if (ifDownSample)
{
if (c % 2 == 1)continue;
}

double x = (double)c;
double y = (double)r;
double theta = x / R;
double phi = y / R;
double X = R*sin(phi)*sin(theta);
double Y = R*sin(phi)*cos(theta);
double Z = R*cos(phi);
int color_b = PanoramaIMG.at<cv::Vec3b>(r, c)[0];
int color_g = PanoramaIMG.at<cv::Vec3b>(r, c)[1];
int color_r = PanoramaIMG.at<cv::Vec3b>(r, c)[2];
//if (color_b == 0)continue;//图像的黑色部分不要
if (abs(theta) <= 0.2 || abs(phi) <= 0.2)
{
color_b = 0;
color_g = 255;
color_r = 0;
}
PtNum++;
outFile << X << " " << Y << " " << Z << " " << color_r << " " << color_g << " " << color_b << endl;
}
}
cout << "done! last point cloud num:" << PtNum << endl;
outFile.close();
}
void PanoramaIMG_toBallCloud()
{
//std::string PanoramaIMGFile = std::string(".\\Data\\picture\\PanoramaIMG.jpg");//拍摄而得全景
std::string PanoramaIMGFile = std::string(".\\Output\\SphericalMapping.jpg");//黑色采样全景
std::string OutCloudFile = std::string(".\\Output\\PanoramaIMG_toBallCloud.txt");
IMG2BallCloud(PanoramaIMGFile, OutCloudFile);
}

上结果:
将视角分别移动到里面和外面,效果都很绝佳。

说两句:
观察这只水鸟很久了,不知道它为何孤身一只。
景色很美,它飞起来的时候翅膀也很大,希望没人杀掉它。
希望它多吃点,变成仙鹤。池塘里还有这么多鱼呢。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: