Commit 4ea32bcf authored by Aylen Ricca's avatar Aylen Ricca
Browse files

some debug and test from static imgs - BUG: casting int to double div in ballRoundness

parent f0bfc9d3
......@@ -26,10 +26,13 @@
#define CYAN_REGION 6
#define MAGENTA_REGION 7
#define CANT_REGIONS 15
//#define CANT_REGIONS 15
#define CANT_REGIONS 40 //FIXME
#define IMAGE_WIDTH 160 //px
#define IMAGE_HEIGHT 120 //px
//#define IMAGE_WIDTH 160 //px
//#define IMAGE_HEIGHT 120 //px
#define IMAGE_WIDTH 640 //px
#define IMAGE_HEIGHT 480 //px
#define DISTANCIA_FOCAL_HAVIMO 164//d(cm) * ancho(px) / ancho(cm)
#define DFH_FOR_PROPORTION 179
......
......@@ -6,8 +6,6 @@
############################################################*/
#include "vision.h"
#include "config.h"
#include "confuse.h"
#include <stdio.h>
int main() {
......
......@@ -561,11 +561,14 @@ unsigned short int vision_objRec_detectRivals(void) {
*/
double getBlobRoundness(struct blob b) {
unsigned short int aux_width = b.max_x - b.min_x;
unsigned short int aux_height = b.max_y - b.min_y;
if(aux_width > aux_height) {
return aux_height / aux_width;
} else {
return aux_width / aux_height;
unsigned short int aux_height = b.max_y - b.min_y;
printf ("......... ROUNDNESS :: %d - %d\n", aux_width, aux_height);
if(aux_width > aux_height) {
printf ("......... ROUNDNESS = %f\n", ((double)aux_height/(double)aux_width));
return (double)aux_height / (double)aux_width;
} else {
printf ("......... ROUNDNESS = %f\n", ((double)aux_width/(double)aux_height));
return (double)aux_width/(double)aux_height;
}
}
......@@ -592,19 +595,24 @@ unsigned short int vision_objRec_detectBall(void) {
//Obtenemos la mejor pelota
for(i = 0; i < CANT_REGIONS; i++) {
if(blobs[i].region_index != INVALID_REGION && blobs[i].region_color == BALL_REGION) {
if(blobs[i].region_index != INVALID_REGION && blobs[i].region_color == BALL_REGION) {
printf("...posible pelota...\n");
if(blobs[i].max_y >= BOTTOM_MARGEN_PROXIMITY) {
aux_ball_roundness = 1;
aux_ball_roundness = 1;
printf("......roundness(=1) = %f...\n",aux_ball_roundness);
} else {
aux_ball_roundness = getBlobRoundness(blobs[i]);
if(aux_ball_roundness < MIN_BALL_ROUNDNESS)
continue;
printf("......roundness = %f...\n",aux_ball_roundness);
if(aux_ball_roundness < MIN_BALL_ROUNDNESS){
printf("......roundness menor a MIN (=%f)...\n",aux_ball_roundness);
continue;
}
}
//Encontre una pelota
if(blob_ball == NULL) {
if(blob_ball == NULL) {
printf("..... first ball\n");
//Es la primera region que parece una bola
blob_ball = &blobs[i];
......@@ -618,7 +626,8 @@ unsigned short int vision_objRec_detectBall(void) {
}
} else {
printf(".....another ball\n");
//Ya hay un objeto identificado como la bola. Me quedo con el mas grande y cuadrado.
int blob_w = blobs[i].max_x - blobs[i].min_x;
int blob_h = blobs[i].max_y - blobs[i].min_y;
......
......@@ -18,28 +18,30 @@ using namespace cv;
#include <cvblob.h>
using namespace cvb;
#include <string.h>
#include <errno.h>
#include "config.h"
#include "confuse.h"
#define WIDTH 0 //--FIXME
#define HEIGHT 0 //--FIXME
#define FPS 0 //--FIXME
#define WIDTH 320
#define HEIGHT 240
#define FPS 5
#define CANT_CALIBRACIONES 7
static const char filename[] = "futbotVision.conf";
static const char imagen [] = "imgs/imagen00000.jpg";
//static const char imagen [] = "imgs/imagen10000.jpg"; // determinar cual es la pelota
//static const char imagen [] = "imgs/imagen10001.jpg"; // determinar cual es la pelota
//static const char imagen [] = "imgs/imagen10010.jpg"; // determinar cual es la pelota y por que ve 2 aliados
//static const char imagen [] = "imgs/imagen10011.jpg"; // determinar cual es la pelota y por que ve 2 aliados
//static const char imagen [] = "imgs/imagen10100.jpg"; // ver xq ve opp y my goal y un solo landmark
//static const char imagen [] = "imgs/imagen10101.jpg"; // ver xq ve my goal y opp lat post y un solo landmark
//static const char imagen [] = "imgs/imagen10110.jpg"; // ver xq ve my goal con alto likeness
//static const char imagen [] = "imgs/imagen10111.jpg"; // ver xq ve my goal con alto likeness
//static const char imagen [] = "imgs/imagen11000.jpg"; // ver el tema de robot proximo
CvCapture *capture;
IplImage *img;
CvSize imgSize;
IplImage *frame;
int frameNumber;
char imagen [] = "imgs/imagen01101.jpg";
// AMARILLO - AZUL - NARANJA - MAGENTA -cam CSI
//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;
/* BALL - FIELD - MY GOAL - OPP GOAL - ROBOT BODY - CYAN - MAGENTA */
cv::Scalar *calibsMIN;
cv::Scalar *calibsMAX;
......@@ -47,24 +49,58 @@ cv::Scalar *calibsMAX;
* Carga el archivo de configuracion.
*/
int getConfiguration(){
cfg_t *conf = initCfg("futbotVision.conf");
if (!conf) return -1;
FILE *file = fopen(filename, "r");
int a, b, c;
int cont = 0, pos = 0;
char line [128];
cv::Scalar s;
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);
calibsMAX = (cv::Scalar*) malloc(sizeof(cv::Scalar)*CANT_CALIBRACIONES);
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));
if (file != NULL)
{
while (fgets(line, sizeof line, file) != NULL) /* read a line */
{
if ((line[0] != '\n') && (line[0] != '#') && (line[0] != '{') && (line[0] != '}'))
{
sscanf(line, " %[^\n]", line); /* skip white spaces at the beginning*/
switch (cont%4)
{
case 2: /* min HSI */
sscanf(line, "hsiMin={%d,%d,%d}\n", &a, &b, &c);
calibsMIN[pos] = cv::Scalar(a, b, c);
break;
case 3: /* max HSI */
sscanf(line, "hsiMax={%d,%d,%d}\n", &a, &b, &c);
calibsMAX[pos] = cv::Scalar(a, b, c);
pos++;
break;
default: /* discard */
break;
}
cont++;
}
}
fclose (file);
}
else
{
perror(filename); /* error openning the file*/
return -1;
}
}
// printf("----------------------\n");
// for (int i=0; i<CANT_CALIBRACIONES; i++) {
// printf("HSI min : {%f,%f,%f}\n",calibsMIN[i].val[0],calibsMIN[i].val[1],calibsMIN[i].val[2]);
// }
// printf("----------------------\n");
// for (int i=0; i<CANT_CALIBRACIONES; i++) {
// printf("HSI max : {%f,%f,%f}\n",calibsMAX[i].val[0],calibsMAX[i].val[1],calibsMAX[i].val[2]);
// }
return 0;
}
/**
* Inicializa las estructuras que utiliza.
......@@ -125,7 +161,6 @@ void getOneColorBlobs (const IplImage *hsvImage, IplImage * labelImg, CvBlobs &b
cvInRangeS(hsvImage, min, max, segmentated);
if (min.val[0] < 0) {
printf("HUE NEAR ZERO\n");
min.val[0] = 180 + min.val[0];
max.val[0] = 180;
IplImage *segmentated2 = cvCreateImage(imgSize, 8, 1);
......@@ -170,11 +205,8 @@ struct blob fillZeros(){
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_index = region_idx;
res.region_color = region_color;
res.number_of_pixels = info.area;
......@@ -189,17 +221,17 @@ else if (region_color == 7) region_color = 5;
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);
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");
// 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;
}
......@@ -239,37 +271,24 @@ void utilBlobs_getBlobs(struct blob* result){
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[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();
//for(indice = 0; indice < CANT_REGIONS; indice++) {
for (int i=0; i < CANT_CALIBRACIONES && indice < CANT_REGIONS; i++){
IplImage *labelImg = cvCreateImage(cvGetSize(frame), IPL_DEPTH_LABEL, 1);
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();
CvBlob* bloby;
while (it!=blobsitos.end() && indice < CANT_REGIONS){
bloby = (*it).second;
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);
result [indice++] = infoToBlob(*bloby, indice+1, i+1);
it++;
} /*else {
result [indice] = fillZeros();
}*/
//}
//saveBlobs(frameNumber++, blobsitos);
cvReleaseImage(&labelImg);
cvReleaseBlobs(blobsitos);
}
}
cvReleaseImage(&labelImg);
cvReleaseBlobs(blobsitos);
}
cvReleaseImage(&hsv);
while(indice < CANT_REGIONS) result [indice++] = fillZeros();
......
......@@ -8,9 +8,6 @@
#ifndef I_UTILSBLOBS
#define I_UTILSBLOBS
#include "config.h"
#include "confuse.h"
/**
* Inicializa las estructuras que utiliza. Carga archivo de configuracion
*/
......
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