-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmain.cpp
84 lines (65 loc) · 2.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <bits/stdc++.h>
#include <fstream>
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <chrono>
#include "visualization.h"
#include "BisenetTensorRT.h"
#include "PointPainting.h"
int main(int argc, char** argv)
{
std::string enginePath = "../bisenet_tensorrt.trt";
if (argc > 1)
enginePath = argv[1];
auto bisenet = BiseNetTensorRT(enginePath);
auto painter = PointPainter();
auto visualizer = Visualizer();
std::string rootPath = "../data/";
std::string savePointcloudsPath = "../data/results_pointclouds/";
std::string rootImagesPath = rootPath + "image_2";
std::string rootPointcloudsPath = rootPath + "velodyne";
// read the images & pointclouds paths
std::vector<std::string> imagesPaths;
std::vector<std::string> pointcloudsPaths;
for (const auto & entry : std::filesystem::directory_iterator(rootImagesPath))
imagesPaths.push_back(entry.path().string());
for (const auto & entry : std::filesystem::directory_iterator(rootPointcloudsPath))
pointcloudsPaths.push_back(entry.path().string());
std::sort(imagesPaths.begin(), imagesPaths.end());
std::sort(pointcloudsPaths.begin(), pointcloudsPaths.end());
// loop over samples
for (int i = 0; i < imagesPaths.size(); i++)
{
// read image
std::string imagePath = imagesPaths[i];
cv::Mat image = cv::imread(imagePath, cv::ImreadModes::IMREAD_COLOR);
// read pointcloud
std::string pointcloudPath = pointcloudsPaths[i];
std::vector<Point> pointcloud = loadPointCloud(pointcloudPath);
auto t1 = std::chrono::system_clock::now();
// do inference
cv::Mat semantic = bisenet.Inference(image);
auto t2 = std::chrono::system_clock::now();
// pointpainting
painter.Paint(pointcloud, semantic);
auto t3 = std::chrono::system_clock::now();
std::cout << "Bisenetv2 = " << std::chrono::duration<double>(t2-t1).count() * 1e3 << " ms" << std::endl;
std::cout << "PointPainting = " << std::chrono::duration<double>(t3-t2).count() * 1e3 << " ms" << std::endl;
std::cout << "Total Inference = " << std::chrono::duration<double>(t3-t1).count() * 1e3 << " ms" << std::endl;
savePointCloud(pointcloud, savePointcloudsPath + to_string(i) + ".bin");
// visualization
cv::Mat coloredSemantic;
visualizer.ConvertToSemanticMap(semantic, coloredSemantic);
cv::imshow("coloredSemantic", coloredSemantic);
// cv::imshow("image", image);
// just for visualization ,add 20 to brightness the image, as ids is [0-19] which is really dark
// semantic.convertTo(semantic,CV_8UC1, 1, 20);
// cv::imshow("semantic", semantic);
if (cv::waitKey(0) == 27)
{
cv::destroyAllWindows();
return 0;
}
}
return 0;
}