oliver-batchelor/multical

(-5:Bad argument) in function 'calibrateCamera'

Super-Iron-Man opened this issue · 6 comments

when I run calibrate.py, it shows:
`points.corners, image_size, None, None, criteria=criteria, flags=flags)
cv2.error: OpenCV(4.5.5) 👎 error: (-5:Bad argument) in function 'calibrateCamera'

Overload resolution failed:

  • Can't parse 'imagePoints'. Sequence item with index 0 has a wrong type
  • Can't parse 'imagePoints'. Sequence item with index 0 has a wrong type`

when I run
print(np.array(points.object_points).shape

it shows:
(12,114,3)

same problem, I uninstall opencv-python and reinstall opencv-contrib-python , solved this issue.

my final version:

opencv-contrib-python 4.5.5.64

dkguo commented

Same problem here. Using opencv-contrib-python 4.5.5.64 doesn’t help. Do you have other ideas for this problem? Thanks.

This issue origins from the type checker, of which OpenCV has been updated from a specific version(sorry I am not sure).
"calibrateCamera" needs float32 of nparray. but NumPy turns it to np.float64 as a default.

Quick solution

you may change as below(in camera.py):

            np.array(points.object_points, dtype=np.float32),
            np.array(points.corners, dtype=np.float32),

This is not a good idea, but works for quick turns.
Hope it works.

I'm going through the same problem trying to calibrate 4 cameras. The problem seems to happen in the top_detection_coverage function call in line 72 of camera.py. After the call points = calibration_points(boards, detections) in line 70 the object points.object_points is a list of numpy arrays. After the top_detection_coverage call the same object turns into a list of lists for one of my cameras and the error occurs. Coincidence or not, this camera has a different resolution from the others, but I've done this before and it worked.

I'm still trying a few solutions and if something works I'll bring it here.

Commenting the line that calls top_detection_coverage obviously works, but doesn't seem like the best solution!

adding
for i in range(len(points.object_points)): points.object_points[i] = np.ndarray(points.object_points[i], dtype=np.float32) for i in range(len(points.corners)): points.corners[i] = np.array(points.corners[i], dtype=np.float32)
after the top_detection_coverage function call works well for me. I think the reason is just what @jessicalfr say.