multical icon indicating copy to clipboard operation
multical copied to clipboard

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

Open Super-Iron-Man opened this issue 3 years ago • 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) :-1: 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)

Super-Iron-Man avatar Jan 25 '22 08:01 Super-Iron-Man

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

my final version:

opencv-contrib-python 4.5.5.64

ykk648 avatar May 13 '22 05:05 ykk648

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

dkguo avatar Nov 18 '22 06:11 dkguo

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.

Jungduri avatar Jan 25 '23 05:01 Jungduri

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.

jessicalfr avatar Mar 27 '23 14:03 jessicalfr

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

jessicalfr avatar Mar 27 '23 14:03 jessicalfr

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.

helloqxwang avatar Sep 23 '23 17:09 helloqxwang