Commit 276230ac authored by Nicolas Furquez's avatar Nicolas Furquez
Browse files

configuracion + vision

parent 2779edd3
......@@ -15,6 +15,15 @@ set_property(TARGET libICamera PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE
add_library(libvision STATIC IMPORTED)
set_property(TARGET libvision PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/libvision.a)
add_library(libConfiguracion STATIC IMPORTED)
set_property(TARGET libConfiguracion PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../../lib/libConfiguracion.a)
add_library(libconfuse STATIC IMPORTED)
set_property(TARGET libconfuse PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../../libinclude/libconfuse.a)
set_source_files_properties(main.c PROPERTIES LANGUAGE CXX )
......@@ -22,6 +31,6 @@ add_executable(integrationTest main.c)
SET_TARGET_PROPERTIES(integrationTest PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(integrationTest libvision libICamera ${LIBS} -lm)
target_link_libraries(integrationTest libvision libICamera libConfiguracion libconfuse ${LIBS} -lm)
INSTALL(TARGETS integrationTest DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})
\ No newline at end of file
# 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}
}
......@@ -6,13 +6,33 @@
############################################################*/
#include "vision.h"
#include <stdio.h>
#include <stdio.h>
int main() {
if (!vision_initialize(DEFAULT_HAVIMO_ID, DEFAULT_BAUDNUM, CYAN_COLOR))
if (!vision_initialize(DEFAULT_HAVIMO_ID, DEFAULT_BAUDNUM, MAGENTA_COLOR))
return -1;
vision_checkVision(0);
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");
vision_terminate();
printf("FINAL FELIZ...\n");
printf("THE END!\n");
return 0;
}
/*############################################################
# #
# 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, CYAN_COLOR))
return -1;
vision_checkVision(0);
vision_terminate();
printf("FINAL FELIZ...\n");
return 0;
}
#ifndef I_CONFIG
#define I_CONFIG
#include "confuse.h"
cfg_t *initCfg(const char* fileConf);
#endif
\ No newline at end of file
/*############################################################
# #
# 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
parados en visrob:
mkdir buid
cd buid/
Segun corresponda
cmake -DCAMARA=hab -DCMAKE_CXX_COMPILER=g++ ..
o
cmake -DCAMARA=web -DCMAKE_CXX_COMPILER=g++ ..
make
si todo bien
make install
cd ..
esto copia a lib/ las librerias creadas
para los ejemplos:
ir al ejemplo
mkdir buid
cd buid/
cmake -DCMAKE_CXX_COMPILER=g++ ..
make
si todo bien
make install
cd ..
junto a los fuentes tenemos el binario
Se generaron los compiladores para otros modulos dentro de src/ (por ejemplo DynamixelCustom) si se quiere hacer compilar, luego de modificar el cmakelist.txt descomentar la linea correspondiente en el cmakelist de la carpeta raiz del proyecto.
\ No newline at end of file
......@@ -4,10 +4,14 @@ PROJECT(libConfiguracion)
INCLUDE_DIRECTORIES(../../include)
ADD_LIBRARY(Configuracion STATIC Config.c)
ADD_LIBRARY(Configuracion STATIC config.c)
SET_PROPERTY(TARGET Configuracion PROPERTY SOVERSION 1.0)
set_source_files_properties(config.c PROPERTIES LANGUAGE CXX )
INSTALL(TARGETS Configuracion DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../../lib)
install(FILES Config.h DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
#install(FILES Config.h DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
# TO DO >>> agregar la instalacion de confuse: ./configure y make en confuse-2.7 y copia de confuse-2.7/src/.libs/libconfuse.a to visrob2/libinclude
#include <string.h>
#include <stdlib.h>
#include "confuse.h"
#include "Config.h"
#include <errno.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("object", objects_op, CFGF_TITLE | CFGF_MULTI), //detailed objects params
// flags
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;
}
#ifndef I_CONFIG
#define I_CONFIG
#include "confuse.h"
cfg_t *initCfg(const char* fileConf);
#endif
\ No newline at end of file
/*############################################################
# #
# 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;
}
......@@ -29,8 +29,8 @@ 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
* 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 &&
......@@ -51,7 +51,7 @@ unsigned int blob_equals(struct blob b1, struct blob b2) {
* 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) { // --FIXME ningun parametro necesario
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
......@@ -70,10 +70,9 @@ struct blob * iVisionModule_getNextFrame(int ID) { // --FIXME ningun parametro n
/**
* Inicializa las estructuras que utiliza la interfaz.
*/
int iVisionModule_initialize(int ID, int rate) { // --FIXME ver parametros si se necesita alguno
//Inicializamos la conexión
return utilBlobs_initialize(); // --FIXME aca va la llamada a iniciar la conexion con la camara y demas estructuras como cargar
// del conf las variables retorna 1 si todo OK - 0 si hubo algun problema con la conexion de camara
int iVisionModule_initialize(int ID, int rate) {
//Inicializamos la conexión y creacion de estructuras para manejar la webcam
return utilBlobs_initialize();
}
/**
......
......@@ -18,30 +18,60 @@ using namespace cv;
#include <cvblob.h>
using namespace cvb;
#define WIDTH 640
#define HEIGHT 480
#define FPS 5
#define CANT_CALIBRACIONES 1
#include <string.h>
#include <errno.h>
#include "config.h"
#include "confuse.h"
#define WIDTH 0 //--FIXME
#define HEIGHT 0 //--FIXME
#define FPS 0 //--FIXME
CvCapture *capture;
IplImage *img;
CvSize imgSize;
IplImage *frame;
int frameNumber;
// AMARILLO - AZUL - NARANJA - MAGENTA -cam web --FIXME levantar del .conf
//cv::Scalar calibsMIN [] = {cv::Scalar(19,208,80),cv::Scalar(43,26,40),cv::Scalar(6,160,75),cv::Scalar(167,110,44)};
//cv::Scalar calibsMAX [] = {cv::Scalar(24,249,125),cv::Scalar(113,132,58),cv::Scalar(15,226,184),cv::Scalar(179,187,102)};
char imagen [] = "imgs/imagen01101.jpg";
// AMARILLO - AZUL - NARANJA - MAGENTA -cam CSI
cv::Scalar calibsMIN [] = {cv::Scalar(9,156,44),cv::Scalar(121,83,46),cv::Scalar(13,229,75),cv::Scalar(-4,172,42)};
cv::Scalar calibsMAX [] = {cv::Scalar(17,245,124),cv::Scalar(121,83,46),cv::Scalar(13,229,75),cv::Scalar(-4,172,42)};
//cv::Scalar calibsMIN [] = {cv::Scalar(21, 208, 82),cv::Scalar(107, 58, 44),cv::Scalar(11, 207, 81),cv::Scalar(-24, 41, 24),cv::Scalar(0, 0, 19)};
//cv::Scalar calibsMAX [] = {cv::Scalar(24, 253, 145),cv::Scalar(118, 142, 55),cv::Scalar(19, 255, 202),cv::Scalar(6, 215, 115),cv::Scalar(0, 0, 22)};
int CANT_CALIBRACIONES = 0;
cv::Scalar *calibsMIN;
cv::Scalar *calibsMAX;
/**
* Inicializa las estructuras que utiliza. Carga archivo de configuracion
* Carga el archivo de configuracion.
*/
int getConfiguration(){
cfg_t *conf = initCfg("futbotVision.conf");
if (!conf) return -1;
CANT_CALIBRACIONES = cfg_size(conf, "region");
calibsMAX = (cv::Scalar*) malloc(sizeof(cv::Scalar)*CANT_CALIBRACIONES);
calibsMIN = (cv::Scalar*) malloc(sizeof(cv::Scalar)*CANT_CALIBRACIONES);
printf("REGIONES A CALIBRAR %d\n", CANT_CALIBRACIONES);
for(int i = 0; i < CANT_CALIBRACIONES; i++) {
cfg_t *cfg_obj = cfg_getnsec(conf, "region", i);
printf("REGION id: %d\n",cfg_getint(cfg_obj,"id"));
printf("REGION name: %s\n", cfg_title(cfg_obj));
printf("HSI max : {%d,%d,%d}\n",cfg_getnint(cfg_obj, "hsiMax", 0),cfg_getnint(cfg_obj, "hsiMax", 1),cfg_getnint(cfg_obj, "hsiMax", 2));
printf("HSI min : {%d,%d,%d}\n",cfg_getnint(cfg_obj, "hsiMin", 0),cfg_getnint(cfg_obj, "hsiMin", 1),cfg_getnint(cfg_obj, "hsiMin", 2));
}
}
/**
* Inicializa las estructuras que utiliza.
*/
int utilBlobs_initialize(){
if (!(capture = cvCaptureFromCAM(0))){
getConfiguration();
/*if (!(capture = cvCaptureFromCAM(0))){
fprintf(stderr, "== ERROR 0 - revisar conexion a camara.\n");
return 0;
}
......@@ -55,8 +85,8 @@ int utilBlobs_initialize(){
return 0;
}
img = cvRetrieveFrame(capture);
//img = cvLoadImage("segmentada.png",1);
*/
img = cvLoadImage(imagen,1);
imgSize = cvGetSize(img);
frame = cvCreateImage(imgSize, img->depth, img->nChannels);
frameNumber = 0;
......@@ -69,19 +99,20 @@ int utilBlobs_initialize(){
*/
void utilBlobs_terminate(){
cvReleaseImage(&frame);
cvReleaseCapture(&capture);
// cvReleaseCapture(&capture);
}
/**
* Obtiene un nuevo frame de la camara conectada, retorna -1 si hay algún problema con la lectura desde la camara
*/
int utilBlobs_getFrame(){
if (!cvGrabFrame(capture)) {
/* if (!cvGrabFrame(capture)) {
fprintf(stderr,"== ERROR 1 - revisar conexion a camara. Posible desconexion.\n");
return 0;
}
img = cvRetrieveFrame(capture);
//img = cvLoadImage("segmentada.png",1);
*/
img = cvLoadImage(imagen,1);
cvConvertScale(img, frame, 1, 0);
return 1;
}
......@@ -94,7 +125,8 @@ void getOneColorBlobs (const IplImage *hsvImage, IplImage * labelImg, CvBlobs &b
cvInRangeS(hsvImage, min, max, segmentated);
if (min.val[0] < 0) {
min.val[0] = 180 - min.val[0];
printf("HUE NEAR ZERO\n");
min.val[0] = 180 + min.val[0];
max.val[0] = 180;
IplImage *segmentated2 = cvCreateImage(imgSize, 8, 1);
cvInRangeS(hsvImage, min, max, segmentated2);
......@@ -132,27 +164,18 @@ struct blob fillZeros(){
res.min_x = (unsigned int) 0;
res.max_y = (unsigned int) 0;
res.min_y = (unsigned int) 0;
/*
printf("===== START DEBUG =====\n");
printf("reg_idx: %u\n", res.region_index);
printf("reg_col: %u\n", res.region_color);
printf("nro_pix: %u\n", res.number_of_pixels);
printf("suma__x: %u%u\n", res.sum_of_x_coord_high, res.sum_of_x_coord_low);
printf("suma__y: %u%u\n", res.sum_of_y_coord_high, res.sum_of_y_coord_low);
printf("maxim_x: %u\n", res.max_x);
printf("minim_x: %u\n", res.min_x);
printf("maxim_y: %u\n", res.max_y);
printf("minim_y: %u\n", res.min_y);
printf("===== FIN DEBUG =====\n");
*/
return res;
}
struct blob infoToBlob(CvBlob info, unsigned int region_idx){
struct blob infoToBlob(CvBlob info, unsigned int region_idx, unsigned int region_color){
struct blob res;
if (region_color == 5) region_color = 1;
else if (region_color == 6) region_color = 7;
else if (region_color == 7) region_color = 5;
res.region_index = region_idx+1;
res.region_color = BALL_REGION;
res.region_color = region_color;
res.number_of_pixels = info.area;
res.sum_of_x_coord_high = 0;
......@@ -165,7 +188,7 @@ struct blob infoToBlob(CvBlob info, unsigned int region_idx){
res.min_x = info.minx;
res.max_y = info.maxy;
res.min_y = info.miny;
/*
printf("===== START DEBUG =====\n");
printf("reg_idx: %u\n", res.region_index);
printf("reg_col: %u\n", res.region_color);
......@@ -177,7 +200,7 @@ struct blob infoToBlob(CvBlob info, unsigned int region_idx){
printf("maxim_y: %u\n", res.max_y);
printf("minim_y: %u\n", res.min_y);
printf("===== FIN DEBUG =====\n");
*/
return res;
}
......@@ -214,29 +237,40 @@ void utilBlobs_getBlobs(struct blob* result){
IplImage *hsv = cvCreateImage(imgSize, 8, 3);
cvCvtColor(frame,hsv,CV_BGR2HSV);
int indice=0;
CvBlobs blobsitos;
for (int i=0; i < CANT_CALIBRACIONES; i++){
if (indice < CANT_REGIONS){
IplImage *labelImg = cvCreateImage(cvGetSize(frame), IPL_DEPTH_LABEL, 1);
getOneColorBlobs(hsv, labelImg, blobsitos, imgSize, calibsMIN[0], calibsMAX[0]);
getOneColorBlobs(hsv, labelImg, blobsitos, imgSize, calibsMIN[i], calibsMAX[i]);
cvRenderBlobs(labelImg, blobsitos, frame, frame, CV_BLOB_RENDER_BOUNDING_BOX);
std::stringstream filename;
filename << "debugBLOB_" << std::setw(5) << std::setfill('0') << indice << ".png";
cvSaveImage(filename.str().c_str(),frame);
CvBlobs::const_iterator it = blobsitos.begin();
unsigned int indice;
for(indice = 0; indice < CANT_REGIONS; indice++) {
//for(indice = 0; indice < CANT_REGIONS; indice++) {
CvBlob* bloby;
if (it!=blobsitos.end()){
while (it!=blobsitos.end() && indice < CANT_REGIONS){
bloby = (*it).second;
result [indice] = infoToBlob(*bloby, indice);
result [indice++] = infoToBlob(*bloby, indice, i+3);
// std::stringstream filename;
// filename << "debugBLOB_" << std::setw(5) << std::setfill('0') << indice << ".png";
// cvSaveImageBlob(filename.str().c_str(), frame, it->second);
it++;
} else {
} /*else {
result [indice] = fillZeros();
}
}
}*/
//}
//saveBlobs(frameNumber++, blobsitos);
cvReleaseImage(&labelImg);
cvReleaseBlobs(blobsitos);
}
}
cvReleaseImage(&hsv);
while(indice < CANT_REGIONS) result [indice++] = fillZeros();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment