-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
66 lines (55 loc) · 1.85 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
#include "pch.h"
#include "lib/plugin.h"
cv::Ptr<cv::StereoBM> m_StereoBM;
VOID DP_Process(
CONST IN cv::Mat &LeftImage,
CONST IN cv::Mat &RightImage,
OUT cv::Mat &DepthImage)
{
StereoDepthPerceptionLib::Compute(LeftImage, RightImage);
StereoDepthPerceptionLib::GetDepthImage(DepthImage);
}
VOID OCV_Process(
CONST IN cv::Mat &LeftImage,
CONST IN cv::Mat &RightImage,
OUT cv::Mat &DisparityImage)
{
cv::Mat GL, GR;
cv::cvtColor(LeftImage, GL, cv::COLOR_BGR2GRAY);
cv::cvtColor(RightImage, GR, cv::COLOR_BGR2GRAY);
m_StereoBM->compute(GL, GR, DisparityImage);
cv::normalize(DisparityImage, DisparityImage, 0, 255, cv::NORM_MINMAX, CV_8U);
}
int main()
{
std::string DATASET_PATH = "../res/02/";
cv::VideoCapture cam0, cam1, cam2;
cam0 = cv::VideoCapture(DATASET_PATH + "left/000000.png", cv::CAP_IMAGES);
cam1 = cv::VideoCapture(DATASET_PATH + "right/000000.png", cv::CAP_IMAGES);
std::cout << "Reading Dataset: " + DATASET_PATH << std::endl;
if (!cam0.isOpened() || !cam1.isOpened())
{
std::cerr << "ERROR READING DATASET" << std::endl;
return -1;
}
// OpenCV
m_StereoBM = cv::StereoBM::create();
m_StereoBM->setNumDisparities(32);
// CUDA
StereoDepthPerceptionLib::Setup(cv::Size(cam0.get(cv::CAP_PROP_FRAME_WIDTH), cam0.get(cv::CAP_PROP_FRAME_HEIGHT)));
cv::Mat LeftImage, RightImage, StereoImage, DepthImage, DisparityImage;
while (cam0.read(LeftImage) && cam1.read(RightImage))
{
auto TIME_START;
DP_Process(LeftImage, RightImage, DepthImage);
auto TIME_STOP;
OCV_Process(LeftImage, RightImage, DisparityImage);
cv::hconcat(LeftImage, RightImage, StereoImage);
cv::putText(StereoImage, "FPS: " + std::to_string(1 / TIME_RESULT), {10, 15}, 1, 1, CV_RGB(255, 0, 0));
cv::imshow("Stereo WebCam", StereoImage);
cv::imshow("Depth(CUDA)", DepthImage);
cv::imshow("Disparity(Open CV)", DisparityImage);
cv::waitKey(1);
}
return 0;
}