0

I am working on a project where I need to generate depth images from a point cloud. While I have come across examples in the literature that explains how to create a point cloud from a depth map, I'm specifically looking for guidance on the reverse process.

Can someone please provide insights or suggestions on how to create a depth map from a point cloud with Python programming language? Any relevant information, techniques, or resources would be greatly appreciated.

tolgabuyuktanir
  • 646
  • 6
  • 20
Valentyn
  • 659
  • 1
  • 7
  • 28
  • This question is too broad for Stack Overflow. "I want to do X" is not a question. Please ask a _specific_ question. Having attempted to solve your problem yourself usually helps in formulating a good question. See [what's on-topic here](/help/on-topic), [ask], the [question checklist](//meta.stackoverflow.com/q/260648/843953), and how to provide a [mre]. – Pranav Hosangadi Nov 29 '22 at 17:47
  • While I understand the concern raised by @PranavHosangadi, My question is not more general than other questions asked her. Please see https://stackoverflow.com/questions/64094463/how-can-i-generate-a-point-cloud-from-a-depth-image-and-rgb-image – Valentyn Nov 29 '22 at 18:01
  • If you want to do the reverse maybe you can try projection simply? I had projection related answer: https://stackoverflow.com/questions/43644656/converting-3d-point-cloud-to-a-2d-gridmap-on-python/73913607#73913607 – Shaig Hamzaliyev Nov 30 '22 at 08:30

1 Answers1

0

First of all, you need the intrinsic matrix of the camera. You can find fx, fy, cx, and cy values from the camera intrinsic matrix.

Example intrinsic matrix:

    # [ Fx, 0,  Cx,  Fx*-Tx ]
    # [ 0,  Fy, Cy,  0      ]
    # [ 0,  0,  1,   0      ]

Here is an example of creating a point cloud from a depth map.

    # read the depth image here and define intrinsic values

    fx = FX_DEPTH
    fy = FY_DEPTH
    cx = CX_DEPTH
    cy = CY_DEPTH

    x = (u - cx) / fx
    y = (v - cy) / fy
    z = image[v, u]
    x *= z
    y *= z
    z = z
    print(f"x: {x} y: {y} z: {z}")

But you are looking for a Python example of the reverse process. Here is the code of the reverse process:

    # read a point from the point cloud and define intrinsic values

    fx = FX_DEPTH
    fy = FY_DEPTH
    cx = CX_DEPTH
    cy = CY_DEPTH

    u = (x / z) * fx + cx
    v = (y / z) * fy + cy
    w, h = image.shape
    image[v, u] = z
    print(f"Position: {u} {v} Value:{image[u, v]}")

You can create the depth map if you iterate this code piece for all points.

tolgabuyuktanir
  • 646
  • 6
  • 20