www.pudn.com > match-v3.3.src.rar > match.cpp
/* match.cpp */ /* Vladimir Kolmogorov (vnk@cs.cornell.edu), 2001-2003. */ #include#include #include "match.h" /************************************************************/ /************************************************************/ /************************************************************/ Match::Match(char *name_left, char *name_right, bool color) { Coord p; if (!color) { im_color_left = im_color_right = NULL; im_color_left_min = im_color_right_min = NULL; im_color_left_max = im_color_right_max = NULL; im_left = (GrayImage) imLoad(IMAGE_GRAY, name_left); if (!im_left) { fprintf(stderr, "Can't load %s\n", name_left); exit(1); } im_right = (GrayImage) imLoad(IMAGE_GRAY, name_right); if (!im_right) { fprintf(stderr, "Can't load %s\n", name_right); exit(1); } im_size.x = imGetXSize(im_left); im_size.y = imGetYSize(im_left); if ( im_size.x != imGetXSize(im_right) || im_size.y != imGetYSize(im_right) ) { fprintf(stderr, "Image sizes are different!\n"); exit(1); } im_left_min = im_left_max = im_right_min = im_right_max = NULL; } else { im_left = im_right = NULL; im_left_min = im_right_min = NULL; im_left_max = im_right_max = NULL; im_color_left = (RGBImage) imLoad(IMAGE_RGB, name_left); if (!im_color_left) { fprintf(stderr, "Can't load %s\n", name_left); exit(1); } im_color_right = (RGBImage) imLoad(IMAGE_RGB, name_right); if (!im_color_right) { fprintf(stderr, "Can't load %s\n", name_right); exit(1); } im_size.x = imGetXSize(im_color_left); im_size.y = imGetYSize(im_color_left); if ( im_size.x != imGetXSize(im_color_right) || im_size.y != imGetYSize(im_color_right) ) { fprintf(stderr, "Image sizes are different!\n"); exit(1); } im_color_left_min = im_color_left_max = im_color_right_min = im_color_right_max = NULL; } disp_base = Coord(0, 0); disp_max = Coord(0, 0); disp_size = Coord(1, 1); x_left = (LongImage) imNew(IMAGE_LONG, im_size.x, im_size.y); y_left = (LongImage) imNew(IMAGE_LONG, im_size.x, im_size.y); x_right = (LongImage) imNew(IMAGE_LONG, im_size.x, im_size.y); y_right = (LongImage) imNew(IMAGE_LONG, im_size.x, im_size.y); if (!x_left || !y_left || !x_right || !y_right) { fprintf(stderr, "Not enough memory!\n"); exit(1); } for (p.y=0; p.y =0 && c =0 && c =Coord(0,0) && pd =Coord(0,0) && pd =Coord(0,0) && pd 0; iter++) { if (iter==0 || params.randomize_every_iteration) generate_permutation(permutation, label_num); for (index=0; index disp_max.x) a.x = a.y = OCCLUDED; E_old = E; switch (method) { case METHOD_KZ1: KZ1_Expand(a); break; case METHOD_KZ2: KZ2_Expand(a); break; case METHOD_BVZ: BVZ_Expand(a); break; } #ifndef NDEBUG { int E_tmp = E; switch (method) { case METHOD_KZ1: KZ1_ComputeEnergy(); break; case METHOD_KZ2: KZ2_ComputeEnergy(); break; case METHOD_BVZ: BVZ_ComputeEnergy(); break; } if (E_tmp != E) { fprintf(stderr, "E and E_tmp are different! (E = %d, E_tmp = %d)\n", E, E_tmp); exit(1); } } #endif step ++; if (E_old == E) printf("-"); else printf("*"); fflush(stdout); if (E_old == E) { if (!buf[label]) { buf[label] = true; buf_num --; } } else { int i; for (i=0; i