Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in calculating camera FOV #1611

Merged
merged 1 commit into from
Aug 21, 2016
Merged

Fix bug in calculating camera FOV #1611

merged 1 commit into from
Aug 21, 2016

Conversation

samarth-robo
Copy link
Contributor

#1610 fix

See http://www.vtk.org/doc/nightly/html/classvtkCamera.html#a2aec83f16c1c492fe87336a5018ad531 for the correct formula.
This calculation also affects the PCLVisualizer window size.

Piece of code to test:

#include <iostream>

#include <boost/thread/thread.hpp>
#include <pcl/common/common_headers.h>
#include <pcl/visualization/pcl_visualizer.h>

using namespace std;
using namespace pcl;
using namespace Eigen;

int main(int argc, char **argv) {
  // intrinsics matrix
  Matrix3f intrinsics;
  intrinsics(0, 0) = 525.00;  // fx
  intrinsics(0, 1) = 000.00;
  intrinsics(0, 2) = 320.00;  // cx
  intrinsics(1, 0) = 000.00;
  intrinsics(1, 1) = 525.00;  // fy
  intrinsics(1, 2) = 240.00;  // cy
  intrinsics(2, 0) = 000.00;  //  
  intrinsics(2, 1) = 000.00;  //
  intrinsics(2, 2) = 001.00;  // 1
  cout << "Intrinsics " << endl << intrinsics << endl;

  // extrinsics matrix
  Matrix4f extrinsics = Matrix4f::Identity();
  cout << "Extrinsics " << endl << extrinsics << endl;

  visualization::PCLVisualizer viewer("viewer");
  viewer.setCameraParameters(intrinsics, extrinsics);

  // calculate true camera FOV
  double true_h = 2 * intrinsics(1, 2); 
  double true_fovy = 2 * atan(true_h / (2. * intrinsics(1, 1)));
  cout << "true fovy = " << true_fovy << endl;

  vector<visualization::Camera> cams;
  viewer.getCameras(cams);
  for(int i = 0; i < cams.size(); i++) {
    cout << "Cam " << i << " fovy = " << cams[i].fovy << endl;
    assert(cams[i].fovy == true_fovy);
  }

  while(!viewer.wasStopped()) {
    viewer.spinOnce(100);
    boost::this_thread::sleep(boost::posix_time::microseconds(500000));
  }

  return 0;
}

See http://www.vtk.org/doc/nightly/html/classvtkCamera.html#a2aec83f16c1c492fe87336a5018ad531 for the correct formula.
This calculation also affects the PCLVisualizer window size.
@SergioRAgostinho
Copy link
Member

Thanks @samarth-robo 👍 . I will test this now and provide feedback

@SergioRAgostinho
Copy link
Member

Agreed with the changes and harmless to include for 1.8.0.

@SergioRAgostinho SergioRAgostinho added this to the pcl-1.8.1 milestone Aug 18, 2016
@jspricke jspricke merged commit 8609873 into PointCloudLibrary:master Aug 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants