Why does this error occur:
error: (-211:One of the arguments' values is out of range) The number of points in the view #0 is < 4 in function 'cvCalibrateCamera2Internal'
If I run this piece of code:
import cv2
import numpy as np
s = 100
n = 6
h = w = s
gray = np.random.randint(0, 255, (h, w), dtype=np.uint8) # Random image
objpoints = np.random.randint(0, s, size=(n, 1, 3)).astype(np.float32) # Random 'real world' points
imgpoints = objpoints[:, :, :2] # Assume camera image is 1-to-1 mapping of top down view of real world points
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)
The number of points is clearly 6, so not less than 4. Is there someone willing and able to explain this to me?
Thanks in advance!
Edit
Based on the answer of @Christoph Rackwitz I modified the above code such that it works. However, I encountered a gotcha which initially added to my confusion, see the comment in code.
import cv2
import numpy as np
v = 3 # Multiple views
s = 100
n = 100
h = w = s
gray = np.random.randint(0, 255, (h, w), dtype=np.uint8)
objpoints = np.random.randint(0, s, size=(v, n, 3)).astype(np.float32)
objpoints[:, :, 2] = 0 # Planar coordinates
imgpoints = objpoints[:, :, :2]
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(
objpoints,
imgpoints.copy(), # GOTCHA: function fails without this copy due to it being a view instead of a separate array
gray.shape[::-1],
None,
None
)