ethnhe / raster_triangle

A simple renderer with z-buffer for synthesis data generating.
56 stars 20 forks source link

a error about your code (maybe) #5

Closed pyni closed 4 years ago

pyni commented 4 years ago

Hi, i found there maybe a error in your code. I think -1e8 should be 0. Otherwise, the mask may be all white.

ethnhe commented 4 years ago

It seems correct with the visualizing code as follows:

  189     ¦   ¦   from cv2 import imshow, waitKey
  190     ¦   ¦   imshow("bgr", bgr.astype("uint8"))
  191     ¦   ¦   show_zbuf = zbuf.copy()
  192     ¦   ¦   min_d, max_d = show_zbuf[show_zbuf > 0].min(), show_zbuf.max()
  193     ¦   ¦   show_zbuf[show_zbuf>0] = (show_zbuf[show_zbuf>0] - min_d) / (max_d - min_d) * 255
  194     ¦   ¦   show_zbuf = show_zbuf.astype(np.uint8)
  195     ¦   ¦   imshow("dpt", show_zbuf)
  196
  197     ¦   ¦   show_msk = (msk / msk.max() * 255).astype("uint8")
  198     ¦   ¦   imshow("msk", show_msk)
  199     ¦   ¦   waitKey(0)

rnd0

pyni commented 4 years ago

but i think msk = (zbuf>-1e8).astype('uint8') should be changed into: msk = (zbuf>0).astype('uint8') Otherwise, the result is shown as follows:

Screenshot from 2020-08-13 13-20-08

ethnhe commented 4 years ago

You're right, I forgot to update rgbd_renderer.py after updating rastertriangle_so.cpp. That line of code have been revised to msk = (zbuf>1e-8).astype('uint8') in the newest commit. I think >1e-8 is a better choice compared to >0 in float type data. Thanks for your contribution.

pyni commented 4 years ago

What a quick reply! You are welcome.