home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
detect.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-30
|
11KB
|
494 lines
#include "../polygons.h"
#include "../stdDefs.h"
void free_meta_graph(MGvertex *graph);
void free_vertex_list(vertexList *vlist);
void free_edge_list(MGedgeList *elist);
void free_MGvertex_list(MGvertexList *MGvlist);
void load_and_draw_poly(char *file, c_handle pane);
void transform_bbox(c_handle transform, double x1, double y1, double x2,
double y2, double *newx1, double *newy1, double *newx2, double *newy2);
c_handle image_trans;
c_handle view_trans; /* Window View Transform */
c_handle world_trans;
int MANUAL;
int K;
void find_polygons(double sensitivity, int constrain, int manual, int use2_5d,
int bb_x1, int bb_y1, int bb_x2, int bb_y2, int k_cycles,
c_handle picked_pane)
{
c_handle out_im; /* Output Image */
c_handle view;
int init = 0;
int i,j;
int len;
Point vecx, vecy, vecz;
FILE *fp, *fopen();
double u_v_point[4];
double x_y_z_point[4];
double u1, v1, u2, v2;
double wx1, wy1, wx2, wy2;
double_2 *imagePoint1, *imagePoint2;
c_handle inImage;
char imageName[280];
char lineFile[280];
int Ncorners;
int ytemp, xtemp;
char cornerFile[280];
/*
* If the manual flag is set, the parameters have already
* been adjusted by the user. Otherwise use the default
* settings.
*/
fprintf(stderr,"In Building Detect.\n");
MANUAL = manual;
K = k_cycles;
if (K == 0)
K_CYCLES = FALSE;
else
K_CYCLES = TRUE;
in_pane = picked_pane; /* Global variable version */
if (!MANUAL)
setup_defaults(sensitivity);
/*
* Non-adjustable defaults
*/
SEARCH_ANGLE = DEFAULT_SEARCH_ANGLE;
CONSTRAIN = constrain;
inImage = working_image(get_2d_world(top_image(1,picked_pane)));
view = top_view(1,picked_pane);
view_trans = two_d_to_window_transform(view);
image_trans = image_to_window_transform(view);
world_trans = image_to_2d_transform(view);
transform_bbox((c_handle)inverse_transform(image_trans),
(double)bb_x1,(double)bb_y1,
(double)bb_x2,(double)bb_y2,
&u1, &v1, &u2, &v2);
transform_bbox(world_trans,u1,v1,u2,v2,
&wx1, &wy1, &wx2, &wy2);
xstart = (int) floor(wx1);
ystart = (int) floor(wy1);
xstop = (int) ceil(wx2);
ystop = (int) ceil(wy2);
xdim = xstop - xstart;
ydim = ystop - ystart;
/* printf("bounds %d %d %d %d\n", xstart, ystart, xstop, ystop); */
/*** Draw the bounding region ***/
imagePoint1 = (double_2 *) inverse_transform_point(world_trans,
(double)xstart,(double)ystart,0);
imagePoint2 = (double_2 *) inverse_transform_point(world_trans,
(double)xstart,(double)ystop,0);
draw_fat_line(picked_pane,imagePoint1->d1,imagePoint1->d2,
imagePoint2->d1,imagePoint2->d2,2.0);
imagePoint1 = (double_2 *) inverse_transform_point(world_trans,
(double)xstart,(double)ystop,0);
imagePoint2 = (double_2 *) inverse_transform_point(world_trans,
(double)xstop,(double)ystop,0);
draw_fat_line(picked_pane,imagePoint1->d1,imagePoint1->d2,
imagePoint2->d1,imagePoint2->d2,2.0);
imagePoint1 = (double_2 *) inverse_transform_point(world_trans,
(double)xstop,(double)ystop,0);
imagePoint2 = (double_2 *) inverse_transform_point(world_trans,
(double)xstop,(double)ystart,0);
draw_fat_line(picked_pane,imagePoint1->d1,imagePoint1->d2,
imagePoint2->d1,imagePoint2->d2,2.0);
imagePoint1 = (double_2 *) inverse_transform_point(world_trans,
(double)xstop,(double)ystart,0);
imagePoint2 = (double_2 *) inverse_transform_point(world_trans,
(double)xstart,(double)ystart,0);
draw_fat_line(picked_pane,imagePoint1->d1,imagePoint1->d2,
imagePoint2->d1,imagePoint2->d2,2.0);
if (use2_5d)
strcpy(lineFile, get2_5dlineFile(inImage));
else
strcpy(lineFile, get2dlineFile(inImage));
sprintf(cornerFile,"%scorners",getTempDir(inImage));
Ncorners = compute_intersections_region(lineFile,cornerFile,picked_pane,
inImage, xstart,ystart, xstop,ystop);
fprintf(stderr,"Found %d corners.\n",Ncorners);
if (MANUAL) {
fprintf(stderr,"--------Hit Return To Continue--------\n");
getchar();
}
process_region(lineFile, cornerFile, inImage);
/* Clean up Temp files
sprintf(cmdstr,"rm %s",cornerFile);
system(cmdstr); */
}
void
process_region(char *lineFile, char *cornerFile, c_handle im)
{
/*
* NOTE: The global variables (xstart,ystart xstop,ystop) must be
* initalized!
*
*/
cList *s_list;
int no_of_colors;
MGvertex *meta_graph;
MGvertexList *ptr;
MGvertexList *iss_list;
MGvertexList *iss_max;
cList *vertex_list;
cList *corner_list;
strcpy(IMAGE_NAME,(char *) name(get_2d_world(im)));
sprintf(IMAGE_NAME_3D,(char *) name(get_3d_world(im)));
/*
* Get the associated projection matrix for this image...
*/
projectionMat = get_projection_matrix(get_2d_world(im));
/**** Load Low Level Features into Memory ****/
corner_list = read_corners_from_file(cornerFile);
line_list = load_line_data(xstart,ystart,xstop,ystop,lineFile,im);
buildGraph(corner_list,im, in_pane);
if (MANUAL) {
fprintf(stderr,"--------Hit Return To Continue--------\n");
getchar();
}
meta_graph = NULL;
no_of_colors=0;
tours(im,corner_list, &no_of_colors, &meta_graph);
virtualTours(im,corner_list,&no_of_colors,&meta_graph);
build_dependency_graph(corner_list,no_of_colors,meta_graph);
/* If K is zero, then compute the independent subsets in
* the graph and output the maximum of these subsets,
* Otherwise, sort the exisiting meta_graph by node confidence
* and output the top K.
*/
if (K == 0)
iss_list = all_indep_subsets(meta_graph);
else
iss_list = sort_top_K_nodes(meta_graph,K);
if (iss_list != NULL) {
if (iss_list->eList->vertex != NULL) {
if (K == 0)
iss_max = get_max_iss(iss_list);
else
iss_max = iss_list;
if (iss_max == NULL)
fprintf(stderr,"NULL PTR!!\n");
refresh(in_pane);
if (!USE_3D)
poly2curves(in_pane,iss_max,im);
else{
printf("3d!!\n");
poly2_3dcurves(in_pane,iss_max);
}
}
} else
fprintf(stderr,"ISS NULL\n");
fprintf(stderr,"Done. Free Memory!\n");
free_meta_graph(meta_graph);
free_MGvertex_list(iss_list);
free_list(corner_list);
free_line_list(line_list);
refresh(in_pane);
}
void free_list(cList *list)
{
cList *p, *q;
edgeList *e,*f;
for (p = list; p != NULL; p = q) {
for (e=p->eList; e != NULL; e = f) {
f = e->next;
free(e);
}
q = p->next;
free(p);
}
}
void free_line_list(line *list)
{
line *p, *q;
for (p = list; p != NULL; p=q) {
q = p->next;
free(p);
}
}
void free_meta_graph(MGvertex *graph)
{
MGvertex *ptr;
MGvertex *f_ptr;
for (ptr = graph; ptr != NULL; ptr = f_ptr) {
f_ptr = ptr->next;
free_vertex_list(ptr->vList);
free_edge_list(ptr->eList);
free(ptr);
}
}
void free_vertex_list(vertexList *vlist)
{
vertexList *ptr;
vertexList *f_ptr;
for (ptr = vlist; ptr != NULL; ptr = f_ptr) {
f_ptr = ptr->next;
free(ptr);
}
}
void free_MGvertex_list(MGvertexList *vlist)
{
MGvertexList *ptr;
MGvertexList *f_ptr;
for (ptr = vlist; ptr != NULL; ptr = f_ptr) {
f_ptr = ptr->next;
/* CHANGED: May 29, 1996 */
free_edge_list(ptr->eList);
free(ptr);
}
}
void free_edge_list(MGedgeList *elist)
{
MGedgeList *ptr;
MGedgeList *f_ptr;
for (ptr = elist; ptr != NULL; ptr = f_ptr) {
f_ptr = ptr->next;
/* CHANGED: May 29, 1996 */
free_meta_graph(ptr->vertex);
free(ptr);
}
}
int sleep(int time)
{
int j= 50;
int i;
printf("Sleep...");
for (i=0; i < 10000*time; i++)
j = j + 1;
printf("Done.\n");
}
void load_and_draw_poly(char *file, c_handle pane)
{
FILE *fp, *fopen();
int x1,y1,x2,y2;
if ( (fp = fopen(file,"r")) == NULL) {
fprintf(stderr,"Cannot open polygon data\n");
return;
}
while (fscanf(fp,"%d %d %d %d",&x1,&y1,&x2,&y2) != EOF)
draw_fat_line(pane,(double)x1,(double)y1,(double)x2,(double)y2,
(double)LINE_WIDTH);
fclose(fp);
}
void
setup_defaults(double Sensitivity)
/*
* Setup the appropriate global defaults for the building
* detector.
*
* This should depend on the sensitivity rating,
* and information from the image (ie- camera pose, illumination)
*
* Currently, this is set only by the sensitivity.
*
*/
{
MIN_LINE_SUPPORT = DEFAULT_LINE_SUPPORT_LOW -
(DEFAULT_LINE_SUPPORT_LOW -
DEFAULT_LINE_SUPPORT_HIGH)*Sensitivity;
TOKEN_WINDOW = TOKEN_WINDOW_LOW -
(TOKEN_WINDOW_LOW - TOKEN_WINDOW_HIGH)*
Sensitivity;
TOKEN_SUPPORT = TOKEN_SUPPORT_LOW -
(TOKEN_SUPPORT_LOW - TOKEN_SUPPORT_HIGH)*
Sensitivity;
ANGLE_THRESH = DEFAULT_ANGLE_THRESH_LOW -
(DEFAULT_ANGLE_THRESH_LOW -
DEFAULT_ANGLE_THRESH_HIGH)*Sensitivity;
LINE_SWEEP_COLUMN = LINE_SWEEP_COLUMN_LOW -
(LINE_SWEEP_COLUMN_LOW -
LINE_SWEEP_COLUMN_HIGH)*Sensitivity;
LINE_ENDPOINT_WINDOW = LINE_ENDPOINT_WINDOW_LOW -
(LINE_ENDPOINT_WINDOW_LOW -
LINE_ENDPOINT_WINDOW_HIGH)*Sensitivity;
}
void
set_building_parameters(double angle_error, double line_window,
double search_angle, double column,
double line_support, double token_support,
double token_window)
{
MIN_LINE_SUPPORT = line_support;
TOKEN_WINDOW = token_window;
TOKEN_SUPPORT = token_support;
ANGLE_THRESH = angle_error;
LINE_SWEEP_COLUMN = column;
LINE_ENDPOINT_WINDOW = line_window;
}
/* THE FOLLOWING STUFF WAS ADDED BY BOB COLLINS ON NOV 5, 1995 TO
DEAL WITH GENERAL TRANSFORMATIONS OF BOUNDING BOXES */
double min4(double a, double b, double c, double d)
{
if ((a < b))
if ((a < c))
if ((a < d))
return(a);
else
return(d);
else
if ((c < d))
return(c);
else
return(d);
else
if ((b < c))
if ((b < d))
return(b);
else
return(d);
else
if ((c < d))
return(c);
else
return(d);
}
double max4(double a, double b, double c, double d)
{
if ((a > b))
if ((a > c))
if ((a > d))
return(a);
else
return(d);
else
if ((c > d))
return(c);
else
return(d);
else
if ((b > c))
if ((b > d))
return(b);
else
return(d);
else
if ((c > d))
return(c);
else
return(d);
}
void
transform_bbox(c_handle transform, double x1, double y1, double x2, double y2,
double *newx1, double *newy1, double *newx2, double *newy2)
{
double_2 *userPoint;
double a1,a2,a3,a4, b1,b2,b3,b4;
/* printf("tbbox input> %f %f %f %f\n", x1, y1, x2, y2); */
userPoint = (double_2 *) transform_point(transform,x1,y1,0);
a1 = userPoint->d1; b1 = userPoint->d2;
userPoint = (double_2 *) transform_point(transform,x1,y2,0);
a2 = userPoint->d1; b2 = userPoint->d2;
userPoint = (double_2 *) transform_point(transform,x2,y1,0);
a3 = userPoint->d1; b3 = userPoint->d2;
userPoint = (double_2 *) transform_point(transform,x2,y2,0);
a4 = userPoint->d1; b4 = userPoint->d2;
*newx1 = min4(a1,a2,a3,a4);
*newy1 = min4(b1,b2,b3,b4);
*newx2 = max4(a1,a2,a3,a4);
*newy2 = max4(b1,b2,b3,b4);
/* printf("tbbox output> %f %f %f %f\n", *newx1, *newy1, *newx2, *newy2); */
return;
}