Python Numpy Matrix -Multiplikation zur Koordinatentransformation ergibt ein falsches ErgebnisPython

Python-Programme
Anonymous
 Python Numpy Matrix -Multiplikation zur Koordinatentransformation ergibt ein falsches Ergebnis

Post by Anonymous »

Hier ist mein Code: Ich führe eine Koordinaten -Transformation auf einem Satz von 3D -Punkten durch. T < /code> ist meine
4 × 4 -Transformationsmatrix, die immer das Formular
erfüllt

Code: Select all

[[R , t], [ 0, 1]]
(Ich bin mir sicherlich sicher). Punkte ist der Satz von Punkten, die ich mit Form (m, 3)
verwandeln muss, wobei m normalerweise sehr groß ist (1k ~ 2k). Insbesondere die letzte Anzahl einiger der transformierten Punkte (pointa_local_homogenous) ist nicht gleich 1, das ist nicht korrekt. Wenn ich jedoch Methode 2 verwende, sind alle Ergebnisse korrekt.
# Method 1: wrong result.
ones = np.ones((points.shape[0], 1))
points_homogeneous = np.hstack((points, ones))
points_local_homogeneous = (T @ points_homogeneous.T).T
points_local = points_local_homogeneous[:, :3]
# Method 2: Good results.
points_local= (T[:3, :3] @ points.T).T + T[:3, 3]
< /code>
Es gibt auch ein seltsames Phänomen, das das Problem widerspiegelt: Wenn ich zuerst die Matrixmultiplikation durchführe und dann einen Punkt extrahiert, ist das Ergebnis falsch. Wenn ich jedoch zuerst den Punkt extrahiere und dann die Matrixmultiplikation durchführe, ist das Ergebnis korrekt. < /P>
>> (T @ points_homogeneous.T).T[547]
array([-15.44923687, -0.03295934, -0.07585889, -15.45439878])
>> T @ points_homogeneous[547]
array([6.58938647, 3.43626129, 2.84996901, 1. ])
< /code>
Kann mir jemand helfen, den Grund dafür zu verstehen? Jede Anleitung wäre sehr geschätzt!import numpy as np

T =np.array([[-9.99997984e-01, 2.00338436e-03, 1.36517526e-04,2.30385575e+01],
[-2.00432316e-03, -9.99971609e-01, -7.26382636e-03,3.48879370e+00],
[ 1.21961414e-04, -7.26408534e-03, 9.99973609e-01,-5.29494007e-02],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,1.00000000e+00]])
points = np.random.random((1000,3))
print(points)

ones = np.ones((points.shape[0], 1))
points_homogeneous = np.hstack((points, ones))
points_local_homogeneous = (T @ points_homogeneous.T).T
print(points_local_homogeneous)
points_local = points_local_homogeneous[:, :3]
print(points_local)
points_local= (T[:3, :3] @ points.T).T + T[:3, 3]
print(points_local)
< /code>
Ausgabe: < /p>
points:
[[0.70431115 0.18240672 0.33961428]
[0.03708955 0.67343087 0.82448419]
[0.56714298 0.73581627 0.6482321 ]
...
[0.57882963 0.04147515 0.05351834]
[0.67357367 0.02644866 0.19563735]
[0.86036017 0.27597764 0.63466743]]

points_local_homogeneous:
[[ 2.23346596e+01 3.30251359e+00 2.85416795e-01 1.00000000e+00]
[ 2.30029297e+01 2.80931870e+00 7.66625690e-01 1.00000000e+00]
[ 2.24729783e+01 2.74715294e+00 5.89989729e-01 1.00000000e+00]
...
[ 4.21157332e-01 -1.46142995e-03 9.03349144e-01 5.65885052e-01]
[ 3.26428767e-01 -1.54217777e-03 5.56317837e-01 4.18719365e-01]
[ 1.39730259e-01 -3.72909348e-03 6.30229075e+00 1.10249332e+00]]

points_local(Method 1):
[[ 2.23346596e+01 3.30251359e+00 2.85416795e-01]
[ 2.30029297e+01 2.80931870e+00 7.66625690e-01]
[ 2.24729783e+01 2.74715294e+00 5.89989729e-01]
...
[ 4.21157332e-01 -1.46142995e-03 9.03349144e-01]
[ 3.26428767e-01 -1.54217777e-03 5.56317837e-01]
[ 1.39730259e-01 -3.72909348e-03 6.30229075e+00]]

points_local(Method 2):
[[2.23346596e+01 3.30251359e+00 2.85416795e-01]
[2.30029297e+01 2.80931870e+00 7.66625690e-01]
[2.24729783e+01 2.74715294e+00 5.89989729e-01]
...
[2.24598194e+01 3.44577082e+00 3.36839801e-04]
[2.23650649e+01 3.45957466e+00 1.42572815e-01]
[2.21788386e+01 3.20648934e+00 5.79801482e-01]]
< /code>
Die letzte Spalte von Punkten, die lokale Homogeneous 1,0000 betragen, sollte jedoch nicht sein, und das Ergebnis von Methode 1 und Methode 2 ist unterschiedlich. Ich weiß nicht warum?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post