ValueError: setting an array element with a sequence.

asked 2020-09-10 03:17:14 -0600

hoseinimage gravatar image

hi first i computed a Mapping Matrix named homography using findHomography command

M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)
homography = M, mask

then I defined a 3*3 Matrix named camera as camera = np.array([[800, 0, 240], [0, 800, 320], [0, 0, 1]]) and I Globalized this variable (camera) and defined a Function named (projection_matrix) :

global camera
camera = np.array([[800, 0, 240], [0, 800, 320], [0, 0, 1]])
def projection_matrix(homography):

then I called this Function. I want to Multiply Inversion Matrix Of camera to homography Mapping Matrix as:

homography = homography * (-1)
projection_matrix(homography)

# Multiply Inversion Matrix Of camera to homography Matrix

  rot_and_transl = np.dot(np.linalg.inv(camera), homography)

but Pycharm gives These Errors:

**TypeError: only size-1 arrays can be converted to Python scalars**

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:/Users/Ali Hoseyni/PycharmProjects/pythonProject/main.py", line 41, in <module>

rot_and_transl = np.dot(np.linalg.inv(camera), homography) File "<__array_function__ internals>", line 5, in dot

**ValueError: setting an array element with a sequence.**
edit retag flag offensive close merge delete

Comments

what are you trying to achieve here ? what's the context ?

I want to Multiply Inversion Matrix Of camera

this does not make much sense. did you want ot invert the homography instead ?

also, your "homography" is a tuple of 2 Mats, for sure the wrong thing

last, if you wanted the combined homography / camera transform, you need a matrix multiplcation, not a dot product

berak gravatar imageberak ( 2020-09-10 03:35:10 -0600 )edit