Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
futbot
futbot2014
Commits
2779edd3
Commit
2779edd3
authored
Oct 16, 2014
by
Aylen Ricca
Browse files
para compilar ej
parent
f8d6d071
Changes
17
Expand all
Hide whitespace changes
Inline
Side-by-side
visrob2/example/ejCAMVISCONF/clasification.c
0 → 100644
View file @
2779edd3
/*############################################################
# #
# Proyecto Visión robótica y reconstrucción espacial #
# con aplicaciones prácticas. 2010 #
# http://www.fing.edu.uy/inco/grupos/mina/pGrado/vision2010 #
# #
############################################################*/
#include "clasification.h"
#include "iVisionModule.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
//#include <util/delay.h>
int
HaViMo_id
;
/**
* Verifica si 2 blobs pueden ser combinados. Retorna la posicion del blob a, de acuerdo al blob b
* a blob para comparar con b
* b blob para comparar con a
* x_threshold umbral para la comparacion en el eje x
* y_threshold umbral para la comparacion en el eje y
* Retorna:
* 0 No pueden ser combinados
* 1 A arriba de B
* 2 A debajo B
* 3 A a la izquierda de B
* 4 A a la derecha de B
*/
int
vision_cla_canBlobsBeMerged
(
struct
blob
a
,
struct
blob
b
,
unsigned
int
x_threshold
,
unsigned
int
y_threshold
)
{
if
((
abs
(
a
.
min_x
-
b
.
min_x
)
<
x_threshold
)
&&
(
abs
(
a
.
max_x
-
b
.
max_x
)
<
x_threshold
))
{
//A TOP B
if
(
abs
(
a
.
max_y
-
b
.
min_y
)
<
y_threshold
)
return
1
;
//A BOT B
if
(
abs
(
a
.
min_y
-
b
.
max_y
)
<
y_threshold
)
return
2
;
}
if
((
abs
(
a
.
min_y
-
b
.
min_y
)
<
y_threshold
)
&&
(
abs
(
a
.
max_y
-
b
.
max_y
)
<
y_threshold
))
{
//A LEFT B
if
(
abs
(
a
.
max_x
-
b
.
min_x
)
<
x_threshold
)
return
3
;
//A RIGHT B
if
(
abs
(
a
.
min_x
-
b
.
max_x
)
<
x_threshold
)
return
4
;
}
return
0
;
}
/**
* Inicializa las estructuras que utiliza la clasificacion, inicializando iHaViMo.
* HaViMo_dxl_ID identificador dynamixel de havimo
* baudnum baudnum con que se incializara la libreria dynamixel
*/
int
vision_cls_initialize
(
int
HaViMo_dxl_ID
,
int
baudnum
)
{
HaViMo_id
=
HaViMo_dxl_ID
;
return
iVisionModule_initialize
(
HaViMo_dxl_ID
,
baudnum
);
}
/**
* Mergear los blobs, a partir de un region_color especifico, usando como umbral GOAL_THRESHOLD_X y GOAL_THRESHOLD_Y
* blobs blobs a mergear
* region_color color que se debe mergear
* dont_process_blob array que define si no se debe procesar un blob
*/
void
vision_cls_mergeGoalBlobsByRegion
(
struct
blob
*
blobs
,
short
int
region_color
,
unsigned
short
int
*
dont_process_blob
)
{
//Preprocesamiento del array de blobs
unsigned
short
int
i
;
unsigned
short
int
j
;
unsigned
short
int
blobs_merged
;
do
{
blobs_merged
=
0
;
for
(
i
=
0
;
i
<
CANT_REGIONS
;
i
++
)
{
if
(
blobs
[
i
].
region_index
!=
INVALID_REGION
&&
blobs
[
i
].
region_color
==
region_color
&&
!
dont_process_blob
[
i
])
{
for
(
j
=
i
+
1
;
j
<
CANT_REGIONS
;
j
++
)
{
if
(
!
dont_process_blob
[
j
]
&&
blobs
[
j
].
region_index
!=
INVALID_REGION
&&
blobs
[
i
].
region_color
==
blobs
[
j
].
region_color
&&
vision_cla_canBlobsBeMerged
(
blobs
[
i
],
blobs
[
j
],
GOAL_THRESHOLD_X
,
GOAL_THRESHOLD_Y
))
{
//Se combinan los blobs
blobs
[
j
].
region_index
=
0
;
if
(
blobs
[
i
].
max_x
<
blobs
[
j
].
max_x
)
blobs
[
i
].
max_x
=
blobs
[
j
].
max_x
;
if
(
blobs
[
i
].
min_x
>
blobs
[
j
].
min_x
)
blobs
[
i
].
min_x
=
blobs
[
j
].
min_x
;
if
(
blobs
[
i
].
max_y
<
blobs
[
j
].
max_y
)
blobs
[
i
].
max_y
=
blobs
[
j
].
max_y
;
if
(
blobs
[
i
].
min_y
>
blobs
[
j
].
min_y
)
blobs
[
i
].
min_y
=
blobs
[
j
].
min_y
;
blobs_merged
=
1
;
}
}
}
}
}
while
(
blobs_merged
);
}
/**
* Retorna el preprocesamiento realizado sobre el resultado de la segmentacion de la imagen de HaViMo.
* Si no hay un nuevo frame para procesar se retorna NULL.
* force_frame fuerza la obtencion del frame.
*/
struct
blob
*
vision_cls_getNextFrame
(
unsigned
short
int
force_frame
)
{
struct
blob
*
blobs
=
iVisionModule_getNextFrame
(
HaViMo_id
);
if
(
force_frame
)
{
while
(
blobs
==
NULL
){
//_delay_ms(FORCE_FRAME_MS_DELAY);
blobs
=
iVisionModule_getNextFrame
(
HaViMo_id
);
}
}
else
{
if
(
blobs
==
NULL
)
{
printf
(
"null blobs
\n
"
);
return
NULL
;
}
}
//Preprocesamiento del array de blobs
unsigned
short
int
i
;
unsigned
short
int
j
;
unsigned
short
int
blobs_merged
;
do
{
blobs_merged
=
0
;
for
(
i
=
0
;
i
<
CANT_REGIONS
;
i
++
)
{
printf
(
"procesar
\n
"
);
if
(
blobs
[
i
].
region_index
!=
INVALID_REGION
)
{
printf
(
"no es invalida
\n
"
);
if
(
blobs
[
i
].
max_x
-
blobs
[
i
].
min_x
<=
MIN_PX_SIZE_FOR_BLOB
||
blobs
[
i
].
max_y
-
blobs
[
i
].
min_y
<=
MIN_PX_SIZE_FOR_BLOB
)
{
//Invalidamos el blob
printf
(
"invalido blobs
\n
"
);
blobs
[
i
].
region_index
=
INVALID_REGION
;
}
else
{
for
(
j
=
i
+
1
;
j
<
CANT_REGIONS
;
j
++
)
{
if
(
blobs
[
j
].
region_index
!=
INVALID_REGION
&&
blobs
[
i
].
region_color
==
blobs
[
j
].
region_color
&&
vision_cla_canBlobsBeMerged
(
blobs
[
i
],
blobs
[
j
],
THRESHOLD_X
,
THRESHOLD_Y
))
{
//Se combinan los blobs
printf
(
"blobs combinados
\n
"
);
blobs
[
j
].
region_index
=
INVALID_REGION
;
if
(
blobs
[
i
].
max_x
<
blobs
[
j
].
max_x
)
blobs
[
i
].
max_x
=
blobs
[
j
].
max_x
;
if
(
blobs
[
i
].
min_x
>
blobs
[
j
].
min_x
)
blobs
[
i
].
min_x
=
blobs
[
j
].
min_x
;
if
(
blobs
[
i
].
max_y
<
blobs
[
j
].
max_y
)
blobs
[
i
].
max_y
=
blobs
[
j
].
max_y
;
if
(
blobs
[
i
].
min_y
>
blobs
[
j
].
min_y
)
blobs
[
i
].
min_y
=
blobs
[
j
].
min_y
;
blobs
[
i
].
number_of_pixels
+=
blobs
[
j
].
number_of_pixels
;
blobs_merged
=
1
;
}
}
}
}
else
printf
(
"es invalida
\n
"
);
}
}
while
(
blobs_merged
);
return
blobs
;
}
/**
* Finaliza clasificacion. Finaliza iHaViMo.
*/
void
vision_cls_terminate
(
void
)
{
iVisionModule_terminate
();
}
visrob2/example/ejCAMVISCONF/clasification.h
0 → 100644
View file @
2779edd3
/*############################################################
# #
# Proyecto Visión robótica y reconstrucción espacial #
# con aplicaciones prácticas. 2010 #
# http://www.fing.edu.uy/inco/grupos/mina/pGrado/vision2010 #
# #
############################################################*/
/**
* clasification.h: Modulo de clasificacion de la capa de Vision.
* Encargado del preprocesamiento de los blobs obtenidos de HaViMo.
* @author: Gonzalo Gismero
*/
#ifndef I_VISION_CLASIFICATION
#define I_VISION_CLASIFICATION
#include "iVisionModule.h"
#define MIN_PX_SIZE_FOR_BLOB 2//Quitamos los blobs que tengan un ancho o largo de 2 pixeles
#define FORCE_FRAME_MS_DELAY 10 //miliseconds
#define THRESHOLD_Y 7//10 //px
#define THRESHOLD_X 7//10 //px
//Luego del identificar los blobs de los landmarks, se intenta juntar los blobs que sobraron para los arcos con un umbral mayor
#define GOAL_THRESHOLD_X 15//px
#define GOAL_THRESHOLD_Y 15//px
/**
* Inicializa las estructuras que utiliza la clasificacion, inicializando iHaViMo.
* HaViMo_dxl_ID identificador dynamixel de havimo
* baudnum baudnum con que se incializara la libreria dynamixel
*/
int
vision_cls_initialize
(
int
HaViMo_dxl_ID
,
int
baudnum
);
/**
* Finaliza clasificacion. Finaliza iHaViMo.
*/
void
vision_cls_terminate
(
void
);
/**
* Retorna el preprocesamiento realizado sobre el resultado de la segmentacion de la imagen de HaViMo.
* Si no hay un nuevo frame para procesar se retorna NULL.
* force_frame fuerza la obtencion del frame.
*/
struct
blob
*
vision_cls_getNextFrame
(
unsigned
short
int
force_frame
);
/**
* Verifica si 2 blobs pueden ser combinados. Retorna la posicion del blob a, de acuerdo al blob b
* a blob para comparar con b
* b blob para comparar con a
* x_threshold umbral para la comparacion en el eje x
* y_threshold umbral para la comparacion en el eje y
* Retorna:
* 0 No pueden ser combinados
* 1 A arriba de B
* 2 A debajo B
* 3 A a la izquierda de B
* 4 A a la derecha de B
*/
int
vision_cla_canBlobsBeMerged
(
struct
blob
a
,
struct
blob
b
,
unsigned
int
x_threshold
,
unsigned
int
y_threshold
);
/**
* Mergear los blobs, a partir de un region_color especifico, usando como umbral GOAL_THRESHOLD_X y GOAL_THRESHOLD_Y
* blobs blobs a mergear
* region_color color que se debe mergear
* dont_process_blob array que define si no se debe procesar un blob
*/
void
vision_cls_mergeGoalBlobsByRegion
(
struct
blob
*
blobs
,
short
int
region_color
,
unsigned
short
int
*
dont_process_blob
);
#endif
visrob2/example/ejCAMVISCONF/config.c
0 → 100644
View file @
2779edd3
/*############################################################
# #
# Proyecto Futbol de Robots. - PAIE 2014 #
# http://www.fing.edu.uy/inco/proyectos/futbot13/ #
# #
############################################################*/
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "confuse.h"
#include "config.h"
cfg_t
*
initCfg
(
const
char
*
fileConf
){
cfg_opt_t
objects_op
[]
=
{
CFG_INT
(
"id"
,
0
,
CFGF_NONE
),
CFG_INT_LIST
(
"hsiMin"
,
0
,
CFGF_NONE
),
CFG_INT_LIST
(
"hsiMax"
,
0
,
CFGF_NONE
),
CFG_END
()
};
cfg_opt_t
opts
[]
=
{
// CFG_INT("cant_objects", 0, CFGF_NONE), //cant objects allowed to detect
CFG_SEC
(
"region"
,
objects_op
,
CFGF_TITLE
|
CFGF_MULTI
),
//detailed objects params
// CFG_INT("rpi_cam", 0, CFGF_NONE), //using RPI camera connected via CSI --only for tests
// CFG_INT("rpi_cam", 0, CFGF_NONE), //using RPI camera connected via CSI --only for tests
CFG_END
()
};
cfg_t
*
cfg
=
cfg_init
(
opts
,
CFGF_NONE
);
switch
(
cfg_parse
(
cfg
,
fileConf
))
{
case
CFG_FILE_ERROR
:
printf
(
"warning: configuration file '%s' could not be read: %s
\n
"
,
fileConf
,
strerror
(
errno
));
printf
(
"continuing with default values...
\n\n
"
);
case
CFG_SUCCESS
:
break
;
case
CFG_PARSE_ERROR
:
return
0
;
}
return
cfg
;
}
visrob2/example/ejCAMVISCONF/config.h
0 → 100644
View file @
2779edd3
/*############################################################
# #
# Proyecto Futbol de Robots. - PAIE 2014 #
# http://www.fing.edu.uy/inco/proyectos/futbot13/ #
# #
############################################################*/
#ifndef I_CONFIG
#define I_CONFIG
#include "confuse.h"
cfg_t
*
initCfg
(
const
char
*
fileConf
);
#endif
visrob2/example/ejCAMVISCONF/confuse.h
0 → 100644
View file @
2779edd3
This diff is collapsed.
Click to expand it.
visrob2/example/ejCAMVISCONF/futbotVision.conf
0 → 100644
View file @
2779edd3
# regiones a detectar por el modulo vision -calibraciones
region
ball
{
id
=
0
hsiMin
={
11
,
207
,
81
}
hsiMax
={
19
,
255
,
202
}
}
region
field
{
id
=
1
hsiMin
={
25
,
7
,
125
}
hsiMax
={
33
,
31
,
32
}
}
region
my_goal
{
id
=
2
hsiMin
={
21
,
208
,
82
}
hsiMax
={
24
,
253
,
145
}
}
region
opp_goal
{
id
=
3
hsiMin
={
107
,
58
,
44
}
hsiMax
={
118
,
142
,
55
}
}
region
robot_body
{
id
=
4
hsiMin
={
0
,
0
,
19
}
hsiMax
={
0
,
0
,
22
}
}
region
cyan
{
id
=
5
hsiMin
={
0
,
0
,
0
}
hsiMax
={
0
,
0
,
0
}
}
region
magenta
{
id
=
6
hsiMin
={-
24
,
41
,
24
}
hsiMax
={
6
,
215
,
115
}
}
visrob2/example/ejCAMVISCONF/iVisionModule.h
0 → 100644
View file @
2779edd3
/*############################################################
# #
# Proyecto Futbol de Robots. - PAIE 2014 #
# http://www.fing.edu.uy/inco/proyectos/futbot13/ #
# #
############################################################*/
/**
* iVisionModule.h: Interfaz de capa de Interaccion con Camara.
* Realiza el pasaje de blobs detectado.
*/
#ifndef I_VISION_MODULE
#define I_VISION_MODULE
//Region index 0..15
#define INVALID_REGION 0
//Region color
#define UNKOWN_REGION 0
#define BALL_REGION 1
#define FIELD_REGION 2
#define MY_GOAL_REGION 3
#define OPP_GOAL_REGION 4
#define ROBOT_REGION 5
#define CYAN_REGION 6
#define MAGENTA_REGION 7
#define CANT_REGIONS 15
#define IMAGE_WIDTH 160 //px
#define IMAGE_HEIGHT 120 //px
#define DISTANCIA_FOCAL_HAVIMO 164//d(cm) * ancho(px) / ancho(cm)
#define DFH_FOR_PROPORTION 179
struct
blob
{
unsigned
int
region_index
;
unsigned
int
region_color
;
unsigned
int
number_of_pixels
;
unsigned
int
sum_of_x_coord_high
;
unsigned
int
sum_of_x_coord_low
;
unsigned
int
sum_of_y_coord_high
;
unsigned
int
sum_of_y_coord_low
;
unsigned
int
max_x
;
unsigned
int
min_x
;
unsigned
int
max_y
;
unsigned
int
min_y
;
};
/**
* Inicializa las estructuras que utiliza la interfaz.
*/
int
iVisionModule_initialize
(
int
ID
,
int
rate
);
/**
* Elimina las estructuras utilizadas por el modulo.
*/
int
iVisionModule_terminate
(
void
);
/**
* Obtiene el siguiente frame de la camara. En caso de que no este disponible se devuelve NULL
* Si el resultado es valido, antes de devolverlo se procesa.
*/
struct
blob
*
iVisionModule_getNextFrame
(
int
ID
);
/*---------------FUNCIONES AUXILIARES PARA MANEJO DE BLOB---------------*/
/**
* Retorna la comparacion de los arrays de blobs b1 y b2
* b1: array para comparar con b2
* b2: array para comparar con b1
*/
unsigned
int
blob_array_blob_equals
(
struct
blob
*
b1
,
struct
blob
*
b2
);
/**
* Compara 2 blobs
* b1: blob a comparar con b2
* b2: blob a comparar con b1
*/
unsigned
int
blob_equals
(
struct
blob
b1
,
struct
blob
b2
);
/**
* Imprime un conjunto de blobs en consola. Se debe estar conectado a través del puerto serial.
* blobs: array de blobs a imprimr
*/
void
iVisionModule_printBlobs
(
struct
blob
*
blobs
);
#endif
visrob2/example/ejCAMVISCONF/icvBlobs.c
0 → 100644
View file @
2779edd3
/*############################################################
# #
# Proyecto Futbol de Robots. - PAIE 2014 #
# http://www.fing.edu.uy/inco/proyectos/futbot13/ #
# #
############################################################*/
#include "iVisionModule.h"
#include "utilsBlobs.h"
#include <stdio.h>
#include <stdlib.h>
int
BLOB_LENGTH
=
0x10
;
//se leen 16 bytes
/**
* Retorna la comparacion de los arrays de blobs b1 y b2
* b1: array para comparar con b2
* b2: array para comparar con b1
*/
unsigned
int
blob_array_blob_equals
(
struct
blob
*
b1
,
struct
blob
*
b2
)
{
int
i
;
unsigned
int
res
=
0
;
for
(
i
=
0
;
i
<
CANT_REGIONS
;
i
++
)
{
res
=
res
+
blob_equals
(
b1
[
i
],
b2
[
i
]);
}
return
res
;
}
/**
* Compara 2 blobs
* b1: blob a comparar con b2
* b2: blob a comparar con b1
*/
unsigned
int
blob_equals
(
struct
blob
b1
,
struct
blob
b2
)
{
if
(
b1
.
region_index
==
b2
.
region_index
&&
b1
.
region_color
==
b2
.
region_color
&&
b1
.
number_of_pixels
==
b2
.
number_of_pixels
&&
b1
.
sum_of_x_coord_high
==
b2
.
sum_of_x_coord_high
&&
b1
.
sum_of_x_coord_low
==
b2
.
sum_of_x_coord_low
&&
b1
.
sum_of_y_coord_high
==
b2
.
sum_of_y_coord_high
&&
b1
.
sum_of_y_coord_low
==
b2
.
sum_of_y_coord_low
&&
b1
.
max_x
==
b2
.
max_x
&&
b1
.
min_x
==
b2
.
min_x
&&
b1
.
max_y
==
b2
.
max_y
&&
b1
.
min_y
==
b2
.
min_y
)
return
1
;
return
0
;
}
/**
* Obtiene el siguiente frame de la camara. En caso de que no este disponible se devuelve NULL
* Si el resultado es valido, antes de devolverlo se procesa.
*/
struct
blob
*
iVisionModule_getNextFrame
(
int
ID
)
{
//Preguntamos si ya se puede acceder a la camara
if
(
!
utilBlobs_getFrame
())
{
//--FIXME esta funcion obtiene un nuevo frame, retorna null si hay algun problema con la lectura desde la cam
//No esta pronto el frame
return
NULL
;
}
//Obtenemos los blobs detectados
struct
blob
*
result
=
(
struct
blob
*
)
malloc
(
sizeof
(
struct
blob
)
*
CANT_REGIONS
);
utilBlobs_getBlobs
(
result
);
// --FIXME esta funcion procesa el frame obtenido retornando la estructura de blobs
iVisionModule_printBlobs
(
result
);
printf
(
"
\n\n\n
SALIO
\n\n
"
);
return
result
;
}
/**
* Inicializa las estructuras que utiliza la interfaz.
*/
int
iVisionModule_initialize
(
int
ID
,
int
rate
)
{
//Inicializamos la conexión y creacion de estructuras para manejar la webcam
return
utilBlobs_initialize
();
}
/**
* Elimina las estructuras utilizadas por el modulo.
*/
int
iVisionModule_terminate
()
{
//terminar conexion
utilBlobs_terminate
();
// --FIXME aca va la llamada a terminar la conexion con la camara y liberacion de estructuras
return
1
;
}
/**
* Imprime un blob en consola.
* blob: blob a imprimr
*/
void
mostrarBlob
(
struct
blob
b
)
{
printf
(
"region_index: %u
\n
"
,
b
.
region_index
);
printf
(
"region_color: %u
\n
"
,
b
.
region_color
);
printf
(
"number_of_pixels: %u
\n
"
,
b
.
number_of_pixels
);
printf
(
"sum_of_x_coord: %4u%4u
\n
"
,
b
.
sum_of_x_coord_high
,
b
.
sum_of_x_coord_low
);
printf
(
"sum_of_y_coord: %4u%4u
\n
"
,
b
.
sum_of_y_coord_high
,
b
.
sum_of_y_coord_low
);
printf
(
"max_x: %u
\n
"
,
b
.
max_x
);
printf
(
"min_x: %u
\n
"
,
b
.
min_x
);
printf
(
"max_y: %u
\n
"
,
b
.
max_y
);
printf
(
"min_y: %u
\n
"
,
b
.
min_y
);
}
/**
* Imprime un conjunto de blobs en consola.
* blobs: array de blobs a imprimr
*/
void
iVisionModule_printBlobs
(
struct
blob
*
blobs
)
{
printf
(
"
\n\n\n
BLOBS DESCUBIERTOS
\n\n
"
);
if
(
blobs
!=
NULL
)
{
int
i
;
for
(
i
=
0
;
i
<
CANT_REGIONS
;
i
++
)
{
printf
(
"blobs[%d]:
\n
"
,
i
);
mostrarBlob
(
blobs
[
i
]);
printf
(
"-----------
\n
"
);
}
}
else
{
printf
(
"blobs es NULL
\n
"
);
}
}
visrob2/example/ejCAMVISCONF/main.c
0 → 100644
View file @
2779edd3
/*############################################################
# #
# Proyecto Futbol de Robots. - PAIE 2014 #
# http://www.fing.edu.uy/inco/proyectos/futbot13/ #
# #
############################################################*/
#include "vision.h"
#include <stdio.h>
int
main
()
{
if
(
!
vision_initialize
(
DEFAULT_HAVIMO_ID
,
DEFAULT_BAUDNUM
,
MAGENTA_COLOR
))
return
-
1
;
if
(
vision_checkVision
(
0
))
{
unsigned
short
int
i
;
char
buffer
[
33
];
for
(
i
=
0
;
i
<
obj_size
;
i
++
)
{
printf
(
"::"
);
printf
(
"%hu"
,
objects
[
i
].
type
);
printf
(
" "
);
printf
(
"%d"
,
objects
[
i
].
x
);
printf
(
" "
);
printf
(
"%u"
,
objects
[
i
].
y
);
printf
(
" "
);
printf
(
"%u"
,
objects
[
i
].
z
);
printf
(
" "
);
printf
(
"%hu"
,
objects
[
i
].
likeness_level
);
printf
(
"
\n
"
);
}
}
printf
(
"---
\n
"
);
<