我是Point Cloud Library(PCL)和C ++编程的新手。我加载了多个.ply
文件作为参数(比如test0.ply
,test1.ply
... test99.ply
),并将它们一个接一个地可视化,就好像它们是视频帧一样。 / p>
以下是我迄今为止尝试过的内容。如何在每帧(模型缩小)中远离模型? setCameraPosition
函数看起来很相关,但说明令人困惑。
更新:我们需要找到相机current_position
并使用它。就像放大/缩小一样。
#include <iostream>
//#include <unistd.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/pcl_visualizer.h>
// This function displays the help
void showHelp(char *program_name)
{
std::cout << std::endl;
std::cout << "Usage: " << program_name << " cloud_filename.[pcd|ply]" << std::endl;
std::cout << "-h: Show this help." << std::endl;
}
// Main function
int main(int argc, char **argv)
{
// Show help
if (pcl::console::find_switch(argc, argv, "-h") || pcl::console::find_switch(argc, argv, "--help"))
{
showHelp(argv[0]);
return 0;
}
// Fetch point cloud filename in arguments | Works with PLY files
std::vector<int> filenames;
filenames = pcl::console::parse_file_extension_argument(argc, argv, ".ply");
// Visualization
printf("\n Point cloud colors :\n"
" \t white \t = \t original point cloud \n");
pcl::visualization::PCLVisualizer viewer(" Point Cloud Visualizer");
viewer.setBackgroundColor(0.05, 0.05, 0.05, 0); // Set background to a dark grey
// Load file | Works with PLY files
pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_cloud(new pcl::PointCloud<pcl::PointXYZRGB>());
int i = 0;
while (1)
{
// int v1(0);
// viewer.createViewPort(0.0, 0.0, 0.5, 1.0, v1);
i++;
cout << argv[filenames[i % 10]] << endl;
if (pcl::io::loadPLYFile(argv[filenames[i % 10]], *source_cloud) < 0)
{
std::cout << "Error loading point cloud " << argv[filenames[(i % 10) + 1]] << std::endl << std::endl;
showHelp(argv[(i % 10) + 1]);
return -1;
}
// Define R,G,B colors for the point cloud
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(source_cloud);
// We add the point cloud to the viewer and pass the color handler
viewer.addPointCloud(source_cloud, rgb, "original_cloud" + i);
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "original_cloud" + i);
viewer.spinOnce();
viewer.removePointCloud("original_cloud" + i);
}
return 0;
} // End main()
答案 0 :(得分:0)
我认为你走在正确的轨道上,setCameraPosition()应该是你想要的。下面是一些示例代码,用于将摄像机聚焦在特定点上,并将摄像机放置在y维度上5米处。
pcl::PointXYZI center = centerPoint(cloud);
viewer->setCameraPosition(center.x, center.y - 5, center.z, 0, 0, 1);
std::vector<pcl::visualization::Camera> cams;
viewer->getCameras(cams);
for (auto&& camera : cams)
{
camera.focal[0] = center.x;
camera.focal[1] = center.y;
camera.focal[2] = center.z;
}
viewer->setCameraParameters(cams[0]);