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
/
ascendMar8.tar
/
UMass
/
BuildingFinder
/
Staging
/
detect.c.sav
< prev
next >
Wrap
Text File
|
1995-11-07
|
9KB
|
400 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);
c_handle image_trans;
c_handle view_trans; /* Window View Transform */
int MANUAL;
void find_polygons(double sensitivity, int constrain, int manual, int use2_5d,
int bb_x1, int bb_y1, int bb_x2, int bb_y2, c_handle picked_pane)
{
c_handle out_im; /* Output Image */
c_handle view;
int startx,starty,stopx,stopy;
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_2 *userPoint;
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.
*/
MANUAL = manual;
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);
userPoint = (double_2 *) inverse_transform_point(view_trans,
(double)bb_x1,(double)bb_y1,0);
imagePoint1 = (double_2 *) inverse_transform_point(image_trans,
(double)bb_x1,(double)bb_y1,0);
/*
* Does the bounding box lay within the image, if not clip it to fit!
*/
if (imagePoint1->d1 >= image_x_dim(inImage) )
imagePoint1->d1 = image_x_dim(inImage);
if (imagePoint1->d2 >= image_y_dim(inImage) )
imagePoint1->d2 = image_y_dim(inImage);
if (imagePoint1->d1 < 0 )
imagePoint1->d1 = 0;
if (imagePoint1->d2 < 0)
imagePoint1->d2 = 0;
startx = (int) floor(userPoint->d1);
starty = (int) floor(userPoint->d2);
userPoint = (double_2 *) inverse_transform_point(view_trans,
(double)bb_x2,(double)bb_y2,0);
imagePoint2 = (double_2 *) inverse_transform_point(image_trans,
(double)bb_x2,(double)bb_y2,0);
if (imagePoint2->d1 >= image_x_dim(inImage) )
imagePoint2->d1 = image_x_dim(inImage);
if (imagePoint2->d2 >= image_y_dim(inImage) )
imagePoint2->d2 = image_y_dim(inImage);
if (imagePoint2->d1 < 0 )
imagePoint2->d1 = 0;
if (imagePoint2->d2 < 0)
imagePoint2->d2 = 0;
stopx = (int) floor(userPoint->d1);
stopy = (int) floor(userPoint->d2);
ystart = starty - (WINDOW+1);
xstart = startx - (WINDOW+1);
xstop = stopx + (WINDOW+1);
ystop = stopy + (WINDOW+1);
xdim = xstop - xstart;
ydim = ystop - ystart;
/*** Draw the bounding region ***/
draw_fat_line(picked_pane,imagePoint1->d1,imagePoint1->d2,
imagePoint2->d1,imagePoint1->d2,2.0);
draw_fat_line(picked_pane,imagePoint2->d1,imagePoint1->d2,
imagePoint2->d1,imagePoint2->d2,2.0);
draw_fat_line(picked_pane,imagePoint2->d1,imagePoint2->d2,
imagePoint1->d1,imagePoint2->d2,2.0);
draw_fat_line(picked_pane,imagePoint1->d1,imagePoint2->d2,
imagePoint1->d1,imagePoint1->d2,2.0);
if (xstart > xstop) {
xtemp = xstart;
xstart = xstop;
xstop = xtemp;
}
if (ystart > ystop) {
ytemp = ystart;
ystart = ystop;
ystop = ytemp;
}
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);
iss_list = all_indep_subsets(meta_graph);
if (iss_list != NULL) {
iss_max = get_max_iss(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");
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;
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;
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 edge_mag,
double edge_var, 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;
}