distortion_correction.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
36 #ifndef _DISTORTION_CORRECTION_H_
37 #define _DISTORTION_CORRECTION_H_
38 
39 
40 //####################################################################
43 #include <ros/ros.h>
44 
45 #include <opencv2/imgproc/imgproc.hpp>
46 #include <opencv2/highgui/highgui.hpp>
47 #include <opencv2/core/core.hpp>
48 
49 #include <mit_darpa_logs_player/camtrans.h>
50 
51 
52 #include "camera_parameters.h"
53 
55 {
56  // ------------------------------------------------------------------------------
57  //PUBLIC SECTION OF THE CLASS
58  // ------------------------------------------------------------------------------
59  public:
62 
63  int correct_image_distortion(const cv::Mat* distorted, cv::Mat* corrected)
64  {
65  cv::Mat K;
66  K.create(3,3,CV_64F);
67 
68  K.at<double>(0,0) = intrinsic.at<double>(0,0);
69  K.at<double>(0,1) = intrinsic.at<double>(0,1);
70  K.at<double>(0,2) = intrinsic.at<double>(0,2);
71 
72  K.at<double>(1,0) = intrinsic.at<double>(1,0);
73  K.at<double>(1,1) = intrinsic.at<double>(1,1);
74  K.at<double>(1,2) = intrinsic.at<double>(1,2);
75 
76  K.at<double>(2,0) = intrinsic.at<double>(2,0);
77  K.at<double>(2,1) = intrinsic.at<double>(2,1);
78  K.at<double>(2,2) = intrinsic.at<double>(2,2);
79 
80  cv::undistort(*distorted, *corrected, K, distortion);
81  return 1;
82  }
83 
84 
85 
86  int correct_spherical_image_distortion(const cv::Mat* distorted, cv::Mat* corrected)
87  {
88 
89  double position[3];
90  double orientation_quat[4];
91 
92  CamTrans* cam = camtrans_new_spherical(spherical_distortion_params.calibration_width,
93  spherical_distortion_params.calibration_height,
94  intrinsic.at<double>(0,0)/*fx*/,
95  intrinsic.at<double>(1,1)/*fy*/,
96  intrinsic.at<double>(0,2)/*intrinsic.cx*/,
97  intrinsic.at<double>(1,2)/*intrinsic.cy*/,
98  0 /*skew*/,
99  position, orientation_quat,
103 
104  camtrans_scale_image(cam, spherical_distortion_params.scale);
105  cv::Mat mapx;
106  mapx.create(240,376,CV_32FC1);
107 
108  cv::Mat mapy;
109  mapy.create(240,376,CV_32FC1);
110 
111  for (double x=0; x<240; x++)
112  for (double y=0; y<376; y++)
113  {
114  double ox,oy;
115  //camtrans_distort_pixel(cam, x,y,&ox, &oy);
116  camtrans_distort_pixel(cam, y,x,&oy, &ox);
117 
118  mapx.at<float>(x,y) = oy;
119  mapy.at<float>(x,y) = ox;
120  }
121 
122  cv::remap(*distorted, *corrected, mapx, mapy,CV_INTER_LINEAR);
123  return 1;
124  }
125  private:
126 
127 };
128 
129 #endif
130 
CGAL::Exact_predicates_inexact_constructions_kernel K
Defines a class where the parameters of a camera are stored.
struct class_camera_parameters::@0 spherical_distortion_params
int correct_image_distortion(const cv::Mat *distorted, cv::Mat *corrected)
int correct_spherical_image_distortion(const cv::Mat *distorted, cv::Mat *corrected)


polygon_primitives_extraction
Author(s): Miguel Oliveira
autogenerated on Mon Mar 2 2015 01:32:42