src/test/circle_detection.c
void circleDectection_staticadapt(SDL_Surface *img, int *resx, int *resy)
{
    //new matrix to fill the vote count.
    Matrix *matrix = new_matrix(img->w, img->h);

    Uint8 r,g,b;

    int R = img->h /4; //this is the radius of an average face in pixel, might need to change this
    // The width is always 752 same for the height 480
    int counterx, countery;
    Uint32 pix;
    for (int i = R+3; i < img->w -R -3; i++)
    {
        for (int j = R+3; j < img->h -R -3; j++)
        {
            pix = get_pixel(img, i, j); //from pixel.c //to be able to easily manipulate pixels
            SDL_GetRGB(pix,img->format, &r ,&g, &b);
            if (r == 255 ) //if it is white // face edge pixel (it is in binary since BW)
            {

                if ((counterx >= i+R-R/10||counterx <= i-R + R/10) || \
                        (countery >= j+R -R/10|| countery <= j-R + R/10))
                {
                    counterx =i;
                    countery = j;
                    //we draw the circle, taking the center the pixel we found
                    //theta is the 360 circle, though we might need to skip
                    //with cos and sin some theta values
                    for (size_t theta = 0; theta < 360; theta+=2)
                    {
                        int y = i + R*cos(theta); //cos takes double, check for this
                        int x = j + R*sin(theta); //sin takes double as well
                        matrix->data[x][y] +=1;
                    }
                }
            }
        }
    }
    //we now have the matrix with the votes. the greatest number is most likely the center
    //if more have the same value, FOR NOW we take the first we find
    int votes =0;
    for (int v = 0; v < matrix->cols; v++)
    {
        for (int b = 0; b < matrix->rows; b++)
        {
            //to make votes change position with equal votes in m->data, add <=
            if (votes < matrix->data[b][v])
            {
                votes = matrix->data[b][v];
                *resx = v;
                *resy = b;
            }

        }

    }
}
//static adapt makes the Radius of the circle into image width/4
//CircleDetection Static Adapt
static adapt makes the Radius of the circle into image width/4
CircleDetection Static Adapt
static adapt makes the Radius of the circle into image width / 4 CircleDetection Static Adapt
void circleDectection_staticadapt(SDL_Surface *img, int *resx, int *resy)
{
    Matrix *matrix = new_matrix(img->w, img->h);
    Uint8 r,g,b;
    int R = img->h /4; 
    int counterx, countery;
    Uint32 pix;
    for (int i = R+3; i < img->w -R -3; i++)
    {
        for (int j = R+3; j < img->h -R -3; j++)
        {
            pix = get_pixel(img, i, j); 
            SDL_GetRGB(pix,img->format, &r ,&g, &b);
            if (r == 255 ) 
            {
                if ((counterx >= i+R-R/10||counterx <= i-R + R/10) || \
                        (countery >= j+R -R/10|| countery <= j-R + R/10))
                {
                    counterx =i;
                    countery = j;
                    for (size_t theta = 0; theta < 360; theta+=2)
                    {
                        int y = i + R*cos(theta); 
                        int x = j + R*sin(theta); 
                        matrix->data[x][y] +=1;
                    }
                }
            }
        }
    }
    int votes =0;
    for (int v = 0; v < matrix->cols; v++)
    {
        for (int b = 0; b < matrix->rows; b++)
        {
            if (votes < matrix->data[b][v])
            {
                votes = matrix->data[b][v];
                *resx = v;
                *resy = b;
            }
        }
    }
}
void circleDectection_staticadapt ( SDL_Surface * img , int * resx , int * resy ) { Matrix * matrix = new_matrix ( img -> w , img -> h ) ; Uint8 r , g , b ; int R = img -> h / 4 ; int counterx , countery ; Uint32 pix ; for ( int i = R + 3 ; i < img -> w - R - 3 ; i ++ ) { for ( int j = R + 3 ; j < img -> h - R - 3 ; j ++ ) { pix = get_pixel ( img , i , j ) ; SDL_GetRGB ( pix , img -> format , & r , & g , & b ) ; if ( r == 255 ) { if ( ( counterx >= i + R - R / 10 || counterx <= i - R + R / 10 ) || ( countery >= j + R - R / 10 || countery <= j - R + R / 10 ) ) { counterx = i ; countery = j ; for ( size_t theta = 0 ; theta < 360 ; theta += 2 ) { int y = i + R * cos ( theta ) ; int x = j + R * sin ( theta ) ; matrix -> data [ x ] [ y ] += 1 ; } } } } } int votes = 0 ; for ( int v = 0 ; v < matrix -> cols ; v ++ ) { for ( int b = 0 ; b < matrix -> rows ; b ++ ) { if ( votes < matrix -> data [ b ] [ v ] ) { votes = matrix -> data [ b ] [ v ] ; * resx = v ; * resy = b ; } } } }
static adapt makes the Radius of the circle into image width/4
CircleDetection Static Adapt
static adapt makes the Radius of the circle into image width / 4 CircleDetection Static Adapt
//new matrix to fill the vote count. //this is the radius of an average face in pixel, might need to change this // The width is always 752 same for the height 480 //from pixel.c //to be able to easily manipulate pixels //if it is white // face edge pixel (it is in binary since BW) //we draw the circle, taking the center the pixel we found //theta is the 360 circle, though we might need to skip //with cos and sin some theta values //cos takes double, check for this //sin takes double as well //we now have the matrix with the votes. the greatest number is most likely the center //if more have the same value, FOR NOW we take the first we find //to make votes change position with equal votes in m->data, add <=