9 #ifndef __PBIO_API__PBIO__CAMERACALIBRATOR_H_
10 #define __PBIO_API__PBIO__CAMERACALIBRATOR_H_
16 #include "ComplexObject.h"
18 #include "ExceptionCheck.h"
23 #include "stl_wraps_impls/WrapIStreamImpl.h"
24 #include "stl_wraps_impls/WrapOStreamImpl.h"
48 typedef LightSmartPtr<CameraCalibrator>::tPtr
Ptr;
161 const CalibrationSettings settings);
206 bool *pattern_accepted,
207 std::vector<Point> *pattern_points);
243 std::vector<Point>
getTip();
280 const int max_used_patterns_count,
281 float *reprojection_error);
323 const float alpha)
const;
347 std::ostream &binary_stream)
const;
368 pbio::stl_wraps::WrapOStream &binary_stream)
const;
391 std::istream &binary_stream);
413 pbio::stl_wraps::WrapIStream &binary_stream);
419 const DHPtr &dll_handle,
441 CameraCalibrator::CameraCalibrator(
442 const DHPtr &dll_handle,
444 ComplexObject(dll_handle, impl)
458 void* exception = NULL;
460 _dll_handle->CameraCalibrator_initCalibration(
476 checkException(exception, *_dll_handle);
487 bool *pattern_accepted,
488 std::vector<Point> *pattern_points)
491 int32_t pattern_found_i = 0;
492 int32_t pattern_accepted_i = 0;
494 std::vector<float> pattern_points_f;
496 if(_pattern_height > 0 && _pattern_width > 0)
497 pattern_points_f.resize(_pattern_height * _pattern_width * 2);
499 void* exception = NULL;
501 const RawImage::CapiData cdata = image.makeCapiData();
503 _dll_handle->CameraCalibrator_addImage_with_crop(
512 cdata.crop_info_offset_x,
513 cdata.crop_info_offset_y,
514 cdata.crop_info_data_image_width,
515 cdata.crop_info_data_image_height,
519 pattern_points_f.empty() ?
521 &pattern_points_f[0],
524 checkException(exception, *_dll_handle);
528 *pattern_found = pattern_found_i;
531 *pattern_accepted = pattern_accepted_i;
535 pattern_points->resize(_pattern_width * _pattern_height);
536 for(
size_t i = 0; i < pattern_points->size(); ++i)
538 pattern_points->at(i).x = pattern_points_f[i * 2 + 0];
539 pattern_points->at(i).y = pattern_points_f[i * 2 + 1];
548 void* exception = NULL;
550 const float progress = _dll_handle->CameraCalibrator_getPatternSpaceCoverProgress(
554 checkException(exception, *_dll_handle);
563 std::vector<float> pattern_points_f;
565 if(_pattern_height > 0 && _pattern_width > 0)
566 pattern_points_f.resize(_pattern_height * _pattern_width * 2);
568 void* exception = NULL;
570 const int32_t tip_ready = _dll_handle->CameraCalibrator_getTip(
572 pattern_points_f.empty() ?
574 &pattern_points_f[0],
577 checkException(exception, *_dll_handle);
579 std::vector<Point> pattern_points;
583 pattern_points.resize(_pattern_width * _pattern_height);
585 for(
size_t i = 0; i < pattern_points.size(); ++i)
587 pattern_points[i].x = pattern_points_f[i * 2 + 0];
588 pattern_points[i].y = pattern_points_f[i * 2 + 1];
592 return pattern_points;
599 const int max_used_patterns_count,
600 float *reprojection_error_ptr)
602 void* exception = NULL;
604 const float reprojection_error = _dll_handle->CameraCalibrator_calibrate(
606 max_used_patterns_count,
609 checkException(exception, *_dll_handle);
611 if(reprojection_error < 0 - 0.1f)
614 if(reprojection_error_ptr)
615 *reprojection_error_ptr = reprojection_error;
624 const float alpha)
const
626 pbio::image::Image::Ptr result(
627 new pbio::image::Image(
632 void* exception = NULL;
634 const RawImage::CapiData cdata = image.makeCapiData();
636 _dll_handle->CameraCalibrator_undistort_with_crop(
645 cdata.crop_info_offset_x,
646 cdata.crop_info_offset_y,
647 cdata.crop_info_data_image_width,
648 cdata.crop_info_data_image_height,
654 checkException(exception, *_dll_handle);
663 std::ostream &binary_stream)
const
665 pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(binary_stream);
672 pbio::stl_wraps::WrapOStream &binary_stream)
const
674 void* exception = NULL;
676 _dll_handle->CameraCalibrator_saveCameraParameters(
679 pbio::stl_wraps::WrapOStream::write_func,
682 checkException(exception, *_dll_handle);
688 std::istream &binary_stream)
690 pbio::stl_wraps::WrapIStreamImpl binary_stream_wrap(binary_stream);
697 pbio::stl_wraps::WrapIStream &binary_stream)
699 void* exception = NULL;
701 _dll_handle->CameraCalibrator_loadCameraParameters(
704 pbio::stl_wraps::WrapIStream::read_func,
707 checkException(exception, *_dll_handle);
713 #endif // __PBIO_API__PBIO__CAMERACALIBRATOR_H_
HeavySmartPtr< IRawImage >::tPtr Ptr
Alias for the type of a smart pointer to IRawImage.
Definition: IRawImage.h:39
int image_height
Height of images for calibration.
Definition: CameraCalibrator.h:82
Struct that provides raw image data and optional cropping information.
Definition: RawImage.h:28
Interface object for creating other interface objects.
Definition: FacerecService.h:64
PatternType pattern_type
Pattern type.
Definition: CameraCalibrator.h:89
LightSmartPtr< CameraCalibrator >::tPtr Ptr
Alias for the type of a smart pointer to CameraCalibrator.
Definition: CameraCalibrator.h:48
std::vector< Point > getTip()
Get a tip where to put a pattern in the image to get a better pattern space coverage.
Definition: CameraCalibrator.h:561
int width
Image width.
Definition: RawImage.h:109
Сalibration process settings.
Definition: CameraCalibrator.h:56
Format format
Format of image data.
Definition: RawImage.h:125
Error - the class of exceptions thrown when errors occur.
Definition: CameraCalibrator.h:66
bool fix_aspect_ratio
Fix the aspect ratio.
Definition: CameraCalibrator.h:110
int pattern_width
Pattern width.
Definition: CameraCalibrator.h:96
bool calib_fix_principal_point
Fix the principal point at the center.
Definition: CameraCalibrator.h:124
void addImage(const RawImage image, bool *pattern_found, bool *pattern_accepted, std::vector< Point > *pattern_points)
Search a pattern in the image and store it.
Definition: CameraCalibrator.h:484
IRawImage::Ptr undistort(const RawImage image, const float alpha) const
Correct the image distortion using the calibrated or loaded camera parameters.
Definition: CameraCalibrator.h:622
Definition: CameraCalibrator.h:67
bool calib_zero_tangent_dist
Consider a tangential distortion as zero.
Definition: CameraCalibrator.h:117
int height
Image height.
Definition: RawImage.h:117
int pattern_height
Pattern height.
Definition: CameraCalibrator.h:103
Definition: CameraCalibrator.h:65
void loadCameraParameters(std::istream &binary_stream)
Load the calibrated camera parameters from binary_stream. The format is platform-independent.
Definition: CameraCalibrator.h:687
Interface object for camera calibration and correction of image distortion.
Definition: CameraCalibrator.h:39
int image_width
Width of images for calibration.
Definition: CameraCalibrator.h:75
float getPatternSpaceCoverProgress() const
Evaluate covering of the pattern space to get more accurate calibration.
Definition: CameraCalibrator.h:546
Definition: FacerecService.mm:79
bool rational_distortion_model
Use the rational distortion model.
Definition: CameraCalibrator.h:131
PatternType
Types of calibration patterns.
Definition: CameraCalibrator.h:63
void initCalibration(const CalibrationSettings settings)
Initialize the calibration process. All previous accepted patterns will be removed.
Definition: CameraCalibrator.h:452
bool calibrate(const int max_used_patterns_count, float *reprojection_error)
Calibrate the camera.
Definition: CameraCalibrator.h:598
void saveCameraParameters(std::ostream &binary_stream) const
Save the calibrated camera parameters to binary_stream. The format is platform-independent.
Definition: CameraCalibrator.h:662