|
| 1 | +// This file is part of OpenCV project. |
| 2 | +// It is subject to the license terms in the LICENSE file found in the top-level directory |
| 3 | +// of this distribution and at http://opencv.org/license.html. |
| 4 | + |
| 5 | +//authors: Danail Stoyanov, Evangelos Mazomenos, Dimitrios Psychogyios |
| 6 | + |
| 7 | + |
| 8 | +//__OPENCV_QUASI_DENSE_STEREO_H__ |
| 9 | +#ifndef __OPENCV_QUASI_DENSE_STEREO_H__ |
| 10 | +#define __OPENCV_QUASI_DENSE_STEREO_H__ |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +#include <opencv2/core.hpp> |
| 15 | + |
| 16 | + |
| 17 | +namespace cv |
| 18 | +{ |
| 19 | +namespace stereo |
| 20 | +{ |
| 21 | +/** \addtogroup stereo |
| 22 | + * @{ |
| 23 | + */ |
| 24 | + |
| 25 | + |
| 26 | +// A basic match structure |
| 27 | +struct CV_EXPORTS Match |
| 28 | +{ |
| 29 | + cv::Point2i p0; |
| 30 | + cv::Point2i p1; |
| 31 | + float corr; |
| 32 | + |
| 33 | + bool operator < (const Match & rhs) const//fixme may be used uninitialized in this function |
| 34 | + { |
| 35 | + return this->corr < rhs.corr; |
| 36 | + } |
| 37 | +}; |
| 38 | +struct CV_EXPORTS PropagationParameters |
| 39 | +{ |
| 40 | + int corrWinSizeX; // similarity window |
| 41 | + int corrWinSizeY; |
| 42 | + |
| 43 | + int borderX; // border to ignore |
| 44 | + int borderY; |
| 45 | + |
| 46 | + //matching |
| 47 | + float correlationThreshold; // correlation threshold |
| 48 | + float textrureThreshold; // texture threshold |
| 49 | + |
| 50 | + int neighborhoodSize; // neighborhood size |
| 51 | + int disparityGradient; // disparity gradient threshold |
| 52 | + |
| 53 | + // Parameters for LK flow algorithm |
| 54 | + int lkTemplateSize; |
| 55 | + int lkPyrLvl; |
| 56 | + int lkTermParam1; |
| 57 | + float lkTermParam2; |
| 58 | + |
| 59 | + // Parameters for GFT algorithm. |
| 60 | + float gftQualityThres; |
| 61 | + int gftMinSeperationDist; |
| 62 | + int gftMaxNumFeatures; |
| 63 | + |
| 64 | +}; |
| 65 | + |
| 66 | + |
| 67 | +/** |
| 68 | + * @brief Class containing the methods needed for Quasi Dense Stereo computation. |
| 69 | + * |
| 70 | + * This module contains the code to perform quasi dense stereo matching. |
| 71 | + * The method initially starts with a sparse 3D reconstruction based on feature matching across a |
| 72 | + * stereo image pair and subsequently propagates the structure into neighboring image regions. |
| 73 | + * To obtain initial seed correspondences, the algorithm locates Shi and Tomashi features in the |
| 74 | + * left image of the stereo pair and then tracks them using pyramidal Lucas-Kanade in the right image. |
| 75 | + * To densify the sparse correspondences, the algorithm computes the zero-mean normalized |
| 76 | + * cross-correlation (ZNCC) in small patches around every seed pair and uses it as a quality metric |
| 77 | + * for each match. In this code, we introduce a custom structure to store the location and ZNCC value |
| 78 | + * of correspondences called "Match". Seed Matches are stored in a priority queue sorted according to |
| 79 | + * their ZNCC value, allowing for the best quality Match to be readily available. The algorithm pops |
| 80 | + * Matches and uses them to extract new matches around them. This is done by considering a small |
| 81 | + * neighboring area around each Seed and retrieving correspondences above a certain texture threshold |
| 82 | + * that are not previously computed. New matches are stored in the seed priority queue and used as seeds. |
| 83 | + * The propagation process ends when no additional matches can be retrieved. |
| 84 | + * |
| 85 | + * |
| 86 | + * @sa This code represents the work presented in @cite Stoyanov2010. |
| 87 | + * If this code is useful for your work please cite @cite Stoyanov2010. |
| 88 | + * |
| 89 | + * Also the original growing scheme idea is described in @cite Lhuillier2000 |
| 90 | + * |
| 91 | + */ |
| 92 | + |
| 93 | +class CV_EXPORTS QuasiDenseStereo |
| 94 | +{ |
| 95 | +public: |
| 96 | + /** |
| 97 | + * @brief destructor |
| 98 | + * Method to free all the memory allocated by matrices and vectors in this class. |
| 99 | + */ |
| 100 | + virtual ~QuasiDenseStereo() = 0; |
| 101 | + |
| 102 | + |
| 103 | + /** |
| 104 | + * @brief Load a file containing the configuration parameters of the class. |
| 105 | + * @param[in] filepath The location of the .YAML file containing the configuration parameters. |
| 106 | + * @note default value is an empty string in which case the default parameters will be loaded. |
| 107 | + * @retval 1: If the path is not empty and the program loaded the parameters successfully. |
| 108 | + * @retval 0: If the path is empty and the program loaded default parameters. |
| 109 | + * @retval -1: If the file location is not valid or the program could not open the file and |
| 110 | + * loaded default parameters from defaults.hpp. |
| 111 | + * @note The method is automatically called in the constructor and configures the class. |
| 112 | + * @note Loading different parameters will have an effect on the output. This is useful for tuning |
| 113 | + * in case of video processing. |
| 114 | + * @sa loadParameters |
| 115 | + */ |
| 116 | + virtual int loadParameters(cv::String filepath) = 0; |
| 117 | + |
| 118 | + |
| 119 | + /** |
| 120 | + * @brief Save a file containing all the configuration parameters the class is currently set to. |
| 121 | + * @param[in] filepath The location to store the parameters file. |
| 122 | + * @note Calling this method with no arguments will result in storing class parameters to a file |
| 123 | + * names "qds_parameters.yaml" in the root project folder. |
| 124 | + * @note This method can be used to generate a template file for tuning the class. |
| 125 | + * @sa loadParameters |
| 126 | + */ |
| 127 | + virtual int saveParameters(cv::String filepath) = 0; |
| 128 | + |
| 129 | + |
| 130 | + /** |
| 131 | + * @brief Get The sparse corresponding points. |
| 132 | + * @param[out] sMatches A vector containing all sparse correspondences. |
| 133 | + * @note The method clears the sMatches vector. |
| 134 | + * @note The returned Match elements inside the sMatches vector, do not use corr member. |
| 135 | + */ |
| 136 | + virtual void getSparseMatches(std::vector<stereo::Match> &sMatches) = 0; |
| 137 | + |
| 138 | + |
| 139 | + /** |
| 140 | + * @brief Get The dense corresponding points. |
| 141 | + * @param[out] denseMatches A vector containing all dense matches. |
| 142 | + * @note The method clears the denseMatches vector. |
| 143 | + * @note The returned Match elements inside the sMatches vector, do not use corr member. |
| 144 | + */ |
| 145 | + virtual void getDenseMatches(std::vector<stereo::Match> &denseMatches) = 0; |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + /** |
| 150 | + * @brief Main process of the algorithm. This method computes the sparse seeds and then densifies them. |
| 151 | + * |
| 152 | + * Initially input images are converted to gray-scale and then the sparseMatching method |
| 153 | + * is called to obtain the sparse stereo. Finally quasiDenseMatching is called to densify the corresponding |
| 154 | + * points. |
| 155 | + * @param[in] imgLeft The left Channel of a stereo image pair. |
| 156 | + * @param[in] imgRight The right Channel of a stereo image pair. |
| 157 | + * @note If input images are in color, the method assumes that are BGR and converts them to grayscale. |
| 158 | + * @sa sparseMatching |
| 159 | + * @sa quasiDenseMatching |
| 160 | + */ |
| 161 | + virtual void process(const cv::Mat &imgLeft ,const cv::Mat &imgRight) = 0; |
| 162 | + |
| 163 | + |
| 164 | + /** |
| 165 | + * @brief Specify pixel coordinates in the left image and get its corresponding location in the right image. |
| 166 | + * @param[in] x The x pixel coordinate in the left image channel. |
| 167 | + * @param[in] y The y pixel coordinate in the left image channel. |
| 168 | + * @retval cv::Point(x, y) The location of the corresponding pixel in the right image. |
| 169 | + * @retval cv::Point(0, 0) (NO_MATCH) if no match is found in the right image for the specified pixel location in the left image. |
| 170 | + * @note This method should be always called after process, otherwise the matches will not be correct. |
| 171 | + */ |
| 172 | + virtual cv::Point2f getMatch(const int x, const int y) = 0; |
| 173 | + |
| 174 | + |
| 175 | + /** |
| 176 | + * @brief Compute and return the disparity map based on the correspondences found in the "process" method. |
| 177 | + * @param[in] disparityLvls The level of detail in output disparity image. |
| 178 | + * @note Default level is 50 |
| 179 | + * @return cv::Mat containing a the disparity image in grayscale. |
| 180 | + * @sa computeDisparity |
| 181 | + * @sa quantizeDisparity |
| 182 | + */ |
| 183 | + virtual cv::Mat getDisparity(uint8_t disparityLvls=50) = 0; |
| 184 | + |
| 185 | + |
| 186 | + static cv::Ptr<QuasiDenseStereo> create(cv::Size monoImgSize, cv::String paramFilepath = cv::String()); |
| 187 | + |
| 188 | + |
| 189 | + PropagationParameters Param; |
| 190 | +}; |
| 191 | + |
| 192 | +} //namespace cv |
| 193 | +} //namespace stereo |
| 194 | + |
| 195 | +/** @}*/ |
| 196 | + |
| 197 | +#endif // __OPENCV_QUASI_DENSE_STEREO_H__ |
0 commit comments