// CS 4495/7495 Computer Vision // Jim Rehg // // Problem Set 3 // Dynamic Programming for Stereo Correspondence // // Simple implementation of dynamic programming for matching two // scanlines with ordering constraints. The primary differences // between this and a "real" implementation are: (1) We match single // pixel values rather than considering an SSD window around each // match point, (2) We consider all possible disparity values for each // pixel rather than a limited range. #define SCANLEN 9 #define TBLSIZE (SCANLEN + 1) #define OCCLUDE_COST 1 // Information about a single cell in the grid class Cell { public: enum State // Possible states for each cell parent { Initialized = -1, Matched, Occluded, Disoccluded }; double cost; // cost of reaching this cell State parent; // parent cell Cell() {cost = -1.0; parent = State::Initialized;}; ~Cell() {}; void setMin(double _cost, State _parent) { cost = _cost; parent = _parent; } void updateMin(double _cost, State _parent) { if (_cost < cost) {cost = _cost; parent = _parent;}; }; }; // Grid data structure class Lattice { public: Cell tbl[TBLSIZE][TBLSIZE]; Lattice() {}; ~Lattice() {}; void initBoundary(); void forwardPass(int leftscan[SCANLEN], int rightscan[SCANLEN]); double backChain(char pathmap[TBLSIZE][TBLSIZE]); };