DIYer22 / bpycv

Computer vision utils for Blender (generate instance annoatation, depth and 6D pose by one line code)
MIT License
464 stars 58 forks source link

Adding PNG background #24

Closed shadowwkl closed 2 years ago

shadowwkl commented 2 years ago

Dear authors,

Very nice work! I wonder how to add a png image as background, such as empty box/bin for training robotic arms? Thanks for your answering!

DIYer22 commented 2 years ago

Two ways.

  1. Add a Mesh/Plane with png as texture. And put it on background, then render scene.
  2. Cut-paste foreground on background image accroding to instance map.
shadowwkl commented 2 years ago

Two ways.

  1. Add a Mesh/Plane with png as texture. And put it on background, then render scene.
  2. Cut-paste foreground on background image accroding to instance map.

Could you please tell me more detail w.r.t. your first suggestion? I am new in the 3d filed, thanks! The code loads background via a .hdri image and 'load_hdri_world()'. What I have done is transferring a png image to hdr image, then loading it. The problem is that the generated background is just a patch of the original png image, which is not ideal. The ideal case is all the objects falling inside of an open box/bin.

DIYer22 commented 2 years ago

load_hdri_world is to load hdri file which is 360 degree panorama photo. It's a wrong choice to load a 2d image.
You could learn basic Blender tutorial. Then do "Adding PNG background" by GUI, and writing python code according to example code in info pannel.

shadowwkl commented 2 years ago

load_hdri_world is to load hdri file which is 360 degree panorama photo. It's a wrong choice to load a 2d image. You could learn basic Blender tutorial. Then do "Adding PNG background" by GUI, and writing python code according to example code in info pannel.

Thanks for your reply! I can load 2d image as background via GUI, but I wonder how can write a code, like 'load_hdri_world' does, to load 2d image as background, so that it can automatically generate images? For the second option, the edges (object and background) are quite clear, the network can capture it as a short cut I guess, then the performance on real-world images may not be good.

DIYer22 commented 2 years ago

I have updated code, Now, bpycv support this by

plane = add_img_background("/a/b.jpg", size=2)

Sorce code: https://github.com/DIYer22/bpycv/commit/3768e3efdedb328b64df84f7edb4e5cf6fb7e0b4