Commit f0bfc9d3 authored by Aylen Ricca's avatar Aylen Ricca
Browse files

probando cosas

parent f8d6d071
......@@ -6,13 +6,35 @@
############################################################*/
#include "vision.h"
#include <stdio.h>
#include "config.h"
#include "confuse.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;
}
......@@ -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();
}
......@@ -8,6 +8,9 @@
#ifndef I_UTILSBLOBS
#define I_UTILSBLOBS
#include "config.h"
#include "confuse.h"
/**
* Inicializa las estructuras que utiliza. Carga archivo de configuracion
*/
......
......@@ -57,17 +57,20 @@ void processBlobs(void) {
//Identificamos la bola
unsigned short int hayPelota = vision_objRec_detectBall();
printf("PELOTA = %d\n");
printf("PELOTA = %hu\n",hayPelota);
//Identificamos los agentes
vision_objRec_detectAllies();
vision_objRec_detectRivals();
unsigned short int cant_allies = vision_objRec_detectAllies();
printf("ALLIES = %hu\n",cant_allies);
unsigned short int cant_rivals = vision_objRec_detectRivals();
printf("RIVALS = %hu\n",cant_rivals);
//Identificamos los landmarks
struct vision_obj* right_landmark = vision_objRec_getDetectedRightLandmark();
struct vision_obj* left_landmark = vision_objRec_getDetectedLeftLandmark();
if(right_landmark != NULL) {
printf("RIGHT LANDMARK\n");
//Los landmarks son de interes para la estrategia. Copio los datos del landmark a objects.
objects[obj_size].type = RIGHT_LANDMARK;
objects[obj_size].x = right_landmark->x;
......@@ -78,6 +81,7 @@ void processBlobs(void) {
}
if(left_landmark != NULL) {
printf("LEFT LANDMARK\n");
//Los landmarks son de interes para la estrategia. Copio los datos del landmark a objects.
objects[obj_size].type = LEFT_LANDMARK;
objects[obj_size].x = left_landmark->x;
......@@ -90,6 +94,7 @@ void processBlobs(void) {
struct vision_obj* my_goal = vision_objRec_getDetectedMyGoal();
if(my_goal != NULL) {
printf("MY GOAL\n");
//El arco es de interez para la estrategia. Copio los datos del arco a objects.
objects[obj_size].type = MY_GOAL;
objects[obj_size].x = my_goal->x;
......@@ -102,6 +107,7 @@ void processBlobs(void) {
struct vision_obj* opp_goal = vision_objRec_getDetectedOppGoal();
if(opp_goal != NULL) {
printf("OPP GOAL\n");
//El arco es de interez para la estrategia. Copio los datos del arco a objects.
objects[obj_size].type = OPP_GOAL;
objects[obj_size].x = opp_goal->x;
......
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