• Nenhum resultado encontrado

1.2.2 Módulo compute_mr no yes

return(0) aux1 = cos(rot[0]) aux2 = sin(rot[0]) aux3 = cos(rot[1]) aux4 = sin(rot[1]) aux5 = cos(rot[2]) aux6 = sin(rot[2]) mr[0][0] = aux3*aux5 mr[0][1] = aux3*aux6 mr[0][2] = -aux4 mr[1][0] = aux5*aux2*aux4-aux1*aux6 mr[1][1] = aux6*aux2*aux4+aux1*aux5 mr[1][2] = aux2*aux3 mr[2][0] = aux5*aux4*aux1+aux2*aux6 mr[2][1] = -aux2*aux5+aux6*aux4*aux1 mr[2][2] = aux3*aux1 rot[0] = ANG_DEG_RAD(rot[0]) rot[1] = ANG_DEG_RAD(rot[1]) rot[2] = ANG_DEG_RAD(rot[2]) c = 1 compute_mr(mr, rot, c)

1.2.3 - Módulo frame_world

return(0) xd = dxl*(xf-cx) yd = dy*(yf-cy) aux1 = xd*xd+yd*yd aux1 = 1+k*aux1 xu = xd*aux1 yu = yd*aux1 aux1 = xu*mr[2][0]-f*mr[0][0] aux2 = f*mr[0][1]-mr[2][1]*xu aux3 = zw*(f*mr[0][2]-xu*mr[2][2])-xu*trans[2]+f*trans[0] aux4 = yu*mr[2][1]-f*mr[1][1] aux5 = -yu*mr[2][0]+f*mr[1][0] aux6 = -yu*(mr[2][2]*zw+trans[2])+f*mr[1][2]*zw+trans[1]*f *yw = (aux6*aux1+aux3*aux5)/(aux1*aux4-aux5*aux2) *xw = (*yw*aux2+aux3)/aux1

frame_world(mr, trans, xf, yf, xw, yw, zw, dxl, dy, cx, cy, f, k)

1.3 - Listagem da implementação

Apresenta-se, de seguida, a listagem da implementação simspace desenvolvida

em linguagem C em ambiente UNIX numa estação de trabalho SunSparc e que se

destina ao ambiente de processamento de imagem XITE

2

, do qual utiliza algumas

funções e tipos de variáveis já previamente definidas. Esta implementação

contém comentários para auxílio à sua compreensão, assim como informação

sobre os diferentes módulos, para sua posterior extracção através da ferramenta

CDOC(1) existente no XITE.

/*

________________________________________________________________ simspace.c

@(#)simspace.c 1.00 94/06/19, Copyright 1994, DEEC, FEUP Departamento de Engenharia Electrotecnica e de Computadores Faculdade de Engenharia 4099 PORTO CODEX PORTUGAL E-mail: gpai@obelix.fe.up.pt _______________________________________________________________ readarg.h

@(#)readarg.h 1.3 92/01/15, Copyright 1990, Blab, UiO Image processing lab, Department of Informatics University of Oslo

E-mail: blab@ifi.uio.no

________________________________________________________________ message.h

@(#)message.h 1.3 92/01/15, Copyright 1990, Blab, UiO Image processing lab, Department of Informatics

University of Oslo E-mail: blab@ifi.uio.no

________________________________________________________________

Permission to use, copy, modify and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that this copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation and that the

name of B-lab, Department of Informatics or University of Oslo not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission.

B-LAB DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL B-LAB BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

*/ /*******************************************************************/ /* INCLUDES */ #include <stdio.h> #include <math.h> #include <stdlib.h> #include <blab/readarg.h> #include <blab/message.h> #include "gdefs.h" /*******************************************************************/ /*F:compute_mr* ________________________________________________________________ compute_mr ________________________________________________________________ Name: compute_mr - compute the rotation matrix 3D from object world coordinate system to the camera coordinate system Syntax: | int compute_mr(mr, rot, c)

| int c;

| double mr[][3], rot[];

Description: 'compute_mr' performs the determination of the rotation matrix 3D from object world coordinate system to the camera coordinate system.

'mr[][3]' is the rotation matrix 3D from object world coordinate system to the camera coordinate system.

'rot[]' is the angles of the rotation 3D from object world coordinate system to the camera coordinate system.

Return value: | 0 => Ok. Example: | Try yourself. Restrictions: None. Author: Joao Tavares

