FS-Driverless / FS-Driverless/Formula-Student-Driverless-Simulator

Further development of the depth camera simulation

Open
#187 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
286
Forks
126
PR merge metrics
No merged PRs in 30d

Description

Following up to issue #153 which added depth cameras in pull request #181. General information on how the depth cameras are working can be found in #153.

Maybe it would not be so computationally challenging to simulate the infrared "projected points" and then interpolate between them to get that accuracy gradient with higher precision close by and worse far away. The Intel Realsense camera has an algorithm that it can execute on-board in real time, basic info here:
https://www.intelrealsense.com/stereo-depth-vision-basics/

**Sample:**
```
import numpy
import cv2

from matplotlib import pyplot as plt
from matplotlib import cm

left = cv2.imread("l_active.png", cv2.IMREAD_GRAYSCALE)
right = cv2.imread("r_active.png", cv2.IMREAD_GRAYSCALE)

fx = 942.8 # lense focal length
baseline = 54.8 # distance in mm between the two cameras
disparities = 128 # num of disparities to consider
block = 31 # block size to match
units = 0.512 # depth units, adjusted for the output to fit in one byte

sbm = cv2.StereoBM_create(numDisparities=disparities,
blockSize=block)

# calculate disparities
disparity = sbm.compute(left, right)
valid_pixels = disparity > 0

# calculate depth data
depth = numpy.zeros(shape=left.shape).astype("uint8")
depth[valid_pixels] = (fx * baseline) / (units * disparity[valid_pixels])

# visualize depth data
depth = cv2.equalizeHist(depth)
colorized_depth = numpy.zeros((left.shape[0], left.shape[1], 3), dtype="uint8")
temp = cv2.applyColorMap(depth, cv2.COLORMAP_JET)
colorized_depth[valid_pixels] = temp[valid_pixels]
plt.imshow(colorized_depth)
plt.show()

```
**Input:**
_left lens_
![l_active](https://user-images.githubusercontent.com/22589593/88484877-4b040f00-cf72-11ea-958d-6f0a1d93b72b.png)
_right lens_
![r_active](https://user-images.githubusercontent.com/22589593/88484878-4b9ca580-cf72-11ea-973c-591f6649ab24.png)

**Output:**
![image](https://user-images.githubusercontent.com/22589593/88485190-50625900-cf74-11ea-8288-465836b25562.png)

**Source:**
[source.zip](https://github.com/FS-Online/Formula-Student-Driverless-Simulator/files/4977967/source.zip)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.