pcl1.72 visualization::CloudViewer 显示不出图像怎么办

棋棋酱- 2018-10-15 11:08:26
运行完以下程序点云出不来,不管输入什么,输出的都是这个


#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;
using namespace pcl;

int user_data;
//相机内参,根据输入改动
const double u0 = 1329.49 / 4;//由于后面resize成原图的1/4所以有些参数要缩小相同倍数
const double v0 = 954.485 / 4;
const double fx = 6872.874 / 4;
const double fy = 6872.874 / 4;
const double Tx = 174.724;
const double doffs = 293.97 / 4;

void viewerOneOff(visualization::PCLVisualizer& viewer)
{
//viewer.setBackgroundColor(0.0, 0.0, 0.0);
viewer.setBackgroundColor(1, 1, 1);
}

int main()
{
PointCloud<PointXYZRGB> cloud_a;
PointCloud<PointXYZRGB>::Ptr cloud(new PointCloud<PointXYZRGB>);



Mat color1 = imread("im0.png");
Mat depth = imread("Sword1_perfect_d.png");
////Resize
//color1.resize();
Mat color;
resize(color1, color, Size(color1.cols/4,color1.rows/4), 0, 0, CV_INTER_LINEAR);
//imshow("h",color);
//waitKey(0);

int rowNumber = color.rows;
int colNumber = color.cols;

cloud_a.height = rowNumber;
cloud_a.width = colNumber;
cloud_a.points.resize(cloud_a.width * cloud_a.height);

for (unsigned int u = 0; u < rowNumber; ++u)
{
for (unsigned int v = 0; v < colNumber; ++v)
{
/*unsigned int num = rowNumber*colNumber-(u*colNumber + v)-1;*/
unsigned int num = u*colNumber + v;
double Xw = 0, Yw = 0, Zw = 0;


Zw = fx*Tx / (((double)depth.at<Vec3b>(u, v)[0]) + doffs);
Xw = (v+1 - u0) * Zw / fx;
Yw = (u+1 - v0) * Zw / fy;

cloud_a.points[num].b = color.at<Vec3b>(u, v)[0];
cloud_a.points[num].g = color.at<Vec3b>(u, v)[1];
cloud_a.points[num].r = color.at<Vec3b>(u, v)[2];

cloud_a.points[num].x = Xw;
cloud_a.points[num].y = Yw;
cloud_a.points[num].z = Zw;
}
}

*cloud = cloud_a;

visualization::CloudViewer viewer("Cloud Viewer");

viewer.showCloud(cloud);

viewer.runOnVisualizationThreadOnce(viewerOneOff);

while (!viewer.wasStopped())
{
user_data = 9;
}

return 0;
system("pause");
}
...全文
1935 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2020-11-09
  • 打赏
  • 举报
回复
        pcl_viewer 窗口操作
        加载显示点云以后我们可以,在 pcl_viewr 窗口中我们可以使用以下按键来调整视角、放大和缩小:
            r键:重现视角。如果读入文件没有在主窗口显示,不妨按下键盘的r键一试。
            j键:截图功能。
            g键:显示/隐藏 坐标轴。
            -/+:-(减号)可缩小点; +(加号)可放大点。
            q键:退出
            鼠标:左键,使图像绕自身旋转; 滚轮, 按住滚轮不松,可移动图像,滚动滚轮,可放大/缩小 图像; 右键,“原地” 放大/缩小。
            p, P          : switch to a point-based representation                        (以点为基准展示)
            w, W          : switch to a wireframe-based representation (where available)  (以线框为基准展示)
            s, S          : switch to a surface-based representation (where available)    (以平面为基准展示)
            j, J          : take a .PNG snapshot of the current window view               (将当前窗口截图为png格式,保存在bin目录下的Debug或者Release目录下)
            c, C          : display current camera/window parameters                      (显示当前相机参数)
            +/ -          : increment/decrement overall point size                        (放大或缩小当前所有点的尺寸)
            g, G          : display scale grid (on/off)                                   (开启标尺)
            u, U          : display lookup table (on/off)                                 (开启colorbar)
            r, R [+ ALT]  : reset camera [to viewpoint = {0, 0, 0} -> center_{x, y, z}]   (将相机平移到某个位置)
            ALT + s, S    : turn stereo mode on/off                                       (打开立体模式)
            ALT + f, F    : switch between maximized window mode and original size        (改变当前窗口的尺寸)
xuqianmkl 2020-11-09
  • 打赏
  • 举报
回复 3
点R键就可以显示图像
吹起小石头 2020-03-14
  • 打赏
  • 举报
回复 1
我也有这个问题,请问楼主找到解决办法了吗
ASHush 2019-06-14
  • 打赏
  • 举报
回复 1
按键盘R键就可以了。
帝人C 2019-02-19
  • 打赏
  • 举报
回复
动一下鼠标滚轮~

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