3DiVi Face SDK  3.21.0
 Указатель Классы Пространства имен Файлы Функции Переменные Определения типов Перечисления Элементы перечислений Свойства Группы
CameraCalibrator.h
См. документацию.
1 
9 #ifndef __PBIO_API__PBIO__CAMERACALIBRATOR_H_
10 #define __PBIO_API__PBIO__CAMERACALIBRATOR_H_
11 
12 #include <sstream>
13 #include <vector>
14 
15 
16 #include "ComplexObject.h"
17 #include "Error.h"
18 #include "ExceptionCheck.h"
19 #include "Image.h"
20 #include "Point.h"
21 #include "RawImage.h"
22 #include "SmartPtr.h"
23 #include "stl_wraps_impls/WrapIStreamImpl.h"
24 #include "stl_wraps_impls/WrapOStreamImpl.h"
25 
26 
27 
28 
29 namespace pbio
30 {
31 
32 class FacerecService;
33 
39 class CameraCalibrator : public ComplexObject
40 {
41 public:
42 
48  typedef LightSmartPtr<CameraCalibrator>::tPtr Ptr;
49 
50 
57  {
64  {
68  };
69 
76 
83 
90 
97 
104 
111 
118 
125 
132 
134  {
135  fix_aspect_ratio = false;
136  calib_zero_tangent_dist = false;
139  }
140  };
141 
142 
160  void initCalibration(
161  const CalibrationSettings settings);
162 
163 
203  void addImage(
204  const RawImage image,
205  bool *pattern_found,
206  bool *pattern_accepted,
207  std::vector<Point> *pattern_points);
208 
209 
225  float getPatternSpaceCoverProgress() const;
226 
227 
243  std::vector<Point> getTip();
244 
245 
279  bool calibrate(
280  const int max_used_patterns_count,
281  float *reprojection_error);
282 
283 
322  const RawImage image,
323  const float alpha) const;
324 
325 
326 
347  std::ostream &binary_stream) const;
348 
368  pbio::stl_wraps::WrapOStream &binary_stream) const;
369 
370 
391  std::istream &binary_stream);
392 
413  pbio::stl_wraps::WrapIStream &binary_stream);
414 
415 
416 private:
417 
419  const DHPtr &dll_handle,
420  void* impl);
421 
422  int _pattern_width;
423  int _pattern_height;
424 
425  friend class FacerecService;
426  friend class object_with_ref_counter<CameraCalibrator>;
427 };
428 
429 } // pbio namespace
430 
431 
432 
436 
437 namespace pbio
438 {
439 
440 inline
441 CameraCalibrator::CameraCalibrator(
442  const DHPtr &dll_handle,
443  void* impl):
444 ComplexObject(dll_handle, impl)
445 {
446  _pattern_width = 0;
447  _pattern_height = 0;
448 }
449 
450 
451 inline
453  const CalibrationSettings settings)
454 {
455  _pattern_height = 0;
456  _pattern_width = 0;
457 
458  void* exception = NULL;
459 
460  _dll_handle->CameraCalibrator_initCalibration(
461  _impl,
462 
463  settings.image_width,
464  settings.image_height,
465  settings.pattern_type,
466  settings.pattern_width,
467  settings.pattern_height,
468 
469  settings.fix_aspect_ratio,
470  settings.calib_zero_tangent_dist,
471  settings.calib_fix_principal_point,
472  settings.rational_distortion_model,
473 
474  &exception);
475 
476  checkException(exception, *_dll_handle);
477 
478  _pattern_height = settings.pattern_height;
479  _pattern_width = settings.pattern_width;
480 }
481 
482 
483 inline
485  const RawImage image,
486  bool *pattern_found,
487  bool *pattern_accepted,
488  std::vector<Point> *pattern_points)
489 {
490 
491  int32_t pattern_found_i = 0;
492  int32_t pattern_accepted_i = 0;
493 
494  std::vector<float> pattern_points_f;
495 
496  if(_pattern_height > 0 && _pattern_width > 0)
497  pattern_points_f.resize(_pattern_height * _pattern_width * 2);
498 
499  void* exception = NULL;
500 
501  const RawImage::CapiData cdata = image.makeCapiData();
502 
503  _dll_handle->CameraCalibrator_addImage_with_crop(
504  _impl,
505 
506  cdata.data,
507  cdata.width,
508  cdata.height,
509  cdata.format,
510 
511  cdata.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,
516 
517  &pattern_found_i,
518  &pattern_accepted_i,
519  pattern_points_f.empty() ?
520  NULL :
521  &pattern_points_f[0],
522  &exception);
523 
524  checkException(exception, *_dll_handle);
525 
526 
527  if(pattern_found)
528  *pattern_found = pattern_found_i;
529 
530  if(pattern_accepted)
531  *pattern_accepted = pattern_accepted_i;
532 
533  if(pattern_points)
534  {
535  pattern_points->resize(_pattern_width * _pattern_height);
536  for(size_t i = 0; i < pattern_points->size(); ++i)
537  {
538  pattern_points->at(i).x = pattern_points_f[i * 2 + 0];
539  pattern_points->at(i).y = pattern_points_f[i * 2 + 1];
540  }
541  }
542 }
543 
544 
545 inline
547 {
548  void* exception = NULL;
549 
550  const float progress = _dll_handle->CameraCalibrator_getPatternSpaceCoverProgress(
551  _impl,
552  &exception);
553 
554  checkException(exception, *_dll_handle);
555 
556  return progress;
557 }
558 
559 
560 inline
561 std::vector<Point> CameraCalibrator::getTip()
562 {
563  std::vector<float> pattern_points_f;
564 
565  if(_pattern_height > 0 && _pattern_width > 0)
566  pattern_points_f.resize(_pattern_height * _pattern_width * 2);
567 
568  void* exception = NULL;
569 
570  const int32_t tip_ready = _dll_handle->CameraCalibrator_getTip(
571  _impl,
572  pattern_points_f.empty() ?
573  NULL :
574  &pattern_points_f[0],
575  &exception);
576 
577  checkException(exception, *_dll_handle);
578 
579  std::vector<Point> pattern_points;
580 
581  if(tip_ready)
582  {
583  pattern_points.resize(_pattern_width * _pattern_height);
584 
585  for(size_t i = 0; i < pattern_points.size(); ++i)
586  {
587  pattern_points[i].x = pattern_points_f[i * 2 + 0];
588  pattern_points[i].y = pattern_points_f[i * 2 + 1];
589  }
590  }
591 
592  return pattern_points;
593 }
594 
595 
596 
597 inline
599  const int max_used_patterns_count,
600  float *reprojection_error_ptr)
601 {
602  void* exception = NULL;
603 
604  const float reprojection_error = _dll_handle->CameraCalibrator_calibrate(
605  _impl,
606  max_used_patterns_count,
607  &exception);
608 
609  checkException(exception, *_dll_handle);
610 
611  if(reprojection_error < 0 - 0.1f)
612  return false;
613 
614  if(reprojection_error_ptr)
615  *reprojection_error_ptr = reprojection_error;
616 
617  return true;
618 }
619 
620 
621 inline
623  const RawImage image,
624  const float alpha) const
625 {
626  pbio::image::Image::Ptr result(
627  new pbio::image::Image(
628  image.height,
629  image.width,
630  image.format));
631 
632  void* exception = NULL;
633 
634  const RawImage::CapiData cdata = image.makeCapiData();
635 
636  _dll_handle->CameraCalibrator_undistort_with_crop(
637  _impl,
638 
639  cdata.data,
640  cdata.width,
641  cdata.height,
642  cdata.format,
643 
644  cdata.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,
649 
650  alpha,
651  result->data(),
652  &exception);
653 
654  checkException(exception, *_dll_handle);
655 
656  return result;
657 }
658 
659 
660 
661 inline
663  std::ostream &binary_stream) const
664 {
665  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(binary_stream);
666 
667  saveCameraParameters(binary_stream_wrap);
668 }
669 
670 inline
672  pbio::stl_wraps::WrapOStream &binary_stream) const
673 {
674  void* exception = NULL;
675 
676  _dll_handle->CameraCalibrator_saveCameraParameters(
677  _impl,
678  &binary_stream,
679  pbio::stl_wraps::WrapOStream::write_func,
680  &exception);
681 
682  checkException(exception, *_dll_handle);
683 }
684 
685 
686 inline
688  std::istream &binary_stream)
689 {
690  pbio::stl_wraps::WrapIStreamImpl binary_stream_wrap(binary_stream);
691 
692  loadCameraParameters(binary_stream_wrap);
693 }
694 
695 inline
697  pbio::stl_wraps::WrapIStream &binary_stream)
698 {
699  void* exception = NULL;
700 
701  _dll_handle->CameraCalibrator_loadCameraParameters(
702  _impl,
703  &binary_stream,
704  pbio::stl_wraps::WrapIStream::read_func,
705  &exception);
706 
707  checkException(exception, *_dll_handle);
708 }
709 
710 
711 } // pbio namespace
712 
713 #endif // __PBIO_API__PBIO__CAMERACALIBRATOR_H_
HeavySmartPtr< IRawImage >::tPtr Ptr
Псевдоним для типа умного указателя на IRawImage.
Definition: IRawImage.h:39
int image_height
Высота изображения для калибровки.
Definition: CameraCalibrator.h:82
Структура, предоставляющая данные изображения в "сыром" формате и опциональную информацию для обрезки...
Definition: RawImage.h:28
Интерфейсный объект для создания других интерфейсных объектов.
Definition: FacerecService.h:64
PatternType pattern_type
Тип калибровочного шаблона.
Definition: CameraCalibrator.h:89
LightSmartPtr< CameraCalibrator >::tPtr Ptr
Псевдоним для типа умного указателя на CameraCalibrator.
Definition: CameraCalibrator.h:48
std::vector< Point > getTip()
Получить подсказку о требуемой позиции калибровочного шаблона на изображении для лучшего покрытия...
Definition: CameraCalibrator.h:561
int width
Ширина изображения.
Definition: RawImage.h:109
Настройки калибровки.
Definition: CameraCalibrator.h:56
Format format
Формат данных изображения.
Definition: RawImage.h:125
Error - класс исключений, выбрасываемых при возникновении ошибок.
bool fix_aspect_ratio
Зафиксировать соотношение сторон.
Definition: CameraCalibrator.h:110
int pattern_width
Ширина калибровочного шаблона.
Definition: CameraCalibrator.h:96
bool calib_fix_principal_point
Зафиксировать принципиальную точку в центре изображения.
Definition: CameraCalibrator.h:124
void addImage(const RawImage image, bool *pattern_found, bool *pattern_accepted, std::vector< Point > *pattern_points)
Поиск калибровочного шаблона на изображении и его сохранение.
Definition: CameraCalibrator.h:484
IRawImage::Ptr undistort(const RawImage image, const float alpha) const
Скорректировать дисторсию изображения, используя откалиброванные или загруженные параметры камеры...
Definition: CameraCalibrator.h:622
bool calib_zero_tangent_dist
Считать тангенциальную дисторсию нулевой.
Definition: CameraCalibrator.h:117
int height
Высота изображения.
Definition: RawImage.h:117
int pattern_height
Высота калибровочного шаблона.
Definition: CameraCalibrator.h:103
void loadCameraParameters(std::istream &binary_stream)
Загрузить откалиброванные параметры. Формат платформонезависимый.
Definition: CameraCalibrator.h:687
Интерфейсный объект для калибровки камеры и коррекции дисторсии.
Definition: CameraCalibrator.h:39
SmartPtr.
int image_width
Ширина изображения для калибровки.
Definition: CameraCalibrator.h:75
float getPatternSpaceCoverProgress() const
Оценка покрытия пространства поз калибровочного шаблона для более точной калибровки.
Definition: CameraCalibrator.h:546
bool rational_distortion_model
Использовать rational distortion model.
Definition: CameraCalibrator.h:131
PatternType
Типы калибровочных шаблонов.
Definition: CameraCalibrator.h:63
void initCalibration(const CalibrationSettings settings)
Инициализация процесса калибровки. Ранее принятые шаблоны будут удалены.
Definition: CameraCalibrator.h:452
bool calibrate(const int max_used_patterns_count, float *reprojection_error)
Калибровка камеры.
Definition: CameraCalibrator.h:598
void saveCameraParameters(std::ostream &binary_stream) const
Сохранить откалиброванные параметры. Формат платформонезависимый.
Definition: CameraCalibrator.h:662