vedo icon indicating copy to clipboard operation
vedo copied to clipboard

Multi view camera rendering settings

Open LogWell opened this issue 3 years ago • 15 comments

How to set such a scene: https://wuminye.github.io/NHR/datasets.html image

This is a relatively common schematic diagram in the current multi-view research field (such as NeRF), and I hope to add a class of such an example.

LogWell avatar Oct 18 '22 07:10 LogWell

The primitives can be corresponding images, or cameras like: https://www-users.cse.umn.edu/~hspark/CSci5980/csci5980_3dvision.html image

LogWell avatar Oct 18 '22 08:10 LogWell

if you have the individual images and orientations in space you can create

pict1 = Picture("pic1.jpg")
pict1.orientation(pic1_vector)
pict1.pos(pic1_position)
...

marcomusy avatar Oct 18 '22 10:10 marcomusy

In addition, can I define a structure that contains an image and a wireframe model of the camera, and then treat this as a whole and place it somewhere and set the orientation?

image

LogWell avatar Oct 21 '22 04:10 LogWell

You can use an Assembly object to treat multiple objects as a single one:

from vedo import *

pic = Picture(dataurl + "images/dog.jpg")
dz = 800
x0, x1, y0, y1, _, _ = pic.bounds()
cam = [(x0 + x1) / 2, (y0 + y1) / 2, dz]

lines = Lines(
    [
        [cam, (x0, y0, 0)],
        [cam, (x1, y0, 0)],
        [cam, (x0, y1, 0)],
        [cam, (x1, y1, 0)],
    ],
    c="black",
    lw=2,
)

assem = Assembly([pic, lines, Point(cam)])
assem.orientation([0, -1, 0])

show(assem, axes=1)

Screenshot from 2022-10-21 15-43-05

marcomusy avatar Oct 21 '22 13:10 marcomusy

How to access the four corners of Picture, I do not find in picture.py and base.py, because the pic may not be axis aligned after some transformations.

LogWell avatar Oct 22 '22 06:10 LogWell

You can do it with print(assem.unpack(0).bounds())

marcomusy avatar Oct 22 '22 10:10 marcomusy

Emm, Bounds and Corner are different if I do some transformations like:

pic.origin((1, 2, 2))
pic.orientation((0.2, -0.1, 0.3))

so I wonder if there are any ready-made functions that can be used. image

LogWell avatar Oct 22 '22 11:10 LogWell

You should transform the assem obj not the pic. I suggest not to use orientation() as it's ignoring origin() (bug). and also there is another small bug about obj.transform to being filled for pure rotations...

from vedo import *

settings.use_depth_peeling = True

pic = Picture(dataurl + "images/dog.jpg")
dz = 800
x0, x1, y0, y1, _, _ = pic.bounds()
cam = [(x0 + x1) / 2, (y0 + y1) / 2, dz]

lines = Lines(
    [
        [cam, (x0, y0, 0)],
        [cam, (x1, y0, 0)],
        [cam, (x0, y1, 0)],
        [cam, (x1, y1, 0)],
    ],
    c="black",
    lw=2,
)

corners = Points([(x0, y0), (x1,y0), (x0,y1), (x1,y1)])

assem = Assembly([corners, pic, lines, Point(cam)])
#assem.orientation([1, -1, -2]) # do not use

assem.origin(cam)
assem.rotate_y(90)
assem.rotate_z(-70)
assem.rotate_y(-90)

# T = assem.transform  # not filled (bug), workaround:
T = assem.GetMatrix()

corner_pts = corners.clone().apply_transform(T).points()
print(corner_pts)

show(assem, axes=1)
Screenshot 2022-10-22 at 17 12 48

marcomusy avatar Oct 22 '22 15:10 marcomusy

Got it ^_^

LogWell avatar Oct 22 '22 15:10 LogWell

...also it's probably easier if you use around to define a pivoting point instead of origin:


assem.rotate_y(+90, around=cam)
assem.rotate_z(-90, around=cam)
assem.rotate_y(-90, around=cam)

# instead of:
# assem.origin(cam)
# assem.rotate_y(+90)
# assem.rotate_z(-90)
# assem.rotate_y(-90)

to make the cam the pivoting point. I must see if there is a more intuitive/natural way for the API as these rotations are a bit tricky...

marcomusy avatar Oct 22 '22 15:10 marcomusy

How to handle this boundary when I turn to the back? image

LogWell avatar Oct 22 '22 16:10 LogWell

sorry I don't understand the question.

marcomusy avatar Oct 22 '22 17:10 marcomusy

When I scale this down to around 1, the image plane and the line will penetration: Note the four corners: image

from vedo import *

settings.use_depth_peeling = True

pic = Picture(dataurl + "images/dog.jpg")
dz = -1000
if True:
    dz = -0.05
    dim = pic.dimensions()
    pic = pic.scale(2 / np.max(dim) * 0.1) 
x0, x1, y0, y1, _, _ = pic.bounds()
cam = [(x0 + x1) / 2, (y0 + y1) / 2, dz]

lines = Lines(
    [
        [cam, (x0, y0, 0)],
        [cam, (x1, y0, 0)],
        [cam, (x0, y1, 0)],
        [cam, (x1, y1, 0)],
    ],
    c="black",
    lw=1.2,
)

assem = Assembly([pic, lines])
assem.origin(cam)
show(assem, axes=0)

LogWell avatar Oct 23 '22 02:10 LogWell

I think this is a problem with vtk that has been solved in vtk9.2.2, so I would try: pip install vtk -U

marcomusy avatar Oct 23 '22 10:10 marcomusy

After the upgrade, I still have this problem. But I can use a larger scale to temporarily circumvent this problem.

LogWell avatar Oct 23 '22 10:10 LogWell