[89] | 1 | /***************************************************************************
|
---|
| 2 | *
|
---|
| 3 | * Copyright 2000 by David Demirdjian. All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Developed by David Demirdjian
|
---|
| 6 | *
|
---|
| 7 | * Permission to use, copy, or modify this software and its documentation
|
---|
| 8 | * for educational and research purposes only and without fee is hereby
|
---|
| 9 | * granted, provided that this copyright notice and the original authors's
|
---|
| 10 | * names appear on all copies and supporting documentation. If individual
|
---|
| 11 | * files are separated from this distribution directory structure, this
|
---|
| 12 | * copyright notice must be included. For any other uses of this software,
|
---|
| 13 | * in original or modified form, including but not limited to distribution
|
---|
| 14 | * in whole or in part, specific prior permission must be obtained from
|
---|
| 15 | * MIT. These programs shall not be used, rewritten, or adapted as the
|
---|
| 16 | * basis of a commercial software or hardware product without first
|
---|
| 17 | * obtaining appropriate licenses from David Demirdjian. The author makes
|
---|
| 18 | * no representations about the suitability of this software for any purpose.
|
---|
| 19 | * It is provided "as is" without express or implied warranty.
|
---|
| 20 | *
|
---|
| 21 | **************************************************************************/
|
---|
| 22 | #ifndef _STEREOMATCHING_H
|
---|
| 23 | #define _STEREOMATCHING_H
|
---|
| 24 |
|
---|
| 25 | #include "stereobuffer.h"
|
---|
| 26 | #include "datastructures.h"
|
---|
| 27 | #include "reconst3d.h"
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | // ********************************************************************
|
---|
| 31 | // ********************************************************************
|
---|
| 32 | // StereoMatching: class encapsulating all the stereo estimation algos
|
---|
| 33 | // ********************************************************************
|
---|
| 34 | // ********************************************************************
|
---|
| 35 | class StereoMatching {
|
---|
| 36 | public:
|
---|
| 37 | // constructor/destructor
|
---|
| 38 | StereoMatching();
|
---|
| 39 | ~StereoMatching();
|
---|
| 40 |
|
---|
| 41 | // processing data at one scale only or using multiple scale
|
---|
| 42 | enum tScaleProcessing { MONOSCALE, MULTISCALE };
|
---|
| 43 |
|
---|
| 44 | // array of buffers corresponding to different scale levels
|
---|
| 45 | StereoBuffer* sbuffer;
|
---|
| 46 |
|
---|
| 47 | // context definition: create all buffers for stereo processing
|
---|
| 48 | void initializeContext();
|
---|
| 49 | // destroy all buffers
|
---|
| 50 | void destroyContext();
|
---|
| 51 |
|
---|
| 52 | // compute input images as given scale 'sc'
|
---|
| 53 | void setInputImages(int sc, const uchar* iml8_bw, const uchar* imr8_bw);
|
---|
| 54 | void setInputImages(int sc, const uchar* iml8_bw, const uchar* imr8_bw,
|
---|
| 55 | const uchar* imt8_bw);
|
---|
| 56 |
|
---|
| 57 | // set/get image size
|
---|
| 58 | void setInputImageSize(int w, int h);
|
---|
| 59 | int getWidth() const;
|
---|
| 60 | int getHeight() const;
|
---|
| 61 |
|
---|
| 62 | // set threshold to set a pixel disparity as defined/undefined
|
---|
| 63 | void setAcceptDisparityThreshold(const float newVal);
|
---|
| 64 | float getAcceptDisparityThreshold() const;
|
---|
| 65 |
|
---|
| 66 | // set the number of scales
|
---|
| 67 | void setNumScales (const int numscales);
|
---|
| 68 | int getNumScales() const;
|
---|
| 69 | // set the (log) scale (scale at which the stereo image is returned)
|
---|
| 70 | // eg. if scale = n, the stereo image will be 2^n twice as small as the input images
|
---|
| 71 | // if scale = 0, the stereo and input images will have same size
|
---|
| 72 | void setScale (const int scale);
|
---|
| 73 | int getScale() const;
|
---|
| 74 |
|
---|
| 75 | // for monoscale (standard) or multiscale
|
---|
| 76 | void setScaleProcessing(tScaleProcessing sprocessing);
|
---|
| 77 | tScaleProcessing getScaleProcessing(void) const;
|
---|
| 78 |
|
---|
| 79 | // set horopter
|
---|
| 80 | void setHoropter (const int horopt);
|
---|
| 81 | int getHoropter() const;
|
---|
| 82 | // set the range of disp to look for ... from 8 to 64 (step. 8)
|
---|
| 83 | void setNumDepth (const int nDepth);
|
---|
| 84 | int getNumDepth() const;
|
---|
| 85 |
|
---|
| 86 | // set correlation window size from 5 to 17
|
---|
| 87 | void setCorrelationWindowSize(const int hmaskX, const int hmaskY);
|
---|
| 88 | int getCorrelationWindowSizeX() const;
|
---|
| 89 | int getCorrelationWindowSizeY() const;
|
---|
| 90 |
|
---|
| 91 | // *****************************************************
|
---|
| 92 | // doStereo: performs stereo using 2 or 3 images
|
---|
| 93 | // input:
|
---|
| 94 | // - leftImage, rightImage, (topImage): arrays of unsigned char containing the
|
---|
| 95 | // intensity (grayscale) values of an image
|
---|
| 96 | // output:
|
---|
| 97 | // - simage: a pointer on a StereoImage structure containing the stereo information
|
---|
| 98 | void doStereo(StereoImage* simage,
|
---|
| 99 | const unsigned char* leftImage, const unsigned char* rightImage,
|
---|
| 100 | const unsigned char* topImage = NULL);
|
---|
| 101 |
|
---|
| 102 | // -------- monoscale algorithm
|
---|
| 103 | // performs stereo at a given scale
|
---|
| 104 | void doStereo_fixedScale(StereoImage* simage, int scale, const InputImages* inputImage);
|
---|
| 105 |
|
---|
| 106 | // -------- multiscale algorithm
|
---|
| 107 | // assumes simageHigh and simageLow are 2 stereo images estimated at some consecutive scales
|
---|
| 108 | void doStereo_multiscale(StereoImage* simage,
|
---|
| 109 | const StereoImage* simageHigh, const StereoImage* simageLow,
|
---|
| 110 | const unsigned char acceptNew);
|
---|
| 111 |
|
---|
| 112 | // -------- perform sub-pixel estimation --------
|
---|
| 113 | void getList_subPixel(StereoImage* sdata, int scale, const StereoBuffer* sb = NULL);
|
---|
| 114 |
|
---|
| 115 | // check if (x,y,d) is a valid hypothesis
|
---|
| 116 | bool checkValidity(short x, short y, unsigned char d, const char tol) const;
|
---|
| 117 |
|
---|
| 118 | private:
|
---|
| 119 | int width, height; // input image size
|
---|
| 120 | int horopter; // translation to apply to left image
|
---|
| 121 | int numScales;
|
---|
| 122 | int scale; // eg. scale = 2 -> disparity image twice as smaller as input images
|
---|
| 123 | int nbDepth, maxNbDepth; // range to search disp.
|
---|
| 124 |
|
---|
| 125 | // type of processing (monoscale/multiscale)
|
---|
| 126 | tScaleProcessing scaleProcessing;
|
---|
| 127 |
|
---|
| 128 | // parameters for the (SAD) stereo algorithm
|
---|
| 129 | int maskSizeX, maskSizeY; // sizes of SAD filter
|
---|
| 130 | float peakValidationThreshold;
|
---|
| 131 |
|
---|
| 132 | // for sub-pixel estimation
|
---|
| 133 | bool subPixelPerformed;
|
---|
| 134 | float *scorePrev, *scoreInit, *scoreNext;
|
---|
| 135 | float *scorePrev_origin, *scoreInit_origin, *scoreNext_origin;
|
---|
| 136 |
|
---|
| 137 | // internal input images
|
---|
| 138 | InputImages* inputImages;
|
---|
| 139 |
|
---|
| 140 | void estimateStereo(const unsigned char* iml8_bw, const unsigned char* imr8_bw, const unsigned char* imtop8_bw,
|
---|
| 141 | int width, int height,
|
---|
| 142 | int maskSizeX, int maskSizeY, char minDiff, int nbDepth, int nbPartitions,
|
---|
| 143 | StereoBuffer* sb, StereoImage* sdata);
|
---|
| 144 |
|
---|
| 145 | void estimateStereo_sse2(const unsigned char* iml8_bw, const unsigned char* imr8_bw, const unsigned char* imtop8_bw,
|
---|
| 146 | int width, int height,
|
---|
| 147 | int maskSizeX, int maskSizeY, char minDiff, int nbDepth, int nbPartitions,
|
---|
| 148 | StereoBuffer* sb, StereoImage* sdata);
|
---|
| 149 |
|
---|
| 150 | void estimateStereo_Horiz(const unsigned char* iml8_bw, const unsigned char* imr8_bw,
|
---|
| 151 | int width, int height,
|
---|
| 152 | int maskSizeX, int maskSizeY, char minDiff, int nbDepth, int nbPartitions,
|
---|
| 153 | StereoBuffer* sb, StereoImage* sdata);
|
---|
| 154 | void estimateStereo_Horiz_mmx(const unsigned char* iml8_bw, const unsigned char* imr8_bw,
|
---|
| 155 | int width, int height,
|
---|
| 156 | int maskSizeX, int maskSizeY, char minDiff, int nbDepth, int nbPartitions,
|
---|
| 157 | StereoBuffer* sb, StereoImage* sdata);
|
---|
| 158 |
|
---|
| 159 | /// estimate subpixel disparities 'd' on a list of 'nbPoints' image points (x,y)
|
---|
| 160 | void getList_subPixel(const short* x, const short* y, float* subpixel_depth_list, int nbPoints,
|
---|
| 161 | const StereoBuffer* sb, unsigned char* imDepth, int scale);
|
---|
| 162 | // -------- region growing algo --------
|
---|
| 163 | // iterative region growing algorithm:
|
---|
| 164 | // - mode (algo) {0,1}
|
---|
| 165 | // - acceptNew threshold to accept a previously undefined pixel as defined
|
---|
| 166 | // - nbIterations nb iteration of the algo
|
---|
| 167 | // - imDisp_start contains the initial disp image to start with
|
---|
| 168 | // if not given, the internal disp. image is used as starting image
|
---|
| 169 | void doStereo_grow(StereoImage* simage, int mode, const unsigned char acceptNew, int nbIteration);
|
---|
| 170 | // return the diff. between best corr. score and the associated with (x,y,d) ... return -1 if not in the image
|
---|
| 171 | short checkValidity_error(short x, short y, unsigned char d, const char tol) const;
|
---|
| 172 | };
|
---|
| 173 |
|
---|
| 174 | #endif
|
---|
| 175 |
|
---|
| 176 |
|
---|