camera.cpp
Go to the documentation of this file.
1 
12 #include "tuw_utils/camera.h"
13 
14 namespace tuw {
15 
16 
17 void Camera::distort(const std::vector<cv::Point2f> &src, std::vector<cv::Point2f> &des) {
18  const double &srcFx = projectionMatrix(0,0);
19  const double &srcFy = projectionMatrix(1,1);
20  const double &srcCx = projectionMatrix(0,2);
21  const double &srcCy = projectionMatrix(1,2);
22  const double &k1 = distCoeffs(0,0);
23  const double &k2 = distCoeffs(0,1);
24  const double &p1 = distCoeffs(0,2);
25  const double &p2 = distCoeffs(0,3);
26  const double &k3 = distCoeffs(0,4);
27  const double &desFx = cameraMatrix(0,0);
28  const double &desFy = cameraMatrix(1,1);
29  const double &desCx = cameraMatrix(0,2);
30  const double &desCy = cameraMatrix(1,2);
31  des.resize(src.size());
32  double x, y, x1, y1, r2, r4, r6, a1, a2, a3, cdist;
33  for(unsigned int i = 0; i < src.size(); i++) {
34 
35  x = (src[i].x - srcCx) / srcFx;
36  y = (src[i].y - srcCy) / srcFy;
37  r2 = x*x + y*y;
38  r4 = r2*r2;
39  r6 = r4*r2;
40  a1 = 2*x*y;
41  a2 = r2 + 2*x*x;
42  a3 = r2 + 2*y*y;
43  cdist = 1+k1*r2+k2*r4+k3*r6;
44  x1 = (x*cdist + p1*a1 + p2*a2);
45  y1 = (y*cdist + p1*a3 + p2*a1);
46 
47  des[i].x = x1 * desFx + desCx;
48  des[i].y = y1 * desFy + desCy;
49  }
50 }
51 
52 void Camera::distort(const cv::RotatedRect &src, cv::RotatedRect &des) {
53 
54  std::vector<cv::Point2f> vtx(5);
55  src.points(&vtx[0]);
56  vtx[4] = src.center;
57  std::vector<cv::Point2f> vtxDistort;
58  distort(vtx, vtxDistort);
59  des.size = cv::Size2f((cv::norm(vtx[2] - vtx[1])+cv::norm(vtx[0] - vtx[3]))/2., (cv::norm(vtx[1] - vtx[0])+cv::norm(vtx[3] - vtx[2]))/2.);
60  des.angle = atan2(vtx[2].y - vtx[1].y, vtx[2].x - vtx[1].x) * 180.0/M_PI;
61  des.center = vtxDistort[4];
62 
63 }
64 
65 
66 }
cv::Mat_< double > distCoeffs
Definition: camera.h:35
void distort(const std::vector< cv::Point2f > &src, std::vector< cv::Point2f > &des)
Definition: camera.cpp:17
cv::Mat_< double > projectionMatrix
Definition: camera.h:36
TFSIMD_FORCE_INLINE const tfScalar & y() const
cv::Mat_< double > cameraMatrix
Definition: camera.h:34
TFSIMD_FORCE_INLINE const tfScalar & x() const


tuw_ellipses
Author(s): Markus Bader
autogenerated on Mon Jun 10 2019 15:42:10