gpt4 book ai didi

c++ - 如何在PCL获取相机参数?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:19:47 25 4
gpt4 key购买 nike

我安装了 PCL1.7.2。我正在尝试使用 PCL 库。

我想通过“const”显示相机的参数,所以,我想获取相机的参数。但是我不明白如何获取相机的参数。

我看到了“pcl::visualization::Camera 类引用”。 http://docs.pointclouds.org/trunk/classpcl_1_1visualization_1_1_camera.html

我知道“相机”对象上有焦点、位置、 View 等。

现在我已确认以下代码运行。

但我不明白如何获取相机的成员。这是设置 Camera 的成员值的方法。viewer.setCameraPosition(pos_x, pos_y, pos_z, view_x, view_y, view_z, up_x, up_y, up_z, viewport);

所以,请有人告诉我如何通过以下代码获取相机的参数。

这是现在的道路资源。

#include "stdafx.h"
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
int user_data=0;

void
viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor(1.0, 0.5, 1.0);
pcl::PointXYZ o;
o.x = 1.0;
o.y = 0;
o.z = 0;
viewer.addSphere(o, 0.25, "sphere", 0);
std::cout << "i only run once" << std::endl;

}

void
viewerPsycho(pcl::visualization::PCLVisualizer& viewer)
{
static unsigned count = 0;
std::stringstream ss;
ss << "Once per viewer loop: " << count++;
viewer.removeShape("text", 0);
viewer.addText(ss.str(), 200, 300, "text", 0);

//FIXME: possible race condition here:
user_data++;

}

int _tmain(int argc, const _TCHAR** argv)
{
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::io::loadPCDFile("c:\\data\\triceratops\\raw_0.pcd", *cloud);

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

//blocks until the cloud is actually rendered
viewer.showCloud(cloud);

//use the following functions to get access to the underlying more advanced/powerful
//PCLVisualizer

//This will only get called once
viewer.runOnVisualizationThreadOnce(viewerOneOff);

//This will get called once per visualization iteration
viewer.runOnVisualizationThread(viewerPsycho);
while (!viewer.wasStopped())
{
//you can also do cool processing here
//FIXME: Note that this is running in a separate thread from viewerPsycho
//and you should guard against race conditions yourself...
user_data++;
}
return 0;
}

最佳答案

这应该有效:

boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;          
std::vector<pcl::visualization::Camera> cam;

//Save the position of the camera
viewer->getCameras(cam);

//Print recorded points on the screen:
cout << "Cam: " << endl
<< " - pos: (" << cam[0].pos[0] << ", " << cam[0].pos[1] << ", " << cam[0].pos[2] << ")" << endl
<< " - view: (" << cam[0].view[0] << ", " << cam[0].view[1] << ", " << cam[0].view[2] << ")" << endl
<< " - focal: (" << cam[0].focal[0] << ", " << cam[0].focal[1] << ", " << cam[0].focal[2] << ")" << endl;

关于c++ - 如何在PCL获取相机参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27001103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com