Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get camera's parameters at PCL?

I installed PCL1.7.2. and I am trying use PCL libraries.

I want to show camera's parameters by "const", so, I want to get camera's parameters. But I don't understand how to get the camera's parameters.

I saw the "pcl::visualization::Camera Class Reference". http://docs.pointclouds.org/trunk/classpcl_1_1visualization_1_1_camera.html

and I understood there are focal, pos, view etc on the "Camera" object.

and now I have confirmed that the following code run.

but I can't understand how to get Camera's member. this is how to set Camera's member values. viewer.setCameraPosition(pos_x, pos_y, pos_z, view_x, view_y, view_z, up_x, up_y, up_z, viewport);

so, someone please show me how to get Camera's parameters at the following code.

this is now roading source.

#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;
}
like image 467
kuu Avatar asked Nov 18 '14 18:11

kuu


Video Answer


1 Answers

This should work:

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;
like image 71
Daniel Avatar answered Oct 28 '22 03:10

Daniel