forked from Jkotoun/ZPO_stereo_depth_estimation_methods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
73 lines (62 loc) · 2.24 KB
/
demo.py
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
# author: Josef Kotoun
import cv2
import numpy as np
import matplotlib.pyplot as plt
from src.methods.semiglobal_block_matching import SemiglobalBlockMatching
from src.methods.block_matching import BlockMatchingOpenCV, BlockMatching
from src.methods.hitnet import HitNet
from src.methods.depth_anything import DepthAnything
def plot_disparities(disparitySGBM, disparityBM_opencv):
# plt.figure()
# plt.title("BM")
# # plt.imshow(disparityBM, cmap='jet')
# plt.colorbar()
plt.figure()
plt.title("SGBM")
plt.imshow(disparitySGBM, cmap='jet')
plt.colorbar()
plt.figure()
plt.title("BM_opencv")
plt.imshow(disparityBM_opencv, cmap='jet')
plt.colorbar()
plt.show()
if __name__ == "__main__":
bm = BlockMatchingOpenCV(blockSize=5, maxDisparity=32)
bm_ours = BlockMatching(blockSize=5, maxDisparity=32)
sgbm = SemiglobalBlockMatching(blockSize=3, maxDisparity=32)
hitnet = HitNet(r"models\flyingthings_finalpass_xl.pb")
depth_anything = DepthAnything("small")
# Path to the left input image
left_image_path = './test_images/downsized/img2_left.png'
# Path to the right input image
right_image_path = './test_images/downsized/img2_right.png'
imgLeft = cv2.imread(left_image_path)
imgRight = cv2.imread(right_image_path)
# disparity_SGBM = sgbm.process(imgLeft, imgRight)
disparity_BM = bm.process(imgLeft, imgRight).squeeze(0)
plt.figure()
plt.title("BM_opencv")
plt.imshow(disparity_BM, cmap='jet')
plt.colorbar()
disparity_SGBM = sgbm.process(imgLeft, imgRight).squeeze(0)
plt.figure()
plt.title("SGBM")
plt.imshow(disparity_SGBM, cmap='jet')
plt.colorbar()
disparity_HITNET = hitnet.process(imgLeft, imgRight).squeeze(0)
plt.figure()
plt.title("HitNet")
plt.imshow(disparity_HITNET, cmap='jet')
plt.colorbar()
disparity_DEPTH_ANYTHING = depth_anything.process(imgLeft)
plt.figure()
plt.title("DepthAnything")
plt.imshow(disparity_DEPTH_ANYTHING)
plt.colorbar()
disparity_BM_ours = bm_ours.process(imgLeft, imgRight).squeeze(0)
plt.figure()
plt.title("BM_ours")
plt.imshow(disparity_BM_ours, cmap='jet')
plt.colorbar()
plt.show()
# plot_disparities(disparity_SGBM, disparity_BM)