Closed aminzabardast closed 5 years ago
A code to convert the mesh can be found in previous tasks (#47) Try blurring the disparity map before creating the mesh.
The following code can convert the disparity into a mesh. The only problem is that we dont know how much each pixel should be! It must be possible to extract this from camera parameters. Dont know how yet.
import numpy as np
import matplotlib.tri as mtri
from stl import mesh
from IO import read
import scipy.ndimage as ndimage
file_name = null # Address of the file
accuracy = 5 # How many pixels to jump
blur_kernel = 9 # Blur the input by a uniform kernel of sthis size
pixel_size = 10 # The size each pixel corresponsd to
# Generating an equally spaced grid
x = np.arange(0, 512, accuracy)
x, y = np.meshgrid(x, x)
x = x.flatten()
y = y.flatten()
# Generating depth and magnifying the values since their absolute value is less than 1
z = read(file='{}.pfm'.format(file_name))[512:0:-accuracy, 0:512:accuracy]
z = ndimage.uniform_filter(z, size=blur_kernel)
z = z.flatten()*pixel_size
# Creating triangles from point (x, y) point cloud.
tries = mtri.Triangulation(x, y)
# Creating Mesh in the size of triangles
data = np.zeros(len(tries.triangles), dtype=mesh.Mesh.dtype)
mesh = mesh.Mesh(data, remove_empty_areas=False)
# Populating the mesh
mesh.x[:] = x[tries.triangles]
mesh.y[:] = y[tries.triangles]
mesh.z[:] = z[tries.triangles]
# Saving the mesh
mesh.save('{}.stl'.format(file_name))
A good starting point will be TMI Dataset