-
-
Save mayosuke/7bc20e084e5a4326931ec38fca2fd77f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FOV = 90.0 | |
plane_depth = DepthConversion(depth, FOV) | |
plt.imshow(applyColorMap(plane_depth)) | |
H, W = depth.shape | |
x = np.arange(W) | |
y = H / 2 | |
plt.plot(x, depth[y,x],label='distance from camera center') | |
plt.plot(x, plane_depth[y,x],label='distance from camera plane') | |
plt.legend() | |
plt.title(f'depth(y={y})') | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Refs: https://github.com/unrealcv/unrealcv/issues/14 | |
import numpy as np | |
def DepthConversion(PointDepth, FOV): | |
H = PointDepth.shape[0] | |
W = PointDepth.shape[1] | |
f = W / 2 / np.tan(np.radians(FOV / 2)) | |
i_c = np.float(H) / 2 - 1 | |
j_c = np.float(W) / 2 - 1 | |
columns, rows = np.meshgrid(np.linspace(0, W-1, num=W), np.linspace(0, H-1, num=H)) | |
DistanceFromCenter = ((rows - i_c)**2 + (columns - j_c)**2)**(0.5) | |
PlaneDepth = PointDepth / (1 + (DistanceFromCenter / f)**2)**(0.5) | |
return PlaneDepth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import cv2 | |
from unrealcv import client | |
from io import BytesIO | |
def applyColorMap(npy, alpha=50): | |
return cv2.applyColorMap(cv2.convertScaleAbs(npy, alpha=alpha), cv2.COLORMAP_TURBO) | |
client.connect() | |
res = client.request('vget /camera/0/depth npy') | |
depth = np.load(BytesIO(res)) | |
plt.imshow(applyColorMap(depth)) | |
client.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment