void ScaledDetector::detectIntersectionInCurrentScale()
{
	int l,c;
	int rownum = currentSkeleton.rows;
	int colnum = currentSkeleton.cols;
	float intersectionV;
	cv::Mat_<uchar> intersectionArea = cv::Mat::zeros(rownum, colnum, CV_8U);

	ImgPatch patchInProcess;

	for (l = halfPatchSize ; l < rownum - halfPatchSize ; ++l)
	{
		for (c = halfPatchSize ; c < colnum - halfPatchSize ; ++c)
	    {
			if (currentSkeleton[l][c] != 0)
			{
				patchInProcess.setPatch(currentSkeleton(cv::Rect(c-halfPatchSize, l-halfPatchSize, halfPatchSize*2+1, halfPatchSize*2+1)));
				intersectionV = patchInProcess.intersectionValue();
				if (intersectionV > 1)
				{
					reponseMap[l][c] += intersectionV;
					intersectionArea(cv::Rect(c-1,l-1,3,3)).setTo(255);
				}
			}
	    }
	}

//	imshow("before", currentSkeleton);
	currentSkeleton = currentSkeleton - intersectionArea;
//	imshow("after", currentSkeleton);
//	cv::waitKey(-1);
}
Ejemplo n.º 2
0
static Area
getIntersectionArea(Area a, Area b)
{ Area c;

  c = answerObject(ClassArea, a->x, a->y, a->w, a->h, EAV);
  if ( intersectionArea(c, b) )
    answer(c);

  freeObject(c);
  fail;
}
Ejemplo n.º 3
0
Filter* getFilter(int (*transform)(void*, Point*, Point*), void *params, int dim_x, int dim_y,
                  Point pt0) {
    Filter *tg;
    Point *t_grid; //transformed grid
    Poly *cell_poly, *poly;
    Vertex *v;
    char *is_transformed;
    int dim;
    float min_x, max_x, min_y, max_y;
    float area;
    int i, j, k;
    int ii, jj;
    int index;
    int last, allocated;

    if(params==NULL)
        return NULL;
    tg=(Filter*)calloc(1, sizeof(Filter));
    tg->dim_x=dim_x;
    tg->dim_y=dim_y;
    tg->x0=pt0.x;
    tg->y0=pt0.y;
    tg->dx=tg->dy=1;
    dim=tg->dim_x*tg->dim_y;
    tg->num_pts=(int*)calloc(dim, sizeof(int));
    tg->pts=(Point**)calloc(dim, sizeof(Point*));
    tg->coefs=(float**)calloc(dim, sizeof(float*));

    // compute the transformed grid (used to get the polygons corresponding to the cells.
    t_grid=(Point*)calloc((tg->dim_x+1)*(tg->dim_y+1), sizeof(Point));
    is_transformed=(char*)calloc((tg->dim_x+1)*(tg->dim_y+1), sizeof(char));
    for(k=0, j=0; j<=tg->dim_y; j++) {
        for(i=0; i<=tg->dim_x; i++, k++) {
            t_grid[k].x=tg->x0+i*tg->dx-tg->dx/2;
            t_grid[k].y=tg->y0+j*tg->dy-tg->dy/2;
            is_transformed[k]=(char)transform(params, t_grid+k, t_grid+k);
            if(is_transformed[k]==-1)
                return NULL; //should never happen!
        }
    }

    //for each cell, get the corresponding polygon, transform it, get all the overlapping cells,
    //(number of overlaping cells=numPoints[k]) and compute percentage of area inside each of these
    // cells
    cell_poly=generatePoly(4);
    cell_poly->verts[0].x=0;
    cell_poly->verts[0].y=1;
    cell_poly->verts[1].x=1;
    cell_poly->verts[1].y=1;
    cell_poly->verts[2].x=1;
    cell_poly->verts[2].y=0;
    cell_poly->verts[3].x=0;
    cell_poly->verts[3].y=0;
    setSides(cell_poly); // verts won't be used from now on, just normals and dists. only update dists
    for(index=0, k=0, j=0; j<tg->dim_y; j++, index++) {
        for(i=0; i<tg->dim_x; i++, k++, index++) {
            if(!(is_transformed[index] &&
                    is_transformed[index+1] &&
                    is_transformed[index+tg->dim_x+1] &&
                    is_transformed[index+tg->dim_x+2]))
                continue;
            if(!is_transformed[index] ||
                    !is_transformed[index+1] ||
                    !is_transformed[index+tg->dim_x+1] ||
                    !is_transformed[index+tg->dim_x+2]) {
                // cell contains border of transformation area.
                // TODO: handle this case
                continue;
            }
            poly=generatePoly(4);
            v=poly->verts;
            v[0].x=t_grid[index+tg->dim_x+1].x;
            v[0].y=t_grid[index+tg->dim_x+1].y;
            v[1].x=t_grid[index+tg->dim_x+2].x;
            v[1].y=t_grid[index+tg->dim_x+2].y;
            v[2].x=t_grid[index+1].x;
            v[2].y=t_grid[index+1].y;
            v[3].x=t_grid[index].x;
            v[3].y=t_grid[index].y;
            if(convexify4(poly)==-1) {
                deletePoly(poly, 1);
                continue;
            }
            setSides(poly);
            computeArea(poly);
            min_x=max_x=v[0].x;
            min_y=max_y=v[0].y;
            for(ii=1; ii<4; ii++) {
                if(v[ii].x<min_x)
                    min_x=v[ii].x;
                else if(v[ii].x>max_x)
                    max_x=v[ii].x;
                if(v[ii].y<min_y)
                    min_y=v[ii].y;
                else if(v[ii].y>max_y)
                    max_y=v[ii].y;
            }
            min_x=floorf(min_x);
            max_x=ceilf(max_x);
            min_y=floorf(min_y);
            max_y=ceilf(max_y);
            allocated=0;
            if((max_x-min_x) > 100 ||(max_y-min_y) > 100) {
                tg->num_pts[k]=1;
                tg->coefs[k]=(float*)calloc(1, sizeof(float));
                tg->pts[k]=(Point*)calloc(1, sizeof(Point));
                tg->coefs[k][0]=1;
                tg->pts[k][0].x=floor((max_x-min_x)/2); //TODO: fix that!
                tg->pts[k][0].y=floor((max_y-min_y)/2);
                deletePoly(poly, 1);
                continue;
            }
            for(jj=(int)min_y; jj<(int)max_y; jj++) {
                for(ii=(int)min_x; ii<(int)max_x; ii++) {
                    cell_poly->dists[0]=jj+1;
                    cell_poly->dists[1]=ii+1;
                    cell_poly->dists[2]=-jj;
                    cell_poly->dists[3]=-ii;
                    area=intersectionArea(poly, cell_poly);
                    if(area<SMALL)
                        continue;
                    last=tg->num_pts[k]++;
                    if(tg->num_pts[k]>allocated) {
                        allocated+=32;
                        tg->coefs[k]=(float*)realloc(tg->coefs[k], allocated*sizeof(float));
                        tg->pts[k]=(Point*)realloc(tg->pts[k], allocated*sizeof(Point));
                    }
                    tg->coefs[k][last]=area/poly->area;
                    tg->pts[k][last].x=ii;
                    tg->pts[k][last].y=jj;
                }
            }
            tg->coefs[k]=(float*)realloc(tg->coefs[k], tg->num_pts[k]*sizeof(float));
            tg->pts[k]=(Point*)realloc(tg->pts[k], tg->num_pts[k]*sizeof(Point));
            deletePoly(poly, 1);
        } //for(i)
    } //for(j)
    free(t_grid);
    free(is_transformed);
    return tg;
}