~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/vision/camera/camera.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 /**
  4 camera.c:
  5 general camera functions
  6 **/
  7 
  8 #include <tina/sys.h>
  9 #include <tina/sysfuncs.h>
 10 #include <tina/math.h>
 11 #include <tina/mathfuncs.h>
 12 #include <tina/vision.h>
 13 #include <tina/visionfuncs.h>
 14 
 15 /* ARGSUSED quieten lint */
 16 Camera *cam_alloc(int type)
 17 /* unused */
 18 {
 19     Camera *cam = ts_ralloc(Camera);
 20 
 21     cam->label = new_label();
 22 
 23     return (cam);
 24 }
 25 
 26 void    cam_comp_default_rects(Camera * cam)
 27 {
 28     double  kx, ky;
 29     double  cx, cy;
 30 
 31     if (cam == NULL)
 32         return;
 33 
 34     kx = cam->ax * cam->f / cam->pixel;
 35     ky = cam->ay * cam->f / cam->pixel;
 36     cx = cam->cx;
 37     cy = cam->cy;
 38 
 39     cam->cam_to_im = mat3(kx, 0.0, cx,
 40                           0.0, ky, cy,
 41                           0.0, 0.0, 1.0);
 42 
 43     cam->im_to_cam = mat3(1.0 / kx, 0.0, -cx / kx,
 44                           0.0, 1.0 / ky, -cy / ky,
 45                           0.0, 0.0, 1.0);
 46 }
 47 
 48 Camera *cam_make(unsigned int type, Transform3 * transf, double f, double pix, double ax, double ay, double cx, double cy, int width, int height)
 49 {
 50     Camera *cam = ts_ralloc(Camera);
 51 
 52     cam->type = type;
 53     cam->label = new_label();
 54 
 55     cam->f = (float)f;
 56     cam->ax = (float)ax;
 57     cam->ay = (float)ay;
 58     cam->cx = (float)cx;
 59     cam->cy = (float)cy;
 60     cam->pixel = (float)pix;
 61     cam->width = width;
 62     cam->height = height;
 63 
 64     cam->distort_params = NULL;
 65     cam->distort_func = cam->correct_func = NULL;
 66     cam->correct_func = NULL;
 67     cam->copy_dist_func = NULL;
 68     cam->transf = trans3_copy(transf);
 69 
 70     cam_comp_default_rects(cam);
 71 
 72     return (cam);
 73 }
 74 
 75 Camera *cam_copy(Camera * cam)
 76 {
 77     Camera *new_cam;
 78 
 79     if (cam == NULL)
 80         return (NULL);
 81     new_cam = cam_make(cam->type, cam->transf, cam->f, cam->pixel,
 82                        cam->ax, cam->ay, cam->cx, cam->cy,
 83                        cam->width, cam->height);
 84     new_cam->correct_func = cam->correct_func;
 85     new_cam->distort_func = cam->distort_func;
 86     if (cam->distort_params != NULL)
 87     {
 88         if (cam->copy_dist_func != NULL)
 89         {
 90             new_cam->distort_params = cam->copy_dist_func(cam->distort_params);
 91             new_cam->copy_dist_func = cam->copy_dist_func;
 92         } else
 93         {
 94             format("warning: distortion parameters not copied\n");
 95             new_cam->correct_func = new_cam->distort_func = NULL;
 96         }
 97     } else                      /* no distortion now */
 98         new_cam->correct_func = new_cam->distort_func = NULL;
 99     return (new_cam);
100 }
101 
102 Bool    cam_scale_to_image(Camera * cam, Imrect * im)
103 {
104     int     hscale, wscale;
105     Bool    larger;
106 
107     if (cam == NULL || im == NULL)
108         return (false);
109 
110     if (cam->width == im->width && cam->height == im->height)
111         return (true);
112 
113     if (cam->width > im->width)
114     {
115         larger = true;
116         wscale = cam->width / im->width;
117         if (cam->width != wscale * im->width)
118             return (false);     /* can't scale camera */
119     } else
120     {
121         larger = false;
122         wscale = im->width / cam->width;
123         if (im->width != wscale * cam->width)
124             return (false);     /* can't scale camera */
125     }
126 
127     if (cam->height > im->height)
128     {
129         if (larger == false)
130             return (false);
131         hscale = cam->height / im->height;
132         if (hscale != wscale || cam->height != hscale * im->height)
133             return (false);     /* cant scale camera */
134     } else
135     {
136         if (larger == true)
137             return (false);
138         hscale = im->height / cam->height;
139         if (hscale != wscale || im->height != hscale * cam->height)
140             return (false);     /* cant scale camera */
141     }
142 
143     if (larger)
144     {
145         cam->width /= wscale;
146         cam->height /= wscale;
147         cam->pixel *= wscale;   /* the pixel size increases */
148         cam->cx /= wscale;
149         cam->cy /= wscale;
150     } else
151     {
152         cam->width *= wscale;
153         cam->height *= wscale;
154         cam->pixel /= wscale;   /* the pixel size decreases */
155         cam->cx *= wscale;
156         cam->cy *= wscale;
157     }
158     cam_comp_default_rects(cam);
159     return (true);
160 }
161 
162 void    cam_free(Camera * cam)
163 {
164     if (cam == NULL)
165         return;
166 
167     if (cam->transf)
168         rfree((void *) cam->transf);
169     if (cam->distort_params)
170         rfree((void *) cam->distort_params);
171 
172     rfree((void *) cam);
173 }
174 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.