Commit ffc8640f authored by Vincent POLLET's avatar Vincent POLLET
Browse files

[WIP] stereo running on gpu

parent 98cb7b19
Pipeline #53902 failed with stage
in 28 minutes and 52 seconds
......@@ -24,6 +24,7 @@ class StereoParameters:
"""
STEREO_CV_SGBM = 0
CUDA_STEREO_BM = 1
def __init__( self,
algorithm = STEREO_CV_SGBM,
......
......@@ -96,8 +96,26 @@ def stereo_match(img_l, img_r, camera_pair, stereo_parameters=StereoParameters()
disparity = disparity.astype('float32')/16.0
else:
elif stereo_parameters.algorithm == stereo_parameters.CUDA_STEREO_BM:
if cv.cuda.getCudaEnabledDeviceCount() < 1:
raise Exception('No cuda device not avaible')
stereo = cv.cuda.createStereoBM(
numDisparities = stereo_parameters.num_disparities,
blockSize = stereo_parameters.block_size
)
cu_img_l = cv.cuda_GpuMat()
cu_img_l.upload(img_l)
cu_img_r = cv.cuda_GpuMat()
cu_img_r.upload(img_r)
disparity = stereo.compute(cu_img_l, cu_img_r, cv.cuda.Stream_Null()).download()
else:
raise Exception('Unknown stereo algorithm')
# inpaint depth map holes
......
......@@ -120,12 +120,19 @@ def test_stereo_mapping_and_project():
stereo_parameters.erode = True # remove small features
stereo_parameters.inpaint = True # fill holes
stereo_parameters.algorithm = 1
# Create 3D image
map_3d = stereo_match(left_image, right_image, camera_pair, stereo_parameters)
# project color image on left camera (rectified)
projected_image = reproject_image(color_image, map_3d, color, camera_pair, bounding_box, landmarks)
print(projected_image.shape)
np.save('cuda_stereo_output.npy', projected_image)
cv2.imwrite('cuda_stereo_output.png', np.moveaxis(projected_image, 0, -1))
# Compare to saved values
groundtruth_color_image = np.load(resource_path("test/data/projected_image.npy"))
groundtruth_map_3d = np.load(resource_path("test/data/map_3d.npy"))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment