-
Notifications
You must be signed in to change notification settings - Fork 8
/
StereoBMDisparityEstimator.cpp
63 lines (47 loc) · 1.68 KB
/
StereoBMDisparityEstimator.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
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui/highgui.hpp> // for debugging
#include "StereoBMDisparityEstimator.h"
#include "ImageRenderer3.h"
const float StereoBMDisparityEstimator::ALPHA = 1.0;
const Vec2i StereoBMDisparityEstimator::LEFT_POSITION = Vec2i(0,0);
const Vec2i StereoBMDisparityEstimator::RIGHT_POSITION = Vec2i(5,0);
StereoBMDisparityEstimator::StereoBMDisparityEstimator(void)
{
}
StereoBMDisparityEstimator::~StereoBMDisparityEstimator(void)
{
}
Mat StereoBMDisparityEstimator::estimateDepth(const LightFieldPicture lightfield)
{
// render images
ImageRenderer3 renderer = ImageRenderer3();
renderer.setLightfield(lightfield);
renderer.setAlpha(ALPHA);
renderer.setPinholePosition(StereoBMDisparityEstimator::LEFT_POSITION);
Mat image1 = renderer.renderImage();
cvtColor(image1, image1, CV_RGB2GRAY);
image1.convertTo(image1, CV_8UC1, 255.0);
renderer.setPinholePosition(StereoBMDisparityEstimator::RIGHT_POSITION);
Mat image2 = renderer.renderImage();
cvtColor(image2, image2, CV_RGB2GRAY);
image2.convertTo(image2, CV_8UC1, 255.0);
// estimate disparity
Mat disparity;
StereoBM stereo = StereoBM(StereoBM::BASIC_PRESET, 32, 21);
stereo(image1, image2, disparity, CV_32F);
/* start of debugging code */
const int windowFlags = WINDOW_NORMAL;
const string window1 = "image1";
namedWindow(window1, windowFlags);
imshow(window1, image1);
const string window2 = "image2";
namedWindow(window2, windowFlags);
imshow(window2, image2);
const string window3 = "disparity map";
namedWindow(window3, windowFlags);
imshow(window3, disparity);
waitKey(0);
/* end of debugging code */
return disparity;
}