Id: @(#)compute_mr.c 1.00 94/06/10

________________________________________________________________ */

int compute_mr(mr, rot, c) int c;

double mr[][3], rot[]; {

double aux1, aux2, aux3, aux4, aux5, aux6; if (c == 1) { /* covertion deg/rad */ rot[0] = ANG_DEG_RAD(rot[0]); rot[1] = ANG_DEG_RAD(rot[1]); rot[2] = ANG_DEG_RAD(rot[2]); }

/* compute the rotation matrix */ aux1 = cos(rot[0]); aux2 = sin(rot[0]); aux3 = cos(rot[1]); aux4 = sin(rot[1]); aux5 = cos(rot[2]); aux6 = sin(rot[2]); mr[0][0] = aux3*aux5; mr[0][1] = aux3*aux6; mr[0][2] = -aux4; mr[1][0] = aux5*aux2*aux4-aux1*aux6;

mr[1][2] = aux2*aux3; mr[2][0] = aux5*aux4*aux1+aux2*aux6; mr[2][1] = -aux2*aux5+aux6*aux4*aux1; mr[2][2] = aux3*aux1; return(0); } /*******************************************************************/ /*F:frame_world* ________________________________________________________________ frame_world ________________________________________________________________ Name: frame_world - compute the world's coordinates of a point from its frame buffer's coordinates and z world coordinate Syntax: | int frame_world(mr, trans, xf, yf, xw, yw, zw, dxl, dy, cx, cy, f, k) | double mr[][3], trans[], *xw, *yw, zw, dxl, dy, f, k;

| int xf, yf, cx, cy;

Description: 'frame_world' performs the determination of the world coordinates of a point from its frame buffer's coordinates and z world coordinate. 'mr[][3]' is the rotation matrix 3D from object world coordinate system to the camera coordinate system.

'trans[]' is the translation vector 3D from object world coordinate system to the camera coordinate system.

'xf' and 'yf' are the frame buffer's coordinates.

'xw' and 'yw' passed by reference are the world's coordinates. 'zw' is the z world's coordinate.

'dxl' is (sx*dx) where dx is the distance between adjacent sensor elements in x (scan line) direction and sx is the horizontal uncertainty factor.

'dy' is the center to center distance between adjacent CCD sensor in the y direction.

'cx' and 'cy' are the row and column numbers of the center of frame buffer.

'f' is the effective focal length. 'k' is the lens's radial distortion. Return value: | 0 => Ok.

Example: | Try yourself. Restrictions: None. Author: Joao Tavares

Id: @(#)frame_world.c 1.00 94/06/10

________________________________________________________________ */

int frame_world(mr, trans, xf, yf, xw, yw, zw, dxl, dy, cx, cy, f, k) double mr[][3], trans[], *xw, *yw, zw, dxl, dy, f, k;

int xf, yf, cx, cy; {

double xd, yd, xu, yu, aux1, aux2, aux3, aux4, aux5, aux6; xd = dxl*(xf-cx); yd = dy*(yf-cy); aux1 = xd*xd+yd*yd; aux1 = 1.0+k*aux1; xu = xd*aux1; yu = yd*aux1; aux1 = xu*mr[2][0]-f*mr[0][0]; aux2 = f*mr[0][1]-mr[2][1]*xu; aux3 = zw*(f*mr[0][2]-xu*mr[2][2])-xu*trans[2]+f*trans[0]; aux4 = yu*mr[2][1]-f*mr[1][1]; aux5 = -yu*mr[2][0]+f*mr[1][0]; aux6 = -yu*(mr[2][2]*zw+trans[2])+f*mr[1][2]*zw+trans[1]*f; *yw = (aux6*aux1+aux3*aux5)/(aux1*aux4-aux5*aux2); *xw = (*yw*aux2+aux3)/aux1; return(0); } /*******************************************************************/ /*P:simspace* ________________________________________________________________ simspace

Name: simspace - determination of the area in a plane visible by a camera Syntax: | simspace [-cx <xcenterbuf>] [-cy <ycenterbuf>] [-xs <xsizebuf>] | [-ys <ysizebuf>] [-rx <rotationx>] [-ry <rotationy>] [-rx <rotationz>] | [-tx <translationx>] [-ty <translationy>] [-tz <translationz>] <f> | <dx> <dy> <sx> <k> <zwplane>

Description: 'simspace' performs the determination of the area in a plane visible by a camera using the TSAI's model.

The center of frame buffer in direction x is indicate through flag '-cx', by default 'xcenterbuf' is (xsizebuf/2).

The center of frame buffer in direction y is indicate through flag '-cy', by default 'ycenterbuf' is (ysizebuf/2).

The frame buffer's dimensions in directions x and y are indicate trough flags '-xs' and '-ys'. By default the frame buffer's dimensions are 512 by 512.

The angles (in degree) of rotation 3D from object world coordinate system to the camera coordinate system about the x, y and z axis, are indicate through the flags '-rx', '-ry' and '-rz'. By default they are all zero.

The translation 3D from object world coordinate system to the camera coordinate system along the x, y and z axis, are indicate through the flags '-tx', '-ty' and '-tz'. By default they are all zero. 'f' is the effective focal length.

'dx' is the center to center distance between adjacent sensor elements in x (scanline) direction.

'dy' is the center to center distance between adjacent CCD sensor in the y direction.

'sx' is the horizontal uncertainty factor. 'k' is the lens's radial distortion.

'zwplane' is the world 3D coordinate z of the plane. Return value: | 1 => The value for sx must be different from zero. | 2 => The value for dx must be greater than zero. | 3 => The value for dy must be greater than zero.

| 4 => Wrong value for rotation about x <rotationx>; it must be | greater than -360.0 and smaller than 360.0 degree. | 5 => Wrong value for rotation about y <rotationy>; it must be | greater than -360.0 and smaller than 360.0 degree. | 6 => Wrong value for rotation about z <rotationz>; it must be | greater than -360.0 and smaller than 360.0 degree. Examples: | Try yourself.

Restrictions: The value for sx must be different from zero. The values for dx and dy must be greater than zero.

The values for <rotationx>, <rotationy> and <rotationz>, must be smaller than 360 and greater than -360.

Author: Joao Tavares

Id: @(#)simspace.c 1.0 94/06/10

________________________________________________________________ */

#ifdef MAIN

static char *SccsId = "@(#)simspace.c 1.00 94/06/10, DEEC, FEUP"; void main(argc, argv)

int argc; char **argv; {

int nx, ny, cx, cy;

double zw, mr[3][3], rot[3], trans[3], f, dx, dy, dxl, sx, k, xw1, xw2, xw3, xw4, yw1, yw2, yw3, yw4;

int compute_mr(); int frame_world();

InitMessage(&argc, argv, "Usage: %s\n [-cx <xcenterbuf>] [-cy <ycenterbuf>] [-xs <xsizebuf>] [- ys <ysizebuf>] [-rx <rotationx>] [-ry <rotationy>] [-rx <rotationz>] [-tx <translationx>] [-ty <translationy>] [-tz <translationz>] <f> <dx> <dy> <sx> <k> <zwplane>\n");

Iset_message(1); Iset_abort(1); /* read switches */

cx = atoi(read_switch(&argc, argv, "-cx", 1, "0")); cy = atoi(read_switch(&argc, argv, "-cy", 1, "0")); nx = atoi(read_switch(&argc, argv, "-xs", 1, "512")); ny = atoi(read_switch(&argc, argv, "-ys", 1, "512")); rot[0] = atof(read_switch(&argc, argv, "-rx", 1, "0.0")); rot[1] = atof(read_switch(&argc, argv, "-ry", 1, "0.0")); rot[2] = atof(read_switch(&argc, argv, "-rz", 1, "0.0")); trans[0] = atof(read_switch(&argc, argv, "-tx", 1, "0.0")); trans[1] = atof(read_switch(&argc, argv, "-ty", 1, "0.0"));

if (argc == 1) Usage(1, (char*)0);

if (argc != 7) Usage(2, "\nBad number of arguments.\n"); /* read argv[] */ f = atof(argv[1]); dx = atof(argv[2]); dy = atof(argv[3]); sx = atof(argv[4]); k = atof(argv[5]); zw = atof(argv[6]); if (cx == 0) cx = nx/2; if (cy == 0) cy = ny/2;

if ( sx == 0.0) exit(Error(1, "\nThe value for sx must be different from zero.\n")); if ( dx <= 0.0) exit(Error(2, "\nThe value for dx must be greater than zero.\n")); if ( dy <= 0.0) exit(Error(3, "\nThe value for dy must be greater than zero.\n"));

if (rot[0] > 360.0 || rot[0] < -360.0) exit(Error(4, "\nWrong value for rotation about x %g; it must be greater than -360 and smaller than 360 degree.\n", rot[0]));

if (rot[1] > 360.0 || rot[1] < -360.0) exit(Error(5, "\nWrong value for rotation about y %g; it must be greater than -360 and smaller than 360 degree.\n", rot[1]));

if (rot[2] > 360.0 || rot[2] < -360.0) exit(Error(6, "\nWrong value for rotation about z %g; it must be greater than -360 and smaller than 360 degree.\n", rot[2]));

dxl = sx*dx;

/* compute the matrix R */ compute_mr(mr, rot, 1);

printf("\nRotation matrix:\n\n\tr1=%g\tr2=%g\tr3=%g\n\tr4=%g\tr5=%g\tr6=%g\n\tr7= %g\tr8=%g\tr9=%g.\n", mr[0][0], mr[0][1], mr[0][2], mr[1][0], mr[1][1], mr[1][2], mr[2][0], mr[2][1], mr[2][2]);

/* compute xw1, yw1, xw2, yw2, xw3, yw3, xw4, yw4 */

frame_world(mr, trans, 1, 1, &xw1, &yw1, zw, dxl, dy, cx, cy, f, k); frame_world(mr, trans, 1, ny, &xw2, &yw2, zw, dxl, dy, cx, cy, f, k); frame_world(mr, trans, nx, 1, &xw3, &yw3, zw, dxl, dy, cx, cy, f, k); frame_world(mr, trans, nx, ny, &xw4, &yw4, zw, dxl, dy, cx, cy, f, k);

printf("\nMaximum world space visible by the camera in the plane with z=%g:\n\n\tFirst corner: x=%g, y=%g\n\tSecond corner: x=%g, y=%g\n\tThird corner: x=%g, y=%g\n\tFourth corner: x=%g, y=%g.\n\n", zw, xw1, yw1, xw2, yw2, xw3, yw3, xw4, yw4);

} #endif