Skip to content

For training on a custom dataset #24

@higash1

Description

@higash1

Hello, thank you for the great work and for providing access to the normal maps!

Is the normal map generation in your issue from the following repository's code? #4 https://github.com/wassryan/Deeplidar_v2/blob/master/surface_normal/tool.cpp

Could you provide the series of codes from generating the normals from the lidarmap provided by KITTI?

I exected it with the following code. The results are attached.
`class NormalMap:
def init(self) -> None:
self.depth_map = None
self.normal_map = None
self.util_normal_map = np.zeros((375, 1242, 3), dtype=np.float32)
# for the kitti dataset
self.original_depth_path = '/home/NDdepth/Estimation/preprocess/0000000005.png'
self.original_normal_path = '/home/NDdepth/Estimation/preprocess/normal_0000000005.png'

    self.load_depth_map()
    self.load_original_normal_map()
    # print(self.normal_map[:,:,0].sum(axis=1))
    self.sparse_depth2normal(100)
    # self.convert()
    # self.answer()
    exit()
    # print(self.depth_map.sum(axis=0).sum(axis=0))
    # print(self.normal_map.sum(axis=0).sum(axis=0))

def load_depth_map(self):
    depth_map = cv2.imread(self.original_depth_path, cv2.IMREAD_UNCHANGED)
    depth_map = depth_map.astype(np.float32) / 255.0
    self.depth_map = depth_map

def load_original_normal_map(self):
    normal_map = cv2.imread(self.original_normal_path, cv2.IMREAD_UNCHANGED)
    normal_map = normal_map.astype(np.float32) / 255.0
    self.normal_map = normal_map
    
    # cv2.imwrite('normal.png', self.normal_map)
    cv2.imshow('normal', self.normal_map)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

def search_neighbor_x(self, img, i, j, circle_size):
    rows, cols = img.shape
    neighborx = -1
    for idx1 in range(circle_size):
        idx = idx1 + 1
        if i + idx >= rows:
            continue
        else:
            if img[i + idx, j] != 0.0:
                neighborx = i + idx
                break
    return neighborx

def search_neighbor_y(self, img, i, j, circle_size):
    rows, cols = img.shape
    neighbory = -1
    for idx1 in range(circle_size):
        idx = idx1 + 1
        if j + idx >= cols:
            continue
        else:
            if img[i, j + idx] != 0.0:
                neighbory = j + idx
                break
    return neighbory

def sparse_depth2normal(self, circle_size):
    f = 716.88
    cx , cy = 596.5593, 149.854
    # f = 518.8579
    # cx , cy = 607.1928, 161.2157
    normals = np.zeros_like(self.util_normal_map, dtype=np.float32)
    # depth = input.astype(np.float32)

    rows, cols = self.depth_map.shape

    for i in range(rows):
        for j in range(cols):
            if self.depth_map[i, j] != 0.0:
                neighborx = self.search_neighbor_x(self.depth_map, i, j, circle_size)
                neighbory = self.search_neighbor_y(self.depth_map, i, j, circle_size)
                if neighborx == -1 or neighbory == -1:
                    continue
                else:
                    x = (j - cx) * self.depth_map[i, j] / f
                    y = (i - cy) * self.depth_map[i, j] / f
                    z = self.depth_map[i, j]
                    x1 = (neighbory - cx) * self.depth_map[i, neighbory] / f
                    y1 = (i - cy) * self.depth_map[i, neighbory] / f
                    z1 = self.depth_map[i, neighbory]
                    x2 = (j - cx) * self.depth_map[neighborx, j] / f
                    y2 = (i + 1 - cy) * self.depth_map[neighborx, j] / f
                    z2 = self.depth_map[neighborx, j]
                    x3 = np.array([x1-x, y1-y, z1-z])
                    y3 = np.array([x2-x, y2-y, z2-z])
                    d:np.ndarray = np.cross(x3, y3)
                    n = d / np.linalg.norm(d)
                    normals[i, j, :] = n

    res = np.zeros_like(normals)
    res[:, :, 0] = -1.0 * normals[:, :, 0]
    res[:, :, 2] = -1.0 * normals[:, :, 1]
    res[:, :, 1] = -1.0 * normals[:, :, 2]

    mask = np.any(res != 0, axis=2)
    res[mask] += 1.0

    res *= 127.5
    res = res.astype(np.uint8)
    res = cv2.cvtColor(res, cv2.COLOR_BGR2RGB)
    self.util_normal_map = res
    # cv2.imwrite('make_normal.png', self.util_normal_map)
    cv2.imshow('normal', self.util_normal_map)
    cv2.waitKey(0)
    cv2.destroyAllWindows()`

your gt normal
normal_0000000005

my gt normal
make_normal

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions