diff --git a/WebARKit/WebARKitCamera.cpp b/WebARKit/WebARKitCamera.cpp index e4893d4..98b4006 100644 --- a/WebARKit/WebARKitCamera.cpp +++ b/WebARKit/WebARKitCamera.cpp @@ -13,10 +13,8 @@ bool WebARKitCamera::setupCamera(int width, int height) { } xsize = width; ysize = height; - // simple routine to calculate focal length from diagonal field of view, and convert to camera matrix. - diagonal_image_size = std::pow(std::pow(xsize, 2.0) + std::pow(ysize, 2.0), 0.5); - diagonal_fov_radians = diagonal_fov_degrees * m_pi / 180.0; - focal_length = 0.5 * diagonal_image_size / std::tan(0.5 * diagonal_fov_radians); + + setFocalLength(xsize, ysize); cmat.at(0) = focal_length; cmat.at(2) = 0.5 * xsize; @@ -42,4 +40,13 @@ std::array WebARKitCamera::getCameraData() const { std::array WebARKitCamera::getDistortionCoefficients() const { return kc; } + +void WebARKitCamera::setFocalLength(int width, int height) { + double diagonal_image_size; + double diagonal_fov_radians; + // simple routine to calculate focal length from diagonal field of view, and convert to camera matrix. + diagonal_image_size = std::pow(std::pow(width, 2.0) + std::pow(height, 2.0), 0.5); + diagonal_fov_radians = diagonal_fov_degrees * m_pi / 180.0; + focal_length = 0.5 * diagonal_image_size / std::tan(0.5 * diagonal_fov_radians); +} } // namespace webarkit \ No newline at end of file diff --git a/WebARKit/include/WebARKitCamera.h b/WebARKit/include/WebARKitCamera.h index 98824c1..33b65f6 100644 --- a/WebARKit/include/WebARKitCamera.h +++ b/WebARKit/include/WebARKitCamera.h @@ -17,14 +17,16 @@ class WebARKitCamera { std::array getDistortionCoefficients() const; + double getFocalLength() const { return focal_length; } + private: int xsize, ysize; std::array cmat; std::array kc; double focal_length; - double diagonal_image_size; double diagonal_fov_degrees; - double diagonal_fov_radians; + + void setFocalLength(int width, int height); }; } // namespace webarkit diff --git a/tests/webarkit_test.cc b/tests/webarkit_test.cc index e829673..6f7b692 100644 --- a/tests/webarkit_test.cc +++ b/tests/webarkit_test.cc @@ -78,6 +78,7 @@ TEST(WebARKitCameraTest, TestCamera) { EXPECT_EQ(camera_mat[4], 571.25920269684582); EXPECT_EQ(camera_mat[5], 240.0); EXPECT_EQ(camera_mat[8], 1.0); + EXPECT_EQ(camera.getFocalLength(), 571.25920269684582); camera.printSettings(); }