-
Notifications
You must be signed in to change notification settings - Fork 51
/
main.cpp
71 lines (57 loc) · 1.48 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <opencv2/opencv.hpp>
#include <pm.h>
bool check_image(const cv::Mat &image, std::string name="Image")
{
if(!image.data)
{
std::cerr <<name <<" data not loaded.\n";
return false;
}
return true;
}
bool check_dimensions(const cv::Mat &img1, const cv::Mat &img2)
{
if(img1.cols != img2.cols or img1.rows != img2.rows)
{
std::cerr << "Images' dimensions do not corresponds.";
return false;
}
return true;
}
int main(int argc, char** argv)
{
const float alpha = 0.9f;
const float gamma = 10.0f;
const float tau_c = 10.0f;
const float tau_g = 2.0f;
// Reading images
cv::Mat3b img1 = cv::imread(argv[1], cv::IMREAD_COLOR);
cv::Mat3b img2 = cv::imread(argv[2], cv::IMREAD_COLOR);
// Image loading check
if(!check_image(img1, "Image 1") or !check_image(img2, "Image 2"))
return 1;
// Image sizes check
if(!check_dimensions(img1, img2))
return 1;
// processing images
pm::PatchMatch patch_match(alpha, gamma, tau_c, tau_g);
patch_match.set(img1, img2);
patch_match.process(3);
patch_match.postProcess();
cv::Mat1f disp1 = patch_match.getLeftDisparityMap();
cv::Mat1f disp2 = patch_match.getRightDisparityMap();
cv::normalize(disp1, disp1, 0, 255, cv::NORM_MINMAX);
cv::normalize(disp2, disp2, 0, 255, cv::NORM_MINMAX);
try
{
cv::imwrite("left_disparity.png", disp1);
cv::imwrite("right_disparity.png", disp2);
}
catch(std::exception &e)
{
std::cerr << "Disparity save error.\n" <<e.what();
return 1;
}
return 0;
}