SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
CVCalibration.cpp File Reference
#include <CVCalibration.h>
#include <Utils.h>
#include <HighResTimer.h>
#include <utility>
Include dependency graph for CVCalibration.cpp:

Go to the source code of this file.

Functions

void getInnerAndOuterRectangles (const cv::Mat &cameraMatrix, const cv::Mat &distCoeffs, const cv::Mat &R, const cv::Mat &newCameraMatrix, const cv::Size &imgSize, cv::Rect_< float > &inner, cv::Rect_< float > &outer)
 get inscribed and circumscribed rectangle More...
 

Detailed Description

Date
Winter 2016
Remarks
Please use clangformat to format the code. See more code style on https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
Authors
Marcus Hudritsch, Michael Goettlicher

Definition in file CVCalibration.cpp.

Function Documentation

◆ getInnerAndOuterRectangles()

void getInnerAndOuterRectangles ( const cv::Mat &  cameraMatrix,
const cv::Mat &  distCoeffs,
const cv::Mat &  R,
const cv::Mat &  newCameraMatrix,
const cv::Size &  imgSize,
cv::Rect_< float > &  inner,
cv::Rect_< float > &  outer 
)

get inscribed and circumscribed rectangle

Definition at line 284 of file CVCalibration.cpp.

291 {
292  const int N = 9;
293  // Fill matrix with N * N sampling points
294  cv::Mat pts(N * N, 2, CV_32F);
295  for (int y = 0, k = 0; y < N; y++)
296  {
297  for (int x = 0; x < N; x++)
298  {
299  pts.at<float>(k, 0) = (float)x * (float)imgSize.width / (N - 1);
300  pts.at<float>(k, 1) = (float)y * (float)imgSize.height / (N - 1);
301  k++;
302  }
303  }
304 
305  pts = pts.reshape(2);
306  cv::undistortPoints(pts,
307  pts,
308  cameraMatrix,
309  distCoeffs,
310  R,
311  newCameraMatrix);
312  pts = pts.reshape(1);
313 
314  float iX0 = -FLT_MAX, iX1 = FLT_MAX, iY0 = -FLT_MAX, iY1 = FLT_MAX;
315  float oX0 = FLT_MAX, oX1 = -FLT_MAX, oY0 = FLT_MAX, oY1 = -FLT_MAX;
316  // find the inscribed rectangle.
317  // the code will likely not work with extreme rotation matrices (R) (>45%)
318  for (int y = 0, k = 0; y < N; y++)
319  for (int x = 0; x < N; x++)
320  {
321  cv::Point2f p = {pts.at<float>(k, 0),
322  pts.at<float>(k, 1)};
323  oX0 = MIN(oX0, p.x);
324  oX1 = MAX(oX1, p.x);
325  oY0 = MIN(oY0, p.y);
326  oY1 = MAX(oY1, p.y);
327 
328  if (x == 0)
329  iX0 = MAX(iX0, p.x);
330  if (x == N - 1)
331  iX1 = MIN(iX1, p.x);
332  if (y == 0)
333  iY0 = MAX(iY0, p.y);
334  if (y == N - 1)
335  iY1 = MIN(iY1, p.y);
336  k++;
337  }
338  inner = cv::Rect_<float>(iX0, iY0, iX1 - iX0, iY1 - iY0);
339  outer = cv::Rect_<float>(oX0, oY0, oX1 - oX0, oY1 - oY0);
340 }