如何在PCL获取相机的参数?

How to get camera's parameters at PCL?

本文关键字:参数 相机 获取 PCL      更新时间:2023-10-16

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

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

我看到了"pcl::visualization::Camera Class Reference"。http://docs.pointclouds.org/trunk/classpcl_1_1visualization_1_1_camera.html

我知道"相机"对象上有焦点、pos、视图等。

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

但我不明白如何获得相机的成员。这是设置相机的成员值的方法。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;