star-camera

Camera models
git clone git://git.meso-star.fr/star-camera.git
Log | Files | Refs | README | LICENSE

commit a7f79ff6659a713e30e6bdb078ef5c1aab419e18
parent 0d14b485a39df890972eefccc985b05e4041412b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 27 Jul 2021 08:41:35 +0200

Add the "field of view" <-> "focal length" conversions

Diffstat:
Msrc/scam.h | 12++++++++++++
Msrc/scam_perspective.c | 26++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/scam.h b/src/scam.h @@ -123,6 +123,18 @@ SCAM_API res_T scam_ref_put (struct scam* camera); +SCAM_API res_T +scam_focal_length_to_field_of_view + (const double lens_radius, + const double focal_length, + double* field_of_view); + +SCAM_API res_T +scam_field_of_view_to_focal_length + (const double lens_radius, + const double field_of_view, + double* focal_length); + END_DECLS #endif /* SCAM_H */ diff --git a/src/scam_perspective.c b/src/scam_perspective.c @@ -56,6 +56,8 @@ setup_perspective(struct scam* cam, const struct scam_perspective_args* args) log_err(cam, "perspective camera: invalid negative focal distance: %g\n", args->focal_distance); + res = RES_BAD_ARG; + goto error; } if(pinhole && (args->field_of_view <= 0 || args->field_of_view >= PI)) { @@ -230,6 +232,30 @@ error: goto exit; } +res_T +scam_focal_length_to_field_of_view + (const double lens_radius, + const double focal_length, + double* field_of_view) +{ + if(lens_radius < 0 || focal_length <= 0 || !field_of_view) + return RES_BAD_ARG; + *field_of_view = 2 * atan(lens_radius /focal_length); + return RES_OK; +} + +res_T +scam_field_of_view_to_focal_length + (const double lens_radius, + const double field_of_view, + double* focal_length) +{ + if(lens_radius < 0 || field_of_view <= 0 || field_of_view >= PI || !focal_length) + return RES_BAD_ARG; + *focal_length = lens_radius / tan(field_of_view*0.5); + return RES_OK; +} + /******************************************************************************* * Local function ******************************************************************************/