h-cha / unity_to_instant-ngp

0 stars 0 forks source link

正規化する #7

Open h-cha opened 1 year ago

h-cha commented 1 year ago

opengl unity

h-cha commented 1 year ago

https://github.com/NVlabs/instant-ngp/blob/090aed613499ac2dbba3c2cede24befa248ece8a/scripts/colmap2nerf.py#L342C5-L353C32

import numpy as np

print("flip coordinates ...")

c2w =  [
    [0.9977, -0.0647, -0.02016, -0.10793465059103907],
    [-0.00198, -0.32523, 0.94563, 3.7799645259408403],
    [0.06774, 0.94342, 0.32461, 1.299197965401564],
    [0.0, 0.0, 0.0, 1.0]
]

c2w = np.array(c2w)  # リストをNumPy配列に変換

c2w[0:3, 2] *= -1
print(c2w)
print("a")
c2w[0:3, 1] *= -1
print(c2w)
print("a")
c2w = c2w[[1, 0, 2, 3], :]
print(c2w)
print("a")
c2w[2, :] *= -1
print(c2w)
print("a")
h-cha commented 1 year ago

出力結果

flip coordinates ...
[[ 9.97700000e-01 -6.47000000e-02  2.01600000e-02 -1.07934651e-01]
 [-1.98000000e-03 -3.25230000e-01 -9.45630000e-01  3.77996453e+00]
 [ 6.77400000e-02  9.43420000e-01 -3.24610000e-01  1.29919797e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00  1.00000000e+00]]
a
[[ 9.97700000e-01  6.47000000e-02  2.01600000e-02 -1.07934651e-01]
 [-1.98000000e-03  3.25230000e-01 -9.45630000e-01  3.77996453e+00]
 [ 6.77400000e-02 -9.43420000e-01 -3.24610000e-01  1.29919797e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00  1.00000000e+00]]
a
[[-1.98000000e-03  3.25230000e-01 -9.45630000e-01  3.77996453e+00]
 [ 9.97700000e-01  6.47000000e-02  2.01600000e-02 -1.07934651e-01]
 [ 6.77400000e-02 -9.43420000e-01 -3.24610000e-01  1.29919797e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00  1.00000000e+00]]
a
[[-1.98000000e-03  3.25230000e-01 -9.45630000e-01  3.77996453e+00]
 [ 9.97700000e-01  6.47000000e-02  2.01600000e-02 -1.07934651e-01]
 [-6.77400000e-02  9.43420000e-01  3.24610000e-01 -1.29919797e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00  1.00000000e+00]]
a
h-cha commented 1 year ago
flip_mat = np.array([
    [1, 0, 0, 0],
    [0, -1, 0, 0],
    [0, 0, -1, 0],
    [0, 0, 0, 1]
])

c2w =  [
    [0.9977, -0.0647, -0.02016, -0.10793465059103907],
    [-0.00198, -0.32523, 0.94563, 3.7799645259408403],
    [0.06774, 0.94342, 0.32461, 1.299197965401564],
    [0.0, 0.0, 0.0, 1.0]
]
print(np.matmul(c2w, flip_mat)) # flip cameras (it just works)

出力結果

[[ 9.97700000e-01  6.47000000e-02  2.01600000e-02 -1.07934651e-01]
 [-1.98000000e-03  3.25230000e-01 -9.45630000e-01  3.77996453e+00]
 [ 6.77400000e-02 -9.43420000e-01 -3.24610000e-01  1.29919797e+00]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00  1.00000000e+00]]
h-cha commented 1 year ago

unity_generate_transform_mat2_rotate90_flip_yz.py flip_mat = np.array([ [1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1] ])

h-cha commented 1 year ago

File (2) File (3)

h-cha commented 1 year ago

https://github.com/NVlabs/instant-ngp/blob/090aed613499ac2dbba3c2cede24befa248ece8a/scripts/colmap2nerf.py#L343C6-L349C1 File (4)

h-cha commented 1 year ago

https://github.com/NVlabs/instant-ngp/blob/090aed613499ac2dbba3c2cede24befa248ece8a/scripts/colmap2nerf.py#L369C3-L378C1

up = up / np.linalg.norm(up) PythonでベクトルをL2正規化(normalization)する方法一覧