projection
ocam_functions.h
Go to the documentation of this file.
1 /*------------------------------------------------------------------------------
2  Example code that shows the use of the 'cam2world" and 'world2cam" functions
3  Shows also how to undistort images into perspective or panoramic images
4  Copyright (C) 2008 DAVIDE SCARAMUZZA, ETH Zurich
5  Author: Davide Scaramuzza - email: davide.scaramuzza@ieee.org
6 ------------------------------------------------------------------------------*/
7 
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <float.h>
11 #include <math.h>
12 #include <cv.h>
13 #include <highgui.h>
14 
15 
16 #define CMV_MAX_BUF 1024
17 #define MAX_POL_LENGTH 64
18 
19 struct ocam_model
20 {
21  double pol[MAX_POL_LENGTH]; // the polynomial coefficients: pol[0] + x"pol[1] + x^2*pol[2] + ... + x^(N-1)*pol[N-1]
22  int length_pol; // length of polynomial
23  double invpol[MAX_POL_LENGTH]; // the coefficients of the inverse polynomial
24  int length_invpol; // length of inverse polynomial
25  double xc; // row coordinate of the center
26  double yc; // column coordinate of the center
27  double c; // affine parameter
28  double d; // affine parameter
29  double e; // affine parameter
30  int width; // image width
31  int height; // image height
32 };
33 
34 
35 /*------------------------------------------------------------------------------
36  This function reads the parameters of the omnidirectional camera model from
37  a given TXT file
38 ------------------------------------------------------------------------------*/
39 int get_ocam_model(struct ocam_model *myocam_model, const char *filename);
40 
41 /*------------------------------------------------------------------------------
42  WORLD2CAM projects a 3D point on to the image
43  WORLD2CAM(POINT2D, POINT3D, OCAM_MODEL)
44  projects a 3D point (point3D) on to the image and returns the pixel coordinates (point2D).
45 
46  POINT3D = [X;Y;Z] are the coordinates of the 3D point.
47  OCAM_MODEL is the model of the calibrated camera.
48  POINT2D = [rows;cols] are the pixel coordinates of the reprojected point
49 
50  Copyright (C) 2009 DAVIDE SCARAMUZZA
51  Author: Davide Scaramuzza - email: davide.scaramuzza@ieee.org
52 
53  NOTE: the coordinates of "point2D" and "center" are already according to the C
54  convention, that is, start from 0 instead than from 1.
55 ------------------------------------------------------------------------------*/
56 void world2cam(double point2D[2], double point3D[3], struct ocam_model *myocam_model);
57 
58 /*------------------------------------------------------------------------------
59  CAM2WORLD projects a 2D point onto the unit sphere
60  CAM2WORLD(POINT3D, POINT2D, OCAM_MODEL)
61  back-projects a 2D point (point2D), in pixels coordinates,
62  onto the unit sphere returns the normalized coordinates point3D = [x;y;z]
63  where (x^2 + y^2 + z^2) = 1.
64 
65  POINT3D = [X;Y;Z] are the coordinates of the 3D points, such that (x^2 + y^2 + z^2) = 1.
66  OCAM_MODEL is the model of the calibrated camera.
67  POINT2D = [rows;cols] are the pixel coordinates of the point in pixels
68 
69  Copyright (C) 2009 DAVIDE SCARAMUZZA
70  Author: Davide Scaramuzza - email: davide.scaramuzza@ieee.org
71 
72  NOTE: the coordinates of "point2D" and "center" are already according to the C
73  convention, that is, start from 0 instead than from 1.
74 ------------------------------------------------------------------------------*/
75 void cam2world(double point3D[3], double point2D[2], struct ocam_model *myocam_model);
76 /*------------------------------------------------------------------------------
77  Create Look Up Table for undistorting the image into a perspective image
78  It assumes the the final image plane is perpendicular to the camera axis
79 ------------------------------------------------------------------------------*/
80 void create_perspective_undistortion_LUT( CvMat *mapx, CvMat *mapy, struct ocam_model *ocam_model, float sf);
81 
82 /*------------------------------------------------------------------------------
83  Create Look Up Table for undistorting the image into a panoramic image
84  It computes a trasformation from cartesian to polar coordinates
85  Therefore it does not need the calibration parameters
86  The region to undistorted in contained between Rmin and Rmax
87  xc, yc are the row and column coordinates of the image center
88 ------------------------------------------------------------------------------*/
89 void create_panoramic_undistortion_LUT ( CvMat *mapx, CvMat *mapy, float Rmin, float Rmax, float xc, float yc );
double xc
Definition: ocam_functions.h:25
int length_invpol
Definition: ocam_functions.h:24
void cam2world(double point3D[3], double point2D[2], struct ocam_model *myocam_model)
Definition: ocam_functions.cpp:75
double c
Definition: ocam_functions.h:27
#define MAX_POL_LENGTH
Definition: ocam_functions.h:17
int length_pol
Definition: ocam_functions.h:22
void create_perspective_undistortion_LUT(CvMat *mapx, CvMat *mapy, struct ocam_model *ocam_model, float sf)
Definition: ocam_functions.cpp:153
void create_panoramic_undistortion_LUT(CvMat *mapx, CvMat *mapy, float Rmin, float Rmax, float xc, float yc)
Definition: ocam_functions.cpp:179
double yc
Definition: ocam_functions.h:26
double d
Definition: ocam_functions.h:28
double pol[MAX_POL_LENGTH]
Definition: ocam_functions.h:21
int get_ocam_model(struct ocam_model *myocam_model, const char *filename)
Definition: ocam_functions.cpp:11
double invpol[MAX_POL_LENGTH]
Definition: ocam_functions.h:23
int height
Definition: ocam_functions.h:31
double e
Definition: ocam_functions.h:29
void world2cam(double point2D[2], double point3D[3], struct ocam_model *myocam_model)
Definition: ocam_functions.cpp:109
int width
Definition: ocam_functions.h:30
Definition: ocam_functions.h:19