Tina Ch Tina Ch - 25 days ago 12
Python Question

Calculate homography on Python

I'm trying to to setup a homogenous set of equations using the corresponding 2D and 3D points. And then solve equestion.

pts2d = np.array([[1.0486, -0.3645], [-1.6851, -0.4004], [-0.9437, -0.42], [1.0682, 0.0699], [0.6077, -0.0771], [1.2543, -0.6454], [-0.2709, 0.8635], [-0.4571, -0.3645], [-0.7902, 0.0307], [0.7318, 0.6382], [-1.058, 0.3312], [0.3464, 0.3377], [0.3137, 0.1189], [-0.431, 0.0242], [-0.4799, 0.292], [0.6109, 0.083], [-0.4081, 0.292], [-0.1109, -0.2992], [0.5129, -0.0575], [0.1406, -0.4527]])
pts3d = np.array([[1.5706, -0.149, 0.2598], [-1.5282, 0.9695, 0.3802], [-0.6821, 1.2856, 0.4078], [0.4124, -1.0201, -0.0915], [1.2095, 0.2812, -0.128], [0.8819, -0.8481, 0.5255], [-0.9442, -1.1583, -0.3759], [0.0415, 1.3445, 0.324], [-0.7975, 0.3017, -0.0826], [-0.4329, -1.4151, -0.2774], [-1.1475, -0.0772, -0.2667], [-0.5149, -1.1784, -0.1401], [0.1993, -0.2854, -0.2114], [-0.432, 0.2143, -0.1053], [-0.7481, -0.384, -0.2408], [0.8078, -0.1196, -0.2631], [-0.7605, -0.5792, -0.1936], [0.3237, 0.797, 0.217], [1.3089, 0.5786, -0.1887], [1.2323, 1.4421, 0.4506]])
u = pts2d[:,0]
v = pts2d[:,1]
X = pts3d[:,0]
Y = pts3d[:,1]
Z = pts3d[:,2]
A = np.zeros(40,12)
for i in range[1:2:40]:
for j in range ((i + 1) / 2):
A([i:i + 1], [:]) = mcat([X(j), Y(j), Z(j) [ 1, 0, 0, 0, 0] - u(j)*X(j)-u(j)*Y(j)-u(j)*Z(j)-u(j), [0, 0, 0, 0] X(j), Y(j), Z(j), [1] - v(j)*X(j)-v(j)*Y(j)-v(j)*Z(j)-v(j)])


My error is:for i in range[1:2:40]: ^ IndentationError: unexpected indent

Is it's a problems with loop for identification? Thanks a lot

Answer

If you're getting indentation errors, you probably need to fix your indentation. ;)

for i in range(1:2:40):
    for j in range ((i + 1) / 2):
        A([i:i + 1], [:]) = mcat([X(j), Y(j), Z(j) [ 1, 0, 0, 0, 0] - u(j)*X(j)-u(j)*Y(j)-u(j)*Z(j)-u(j), [0, 0, 0, 0] X(j), Y(j), Z(j), [1] - v(j)*X(j)-v(j)*Y(j)-v(j)*Z(j)-v(j)])

I also suspect there are issues with that final expression. Up to you to fix that.

Comments