-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
59 lines (44 loc) · 1.58 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
#include "depth_anything_trtruntime/trt_module.h"
#include <opencv2/opencv.hpp>
int main() {
// 替换为你的视频文件路径
std::string video_path = "../data/pocket3_night.mp4";
TRTModule model("../weights/depth_anything_vits14-sim-ptq-f16.plan");
// TRTModule model("../weights/depth_anything_vits14.engine");
cv::VideoCapture cap(video_path);
// 检查视频是否成功打开
if (!cap.isOpened()) {
std::cerr << "Error: Could not open video file." << std::endl;
return -1;
}
cv::Mat frame;
cv::Mat colored_depth;
cv::namedWindow("depth anything", cv::WINDOW_NORMAL);
cv::resizeWindow("depth anything", cv::Size(960, 1080));
while (true) {
cap >> frame; // 读取一帧
// 检查是否到达视频末尾
if (frame.empty()) {
std::cout << "End of video." << std::endl;
break;
}
// 在这里添加你的 TensorRT 模型的推理代码
// std::cout << "start infer" << std::endl;
cv::Mat depth = model.predict(frame);
// std::cout << "finish infer" << std::endl;
// 将深度图应用颜色映射
cv::applyColorMap(depth, colored_depth, cv::COLORMAP_INFERNO);
// 显示当前帧和深度图
cv::Mat showImage;
cv::vconcat(frame, colored_depth, showImage);
cv::imshow("depth anything", showImage);
// 按 ESC 键退出循环
if (cv::waitKey(1) == 27) {
break;
}
}
// 关闭视频流
cap.release();
cv::destroyAllWindows();
return 0;
}