├── result_example ├── a1.png ├── a5.png ├── l_inv.png ├── r_inv.png ├── left_disparity.png ├── before_filter_d2.png ├── before_filter_ld2.png └── right_disparity.png ├── dataset ├── Aloe │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Baby1 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Baby2 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Baby3 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Midd1 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Midd2 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Wood1 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Wood2 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Bowling1 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Bowling2 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Cloth1 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Cloth2 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Cloth3 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Cloth4 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Monopoly │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Plastic │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Rocks1 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Rocks2 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Flowerpots │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── Lampshade1 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png └── Lampshade2 │ ├── disp1.png │ ├── disp5.png │ ├── view1.png │ └── view5.png ├── makefile ├── README.md ├── main.cpp ├── pm.h └── pm.cpp /result_example/a1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/result_example/a1.png -------------------------------------------------------------------------------- /result_example/a5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/result_example/a5.png -------------------------------------------------------------------------------- /dataset/Aloe/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Aloe/disp1.png -------------------------------------------------------------------------------- /dataset/Aloe/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Aloe/disp5.png -------------------------------------------------------------------------------- /dataset/Aloe/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Aloe/view1.png -------------------------------------------------------------------------------- /dataset/Aloe/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Aloe/view5.png -------------------------------------------------------------------------------- /dataset/Baby1/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby1/disp1.png -------------------------------------------------------------------------------- /dataset/Baby1/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby1/disp5.png -------------------------------------------------------------------------------- /dataset/Baby1/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby1/view1.png -------------------------------------------------------------------------------- /dataset/Baby1/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby1/view5.png -------------------------------------------------------------------------------- /dataset/Baby2/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby2/disp1.png -------------------------------------------------------------------------------- /dataset/Baby2/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby2/disp5.png -------------------------------------------------------------------------------- /dataset/Baby2/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby2/view1.png -------------------------------------------------------------------------------- /dataset/Baby2/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby2/view5.png -------------------------------------------------------------------------------- /dataset/Baby3/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby3/disp1.png -------------------------------------------------------------------------------- /dataset/Baby3/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby3/disp5.png -------------------------------------------------------------------------------- /dataset/Baby3/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby3/view1.png -------------------------------------------------------------------------------- /dataset/Baby3/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Baby3/view5.png -------------------------------------------------------------------------------- /dataset/Midd1/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Midd1/disp1.png -------------------------------------------------------------------------------- /dataset/Midd1/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Midd1/disp5.png -------------------------------------------------------------------------------- /dataset/Midd1/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Midd1/view1.png -------------------------------------------------------------------------------- /dataset/Midd1/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Midd1/view5.png -------------------------------------------------------------------------------- /dataset/Midd2/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Midd2/disp1.png -------------------------------------------------------------------------------- /dataset/Midd2/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Midd2/disp5.png -------------------------------------------------------------------------------- /dataset/Midd2/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Midd2/view1.png -------------------------------------------------------------------------------- /dataset/Midd2/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Midd2/view5.png -------------------------------------------------------------------------------- /dataset/Wood1/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Wood1/disp1.png -------------------------------------------------------------------------------- /dataset/Wood1/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Wood1/disp5.png -------------------------------------------------------------------------------- /dataset/Wood1/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Wood1/view1.png -------------------------------------------------------------------------------- /dataset/Wood1/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Wood1/view5.png -------------------------------------------------------------------------------- /dataset/Wood2/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Wood2/disp1.png -------------------------------------------------------------------------------- /dataset/Wood2/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Wood2/disp5.png -------------------------------------------------------------------------------- /dataset/Wood2/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Wood2/view1.png -------------------------------------------------------------------------------- /dataset/Wood2/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Wood2/view5.png -------------------------------------------------------------------------------- /dataset/Bowling1/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Bowling1/disp1.png -------------------------------------------------------------------------------- /dataset/Bowling1/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Bowling1/disp5.png -------------------------------------------------------------------------------- /dataset/Bowling1/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Bowling1/view1.png -------------------------------------------------------------------------------- /dataset/Bowling1/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Bowling1/view5.png -------------------------------------------------------------------------------- /dataset/Bowling2/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Bowling2/disp1.png -------------------------------------------------------------------------------- /dataset/Bowling2/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Bowling2/disp5.png -------------------------------------------------------------------------------- /dataset/Bowling2/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Bowling2/view1.png -------------------------------------------------------------------------------- /dataset/Bowling2/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Bowling2/view5.png -------------------------------------------------------------------------------- /dataset/Cloth1/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth1/disp1.png -------------------------------------------------------------------------------- /dataset/Cloth1/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth1/disp5.png -------------------------------------------------------------------------------- /dataset/Cloth1/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth1/view1.png -------------------------------------------------------------------------------- /dataset/Cloth1/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth1/view5.png -------------------------------------------------------------------------------- /dataset/Cloth2/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth2/disp1.png -------------------------------------------------------------------------------- /dataset/Cloth2/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth2/disp5.png -------------------------------------------------------------------------------- /dataset/Cloth2/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth2/view1.png -------------------------------------------------------------------------------- /dataset/Cloth2/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth2/view5.png -------------------------------------------------------------------------------- /dataset/Cloth3/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth3/disp1.png -------------------------------------------------------------------------------- /dataset/Cloth3/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth3/disp5.png -------------------------------------------------------------------------------- /dataset/Cloth3/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth3/view1.png -------------------------------------------------------------------------------- /dataset/Cloth3/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth3/view5.png -------------------------------------------------------------------------------- /dataset/Cloth4/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth4/disp1.png -------------------------------------------------------------------------------- /dataset/Cloth4/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth4/disp5.png -------------------------------------------------------------------------------- /dataset/Cloth4/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth4/view1.png -------------------------------------------------------------------------------- /dataset/Cloth4/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Cloth4/view5.png -------------------------------------------------------------------------------- /dataset/Monopoly/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Monopoly/disp1.png -------------------------------------------------------------------------------- /dataset/Monopoly/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Monopoly/disp5.png -------------------------------------------------------------------------------- /dataset/Monopoly/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Monopoly/view1.png -------------------------------------------------------------------------------- /dataset/Monopoly/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Monopoly/view5.png -------------------------------------------------------------------------------- /dataset/Plastic/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Plastic/disp1.png -------------------------------------------------------------------------------- /dataset/Plastic/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Plastic/disp5.png -------------------------------------------------------------------------------- /dataset/Plastic/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Plastic/view1.png -------------------------------------------------------------------------------- /dataset/Plastic/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Plastic/view5.png -------------------------------------------------------------------------------- /dataset/Rocks1/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Rocks1/disp1.png -------------------------------------------------------------------------------- /dataset/Rocks1/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Rocks1/disp5.png -------------------------------------------------------------------------------- /dataset/Rocks1/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Rocks1/view1.png -------------------------------------------------------------------------------- /dataset/Rocks1/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Rocks1/view5.png -------------------------------------------------------------------------------- /dataset/Rocks2/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Rocks2/disp1.png -------------------------------------------------------------------------------- /dataset/Rocks2/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Rocks2/disp5.png -------------------------------------------------------------------------------- /dataset/Rocks2/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Rocks2/view1.png -------------------------------------------------------------------------------- /dataset/Rocks2/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Rocks2/view5.png -------------------------------------------------------------------------------- /result_example/l_inv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/result_example/l_inv.png -------------------------------------------------------------------------------- /result_example/r_inv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/result_example/r_inv.png -------------------------------------------------------------------------------- /dataset/Flowerpots/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Flowerpots/disp1.png -------------------------------------------------------------------------------- /dataset/Flowerpots/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Flowerpots/disp5.png -------------------------------------------------------------------------------- /dataset/Flowerpots/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Flowerpots/view1.png -------------------------------------------------------------------------------- /dataset/Flowerpots/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Flowerpots/view5.png -------------------------------------------------------------------------------- /dataset/Lampshade1/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Lampshade1/disp1.png -------------------------------------------------------------------------------- /dataset/Lampshade1/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Lampshade1/disp5.png -------------------------------------------------------------------------------- /dataset/Lampshade1/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Lampshade1/view1.png -------------------------------------------------------------------------------- /dataset/Lampshade1/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Lampshade1/view5.png -------------------------------------------------------------------------------- /dataset/Lampshade2/disp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Lampshade2/disp1.png -------------------------------------------------------------------------------- /dataset/Lampshade2/disp5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Lampshade2/disp5.png -------------------------------------------------------------------------------- /dataset/Lampshade2/view1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Lampshade2/view1.png -------------------------------------------------------------------------------- /dataset/Lampshade2/view5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/dataset/Lampshade2/view5.png -------------------------------------------------------------------------------- /result_example/left_disparity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/result_example/left_disparity.png -------------------------------------------------------------------------------- /result_example/before_filter_d2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/result_example/before_filter_d2.png -------------------------------------------------------------------------------- /result_example/before_filter_ld2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/result_example/before_filter_ld2.png -------------------------------------------------------------------------------- /result_example/right_disparity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibergonzani/patch-match-stereo/HEAD/result_example/right_disparity.png -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | OPENCV = `pkg-config --cflags --libs opencv` 2 | 3 | 4 | all: 5 | g++ --std=c++11 -fopenmp -O3 -I./ main.cpp pm.cpp $(OPENCV) -o pm 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Patch Match Stereo 2 | 3 | Implementations in C++ of the Patch Match Stereo algorithm presented in: 4 | * [PatchMatch Stereo - Stereo Matching with Slanted Support Windows](https://www.microsoft.com/en-us/research/wp-content/uploads/2011/01/PatchMatchStereo_BMVC2011_6MB.pdf) 5 | 6 | Be aware, as a university project the code was not meant to be optimized but instead easy to read and understand. 7 | 8 | Code was compiled and tested on ubuntu 16.04 usng g++ 5.4. Compilation requires the opencv libraries to be installed. 9 | Compile it using make 10 | 11 | Execute it using 12 | ``` 13 | pm path/to/imag1 path/to/image2 14 | ``` -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | bool check_image(const cv::Mat &image, std::string name="Image") 7 | { 8 | if(!image.data) 9 | { 10 | std::cerr < 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | template 15 | class Matrix2D 16 | { 17 | public: 18 | Matrix2D(); 19 | Matrix2D(unsigned int rows, unsigned int cols); 20 | Matrix2D(unsigned int rows, unsigned int cols, const T& def); 21 | 22 | T& operator()(unsigned int row, unsigned int col); 23 | const T& operator()(unsigned int row, unsigned int col) const; 24 | 25 | unsigned int rows; 26 | unsigned int cols; 27 | 28 | private: 29 | 30 | std::vector> data; 31 | }; 32 | 33 | 34 | 35 | 36 | class Plane 37 | { 38 | public: 39 | 40 | Plane(); 41 | Plane(cv::Vec3f point, cv::Vec3f normal); 42 | 43 | float operator[](int idx) const; 44 | cv::Vec3f operator()(); 45 | 46 | cv::Vec3f getPoint(); 47 | cv::Vec3f getNormal(); 48 | cv::Vec3f getCoeff(); 49 | 50 | Plane viewTransform(int x, int y, int sign, int& qx, int &qy); 51 | 52 | private: 53 | 54 | cv::Vec3f point; 55 | cv::Vec3f normal; 56 | cv::Vec3f coeff; 57 | }; 58 | 59 | 60 | namespace pm 61 | { 62 | class PatchMatch 63 | { 64 | public: 65 | PatchMatch(float alpha, float gamma, float tau_c, float tau_g); 66 | 67 | PatchMatch(const PatchMatch &pm) = delete; 68 | 69 | PatchMatch& operator=(const PatchMatch &pm) = delete; 70 | 71 | void operator()(const cv::Mat3b &img1, const cv::Mat3b &img2, int iterations, bool reverse=false); 72 | 73 | void set(const cv::Mat3b &img1, const cv::Mat3b &img2); 74 | 75 | void process(int iterations, bool reverse=false); 76 | 77 | void postProcess(); 78 | 79 | cv::Mat1f getLeftDisparityMap() const; 80 | 81 | cv::Mat1f getRightDisparityMap() const; 82 | 83 | float alpha; 84 | float gamma; 85 | float tau_c; 86 | float tau_g; 87 | 88 | private: 89 | 90 | float dissimilarity(const cv::Vec3f &pp, const cv::Vec3f &qq, const cv::Vec2f &pg, const cv::Vec2f &qg); 91 | 92 | float plane_match_cost(const Plane &p, int cx, int cy, int ws, int cpv); 93 | 94 | void precompute_pixels_weights(const cv::Mat3b &frame, cv::Mat &weights, int ws); 95 | 96 | void initialize_random_planes(Matrix2D &planes, float max_d); 97 | 98 | void evaluate_planes_cost(int cpv); 99 | 100 | void spatial_propagation(int x, int y, int cpv, int iter); 101 | 102 | void view_propagation(int x, int y, int cpv); 103 | 104 | void plane_refinement(int x, int y, int cpv, float max_delta_z, float max_delta_n, float end_dz); 105 | 106 | void process_pixel(int x, int y, int cpv, int iter); 107 | 108 | void planes_to_disparity(const Matrix2D &planes, cv::Mat1f &disp); 109 | 110 | void fill_invalid_pixels(int y, int x, Matrix2D &planes, const cv::Mat1b &validity); 111 | 112 | void weighted_median_filter(int cx, int cy, cv::Mat1f &disparity, const cv::Mat &weights, const cv::Mat1b &valid, int ws, bool use_invalid); 113 | 114 | 115 | cv::Mat3b views[2]; // left and right view images 116 | cv::Mat2f grads[2]; // pixels greyscale gradient for both views 117 | cv::Mat1f disps[2]; // left and right disparity maps 118 | 119 | Matrix2D planes[2]; // pixels' planes for left and right view 120 | cv::Mat1f costs[2]; // planes' costs 121 | cv::Mat weigs[2]; // precomputed pixels window weights 122 | //cv::Mat dissm[2]; //pixels dissimilarities, precompute in parallel 123 | 124 | int rows; 125 | int cols; 126 | 127 | }; 128 | 129 | 130 | 131 | inline cv::Mat1f PatchMatch::getLeftDisparityMap() const 132 | { 133 | return this->disps[0]; 134 | } 135 | 136 | 137 | inline cv::Mat1f PatchMatch::getRightDisparityMap() const 138 | { 139 | return this->disps[1]; 140 | } 141 | 142 | 143 | // consider preallocated gradients matrix 144 | void compute_greyscale_gradient(const::cv::Mat3b &frame, cv::Mat2f &gradient); 145 | 146 | 147 | inline bool inside(int x, int y, int lbx, int lby, int ubx, int uby) 148 | { 149 | return lbx <= x && x < ubx && lby <= y && y < uby; 150 | } 151 | 152 | 153 | inline float disparity(float x, float y, const Plane &p) 154 | { 155 | return p[0]*x + p[1]*y + p[2]; 156 | } 157 | 158 | 159 | inline float weight(const cv::Vec3f &p, const cv::Vec3f &q, float gamma=10.0f) 160 | { 161 | return std::exp(-cv::norm(p-q, cv::NORM_L1) / gamma); 162 | } 163 | 164 | 165 | template 166 | inline T vecAverage(const T &x, const T &y, float wx) 167 | { 168 | return wx * x + (1 - wx) * y; 169 | } 170 | } 171 | 172 | #endif -------------------------------------------------------------------------------- /pm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define WINDOW_SIZE 35 5 | #define MAX_DISPARITY 60 6 | #define PLANE_PENALTY 120 7 | 8 | 9 | template 10 | Matrix2D::Matrix2D() {} 11 | 12 | template 13 | Matrix2D::Matrix2D(unsigned int rows, unsigned int cols) 14 | : rows(rows), cols(cols), data(rows, std::vector(cols)) { } 15 | 16 | template 17 | Matrix2D::Matrix2D(unsigned int rows, unsigned int cols, const T &def) 18 | : rows(rows), cols(cols), data(rows, std::vector(cols, def)) { } 19 | 20 | template 21 | inline T& Matrix2D::operator()(unsigned int row, unsigned int col) 22 | { 23 | return data[row][col]; 24 | } 25 | 26 | template 27 | inline const T& Matrix2D::operator()(unsigned int row, unsigned int col) const 28 | { 29 | return data[row][col]; 30 | } 31 | 32 | 33 | 34 | Plane::Plane() {} 35 | 36 | 37 | Plane::Plane(cv::Vec3f point, cv::Vec3f normal) : point(point), normal(normal) 38 | { 39 | float a = -normal[0] / normal[2]; 40 | float b = -normal[1] / normal[2]; 41 | float c = cv::sum(normal.mul(point))[0] / normal[2]; 42 | coeff = cv::Vec3f(a, b, c); 43 | } 44 | 45 | inline float Plane::operator[](int idx) const { return coeff[idx]; } 46 | 47 | inline cv::Vec3f Plane::operator()() { return coeff; } 48 | 49 | inline cv::Vec3f Plane::getPoint() { return point; } 50 | 51 | inline cv::Vec3f Plane::getNormal() { return normal; } 52 | 53 | inline cv::Vec3f Plane::getCoeff() { return coeff; } 54 | 55 | 56 | Plane Plane::viewTransform(int x, int y, int sign, int& qx, int &qy) 57 | { 58 | float z = coeff[0] * x + coeff[1] * y + coeff[2]; 59 | qx = x + sign * z; 60 | qy = y; 61 | 62 | cv::Vec3f p(qx, qy, z); 63 | return Plane(p, this->normal); 64 | } 65 | 66 | 67 | namespace pm 68 | { 69 | 70 | void compute_greyscale_gradient(const::cv::Mat3b &frame, cv::Mat2f &grad) 71 | { 72 | int scale = 1, delta = 0; 73 | cv::Mat gray, x_grad, y_grad; 74 | 75 | cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY); 76 | cv::Sobel(gray, x_grad, CV_32F, 1, 0, 3, scale, delta, cv::BORDER_DEFAULT); 77 | cv::Sobel(gray, y_grad, CV_32F, 0, 1, 3, scale, delta, cv::BORDER_DEFAULT); 78 | x_grad = x_grad / 8.f; 79 | y_grad = y_grad / 8.f; 80 | 81 | //#pragma omp parallel for 82 | for (int y = 0; y < frame.rows; ++y) { 83 | for (int x = 0; x < frame.cols; ++x) { 84 | grad(y, x)[0] = x_grad.at(y, x); 85 | grad(y, x)[1] = y_grad.at(y, x); 86 | } 87 | } 88 | } 89 | 90 | 91 | 92 | PatchMatch::PatchMatch(float alpha, float gamma, float tau_c, float tau_g) 93 | : alpha(alpha), gamma(gamma), tau_c(tau_c), tau_g(tau_g) { } 94 | 95 | 96 | 97 | float PatchMatch::dissimilarity(const cv::Vec3f &pp, const cv::Vec3f &qq, const cv::Vec2f &pg, const cv::Vec2f &qg) 98 | { 99 | float cost_c = cv::norm(pp - qq, cv::NORM_L1); 100 | float cost_g = cv::norm(pg - qg, cv::NORM_L1); 101 | cost_c = std::min(cost_c, this->tau_c); 102 | cost_g = std::min(cost_g, this->tau_g); 103 | return (1 - this->alpha) * cost_c + this->alpha * cost_g; 104 | } 105 | 106 | 107 | 108 | // aggregated matchig cost of a plane for a pixel 109 | float PatchMatch::plane_match_cost(const Plane &p, int cx, int cy, int ws, int cpv) 110 | { 111 | int sign = -1 + 2 * cpv; 112 | 113 | float cost = 0; 114 | int half = ws / 2; 115 | 116 | const cv::Mat3b& f1 = views[cpv]; 117 | const cv::Mat3b& f2 = views[1-cpv]; 118 | const cv::Mat2f& g1 = grads[cpv]; 119 | const cv::Mat2f& g2 = grads[1-cpv]; 120 | const cv::Mat& w1 = weigs[cpv]; 121 | 122 | for(int x = cx - half; x <= cx + half; ++x) 123 | { 124 | for(int y = cy - half; y <= cy + half; ++y) 125 | { 126 | if(!inside(x, y, 0, 0, f1.cols, f1.rows)) 127 | continue; 128 | 129 | //computing disparity 130 | float dsp = disparity(x, y, p); 131 | 132 | if(dsp < 0 || dsp > MAX_DISPARITY) 133 | { 134 | cost += PLANE_PENALTY; 135 | } 136 | else 137 | { 138 | // find matching point in other view 139 | float match = x + sign * dsp; 140 | int x_match = (int)match; 141 | 142 | float wm = 1 - (match - x_match); 143 | 144 | if(x_match > f1.cols - 2) 145 | x_match = f1.cols - 2; 146 | if(x_match < 0) 147 | x_match = 0; 148 | 149 | // and evaluating its color and gradinet (averaged) 150 | cv::Vec3b mcolo = vecAverage(f2(y, x_match), f2(y, x_match+1), wm); 151 | cv::Vec2b mgrad = vecAverage(g2(y, x_match), g2(y, x_match+1), wm); 152 | 153 | float w = w1.at(cv::Vec{cy, cx, y -cy +half, x -cx +half}); 154 | cost += w * dissimilarity(f1(y, x), mcolo, g1(y, x), mgrad); 155 | } 156 | } 157 | } 158 | 159 | return cost; 160 | } 161 | 162 | 163 | 164 | void PatchMatch::precompute_pixels_weights(const cv::Mat3b &frame, cv::Mat &weights, int ws) 165 | { 166 | int half = ws / 2; 167 | 168 | #pragma omp parallel for 169 | for(int cx=0; cx < frame.cols; ++cx) 170 | for(int cy=0; cy < frame.rows; ++cy) 171 | 172 | for(int x = cx - half; x <= cx + half; ++x) 173 | for(int y = cy - half; y <= cy + half; ++y) 174 | if(inside(x, y, 0, 0, frame.cols, frame.rows)) 175 | weights.at(cv::Vec {cy, cx, y -cy +half, x -cx +half}) = weight(frame(cy, cx), frame(y, x), this->gamma); 176 | } 177 | 178 | 179 | 180 | void PatchMatch::planes_to_disparity(const Matrix2D &planes, cv::Mat1f &disp) 181 | { 182 | //cv::Mat1f raw_disp(planes.rows, planes.cols); 183 | 184 | #pragma omp parallel for 185 | for(int x=0; x < cols; ++x) 186 | for(int y=0; y < rows; ++y) 187 | disp(y, x) = disparity(x, y, planes(y, x)); 188 | 189 | //cv::normalize(raw_disp, disp, 0, 255, cv::NORM_MINMAX, CV_8UC1); 190 | } 191 | 192 | 193 | 194 | void PatchMatch::initialize_random_planes(Matrix2D &planes, float max_d) 195 | { 196 | cv::RNG random_generator; 197 | const int RAND_HALF = RAND_MAX / 2; 198 | 199 | #pragma omp parallel for 200 | for(int y=0; y> offsets; 240 | 241 | if(iter%2 == 0) 242 | { 243 | offsets.push_back(std::make_pair(-1, 0)); 244 | offsets.push_back(std::make_pair(0, -1)); 245 | } 246 | else 247 | { 248 | offsets.push_back(std::make_pair(+1, 0)); 249 | offsets.push_back(std::make_pair(0, +1)); 250 | } 251 | 252 | int sign = (cpv == 0) ? -1 : 1; 253 | 254 | Plane& old_plane = planes[cpv](y, x); 255 | float& old_cost = costs[cpv](y, x); 256 | 257 | for(auto it = offsets.begin(); it < offsets.end(); ++it) 258 | { 259 | std::pair ofs = *it; 260 | 261 | int ny = y + ofs.first; 262 | int nx = x + ofs.second; 263 | 264 | if(!inside(nx, ny, 0, 0, cols, rows)) 265 | continue; 266 | 267 | Plane p_neigb = planes[cpv](ny, nx); 268 | float new_cost = plane_match_cost(p_neigb, x, y, WINDOW_SIZE, cpv); 269 | 270 | if(new_cost < old_cost) 271 | { 272 | old_plane = p_neigb; 273 | old_cost = new_cost; 274 | } 275 | } 276 | } 277 | 278 | 279 | 280 | void PatchMatch::view_propagation(int x, int y, int cpv) 281 | { 282 | int sign = (cpv == 0) ? -1 : 1; // -1 processing left, +1 processing right 283 | 284 | // current plane 285 | Plane view_plane = planes[cpv](y, x); 286 | 287 | // computing matching point in other view 288 | // reparameterized corresopndent plane in other view 289 | int mx, my; 290 | Plane new_plane = view_plane.viewTransform(x, y, sign, mx, my); 291 | 292 | if(!inside(mx, my, 0, 0, views[0].cols, views[0].rows)) 293 | return; 294 | 295 | // check if this reparameterized plane is better in the other view 296 | float& old_cost = costs[1-cpv](my, mx); 297 | float new_cost = plane_match_cost(new_plane, mx, my, WINDOW_SIZE, 1-cpv); 298 | 299 | if(new_cost < old_cost) 300 | { 301 | planes[1-cpv](my, mx) = new_plane; 302 | old_cost = new_cost; 303 | } 304 | } 305 | 306 | 307 | 308 | void PatchMatch::plane_refinement(int x, int y, int cpv, float max_delta_z, float max_delta_n, float end_dz) 309 | { 310 | int sign = (cpv == 0) ? -1 : 1; // -1 processing left, +1 processing right 311 | 312 | float max_dz = max_delta_z; 313 | float max_dn = max_delta_n; 314 | 315 | Plane& old_plane = planes[cpv](y, x); 316 | float& old_cost = costs[cpv](y, x); 317 | 318 | while(max_dz >= end_dz) 319 | { 320 | // Searching a random plane starting from the actual one 321 | std::random_device rd; 322 | std::mt19937 gen(rd()); 323 | 324 | std::uniform_real_distribution<> rand_z(-max_dz, +max_dz); 325 | std::uniform_real_distribution<> rand_n(-max_dn, +max_dn); 326 | 327 | float z = old_plane[0] * x + old_plane[1] * y + old_plane[2]; 328 | float delta_z = rand_z(gen); 329 | cv::Vec3f new_point(x, y, z + delta_z); 330 | 331 | cv::Vec3f n = old_plane.getNormal(); 332 | cv::Vec3f delta_n(rand_n(gen), rand_n(gen), rand_n(gen)); 333 | cv::Vec3f new_normal = n + delta_n; 334 | cv::normalize(new_normal, new_normal); 335 | 336 | // test the new plane 337 | Plane new_plane(new_point, new_normal); 338 | float new_cost = plane_match_cost(new_plane, x, y, WINDOW_SIZE, cpv); 339 | 340 | if(new_cost < old_cost) 341 | { 342 | old_plane = new_plane; 343 | old_cost = new_cost; 344 | } 345 | 346 | max_dz /= 2.0f; 347 | max_dn /= 2.0f; 348 | } 349 | } 350 | 351 | 352 | 353 | void PatchMatch::process_pixel(int x, int y, int cpv, int iter) 354 | { 355 | // spatial propagation 356 | spatial_propagation(x, y, cpv, iter); 357 | 358 | // plane refinement 359 | plane_refinement(x, y, cpv, MAX_DISPARITY/2, 1.0f, 0.1f); 360 | 361 | // view propagation 362 | view_propagation(x, y, cpv); 363 | } 364 | 365 | 366 | 367 | void PatchMatch::fill_invalid_pixels(int y, int x, Matrix2D &planes, const cv::Mat1b &validity) 368 | { 369 | int x_lft = x - 1; 370 | int x_rgt = x + 1; 371 | 372 | while(!validity(y, x_lft) && x_lft >= 0) 373 | --x_lft; 374 | 375 | while(!validity(y, x_rgt) && x_lft < cols) 376 | ++x_rgt; 377 | 378 | int best_plane_x = x; 379 | 380 | if(x_lft >= 0 && x_rgt < cols) 381 | { 382 | float disp_l = disparity(x, y, planes(y, x_lft)); 383 | float disp_r = disparity(x, y, planes(y, x_rgt)); 384 | best_plane_x = (disp_l < disp_r) ? x_lft : x_rgt; 385 | } 386 | else if(x_lft >= 0) 387 | best_plane_x = x_lft; 388 | else if(x_rgt < cols) 389 | best_plane_x = x_rgt; 390 | 391 | planes(y, x) = planes(y, best_plane_x); 392 | } 393 | 394 | 395 | 396 | void PatchMatch::weighted_median_filter(int cx, int cy, cv::Mat1f &disparity, const cv::Mat &weights, const cv::Mat1b &valid, int ws, bool use_invalid) 397 | { 398 | int half = ws / 2; 399 | float w_tot = 0; 400 | float w = 0; 401 | 402 | std::vector> disps_w; 403 | 404 | for(int x = cx-half; x <= cx + half; ++x) 405 | for(int y = cy-half; y <= cy + half; ++y) 406 | if(inside(x, y, 0, 0, cols, rows) && (use_invalid || valid(y, x))) 407 | { 408 | cv::Vec w_ids({cy, cx, y -cy +half, x -cx +half}); 409 | 410 | w_tot += weights.at(w_ids); 411 | disps_w.push_back(std::make_pair(weights.at(w_ids), disparity(y,x))); 412 | } 413 | 414 | std::sort(disps_w.begin(), disps_w.end()); 415 | 416 | float med_w = w_tot / 2.0f; 417 | 418 | for(auto dw=disps_w.begin(); dw < disps_w.end(); ++dw) 419 | { 420 | w += dw->first; 421 | 422 | if(w >= med_w) 423 | { 424 | if(dw == disps_w.begin()) 425 | { 426 | disparity(cy, cx) = dw->second; 427 | } 428 | else 429 | { 430 | disparity(cy, cx) = ((dw-1)->second + dw->second) / 2.0f; 431 | } 432 | //disparity(cy, cx) = dw->second; 433 | } 434 | } 435 | } 436 | 437 | 438 | void PatchMatch::operator()(const cv::Mat3b &img1, const cv::Mat3b &img2, int iterations, bool reverse) 439 | { 440 | this->set(img1, img2); 441 | this->process(iterations, reverse); 442 | this->postProcess(); 443 | } 444 | 445 | 446 | 447 | void PatchMatch::set(const cv::Mat3b &img1, const cv::Mat3b &img2) 448 | { 449 | this->views[0] = img1; 450 | this->views[1] = img2; 451 | 452 | this->rows = img1.rows; 453 | this->cols = img1.cols; 454 | 455 | // pixels neighbours weights 456 | std::cerr<<"Precomputing pixels weight...\n"; 457 | int wmat_sizes[] = {rows, cols, WINDOW_SIZE, WINDOW_SIZE}; 458 | this->weigs[0] = cv::Mat(4, wmat_sizes, CV_32F); 459 | this->weigs[1] = cv::Mat(4, wmat_sizes, CV_32F); 460 | precompute_pixels_weights(img1, this->weigs[0], WINDOW_SIZE); 461 | precompute_pixels_weights(img2, this->weigs[1], WINDOW_SIZE); 462 | 463 | // greyscale images gradient 464 | std::cerr<<"Evaluating images gradient...\n"; 465 | this->grads[0] = cv::Mat2f(rows, cols); 466 | this->grads[1] = cv::Mat2f(rows, cols); 467 | compute_greyscale_gradient(img1, this->grads[0]); 468 | compute_greyscale_gradient(img2, this->grads[1]); 469 | 470 | // pixels' planes random inizialization 471 | std::cerr<<"Precomputing random planes...\n"; 472 | this->planes[0] = Matrix2D(rows, cols); 473 | this->planes[1] = Matrix2D(rows, cols); 474 | this->initialize_random_planes(this->planes[0], MAX_DISPARITY); 475 | this->initialize_random_planes(this->planes[1], MAX_DISPARITY); 476 | 477 | // initial planes costs evaluation 478 | std::cerr<<"Evaluating initial planes cost...\n"; 479 | this->costs[0] = cv::Mat1f(rows, cols); 480 | this->costs[1] = cv::Mat1f(rows, cols); 481 | this->evaluate_planes_cost(0); 482 | this->evaluate_planes_cost(1); 483 | 484 | // left and right disparity maps 485 | this->disps[0] = cv::Mat1f(rows, cols); 486 | this->disps[1] = cv::Mat1f(rows, cols); 487 | } 488 | 489 | 490 | 491 | 492 | void PatchMatch::process(int iterations, bool reverse) 493 | { 494 | std::cerr <<"Processing left and right views...\n"; 495 | for(int iter = 0 + reverse; iter < iterations + reverse; ++iter) 496 | { 497 | bool iter_type = (iter % 2 == 0); 498 | std::cerr<<"Iteration "<= 0; --y) 512 | for(int x = cols-1; x >= 0; --x) 513 | process_pixel(x, y, work_view, iter); 514 | } 515 | } 516 | } 517 | std::cerr<planes_to_disparity(this->planes[0], this->disps[0]); 520 | this->planes_to_disparity(this->planes[1], this->disps[1]); 521 | } 522 | 523 | 524 | 525 | void PatchMatch::postProcess() 526 | { 527 | std::cerr<<"Executing post-processing...\n"; 528 | 529 | // checking pixels-plane disparity validity 530 | cv::Mat1b lft_validity(rows, cols, (unsigned char)false); 531 | cv::Mat1b rgt_validity(rows, cols, (unsigned char)false); 532 | 533 | // cv::Mat1b ld(rows, cols); 534 | // cv::Mat1b rd(rows, cols); 535 | 536 | for(int y=0; y < rows; ++y) 537 | { 538 | for(int x=0; x < cols; ++x) 539 | { 540 | int x_rgt_match = std::max(0.f, std::min((float)cols, x - disps[0](y, x))); 541 | lft_validity(y, x) = (std::abs(disps[0](y, x) - disps[1](y, x_rgt_match)) <= 1); 542 | 543 | int x_lft_match = std::max(0.f, std::min((float)rows, x + disps[1](y, x))); 544 | rgt_validity(y, x) = (std::abs(disps[1](y, x) - disps[0](y, x_lft_match)) <= 1); 545 | } 546 | } 547 | 548 | // cv::imwrite("l_inv.png", 255*lft_validity); 549 | // cv::imwrite("r_inv.png", 255*rgt_validity); 550 | 551 | // fill-in holes related to invalid pixels 552 | #pragma omp parallel for 553 | for(int y=0; y < rows; y++) 554 | { 555 | for (int x=0; x < cols; x++) 556 | { 557 | if (!lft_validity(y, x)) 558 | fill_invalid_pixels(y, x, planes[0], lft_validity); 559 | 560 | if (!rgt_validity(y, x)) 561 | fill_invalid_pixels(y, x, planes[1], rgt_validity); 562 | } 563 | } 564 | 565 | this->planes_to_disparity(this->planes[0], this->disps[0]); 566 | this->planes_to_disparity(this->planes[1], this->disps[1]); 567 | 568 | // cv::normalize(disps[0], ld, 0, 255, cv::NORM_MINMAX); 569 | // cv::normalize(disps[1], rd, 0, 255, cv::NORM_MINMAX); 570 | // cv::imwrite("ld2.png", ld); 571 | // cv::imwrite("rd2.png", rd); 572 | 573 | // applying weighted median filter to left and right view respectively 574 | for(int x=0; x