Ask Your Question
0

TypeError: R is not a numpy array, neither a scalar

asked 2018-08-23 03:00:06 -0600

Kush gravatar image

updated 2018-08-23 05:13:45 -0600

I am trying to do stereo fish eye camera calibration using OpenCV and Python Here is my code:

Main part of the code for stereo calibration

N_OK = len(leftImagePoints)

objecPoints = np.array([objectPoints]*len(leftImagePoints), dtype=np.float64)
leftImagePoints=np.asarray(leftImagePoints, dtype=np.float64)
rightImagePoints=np.asarray(rightImagePoints, dtype=np.float64)

objectPoints = np.reshape(objectPoints,(N_OK, 1, CHESSBOARD_SIZE[0]*CHESSBOARD_SIZE[1],3))
leftImagePoints = np.reshape(leftImagePoints, (N_OK, 1, CHESSBOARD_SIZE[0]*CHESSBOARD_SIZE[1], 2))
rightImagePoints = np.reshape(rightImagePoints,(N_OK, 1, CHESSBOARD_SIZE[0]*CHESSBOARD_SIZE[1], 2)) 

K_left = np.zeros((3, 3))
D_left = np.zeros((4, 1))

K_right = np.zeros((3, 3))
D_right = np.zeros((4, 1))


R = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(MAX_IMAGES)]
T = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(MAX_IMAGES)]

print("Calibrating left fisheye camera...")

rms, _, _, _, _ = cv2.fisheye.calibrate(objectPoints,leftImagePoints,imageSize, K_left,D_left,R,T,calibration_flags,      (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6))

print("calibrating right fisheye camera...")

rms, _, _, _, _ = cv2.fisheye.calibrate(objectPoints,rightImagePoints, imageSize,K_right,D_right,R,T,calibration_flags, (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6))

print("calibrating both fisheye cameras together...")

(rms, _, _, _, _) = \
  cv2.fisheye.stereoCalibrate(
     objectPoints,
     leftImagePoints,
     rightImagePoints,
     K_left,
     D_left,
     K_right,
     D_right,
     imageSize,
     R,
     T,
     (cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC + cv2.fisheye.CALIB_CHECK_COND + cv2.fisheye.CALIB_FIX_SKEW)
    );

*error: -Traceback (most recent call last): File "fisheye_calib1.py", line 176, in <module> (cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC + cv2.fisheye.CALIB_CHECK_COND + cv2.fisheye.CALIB_FIX_SKEW) TypeError: R is not a numpy array, neither a scalar *

I am able to do calibration of individual camera but it is throwing errors when it comes to stereo fisheye camera calibration. ' Have I declared R & T in right manner' It is giving error (SystemError: new style getrags format but argument is not a tuple) If anyone could guide me with this would be great help.

edit retag flag offensive close merge delete

Comments

please tell us WHERE the error happens.

(i'm afraid, noone will actually try your 200 line monster)

we also need the exact error msg.

berak gravatar imageberak ( 2018-08-23 03:08:12 -0600 )edit
1

I have edited my code with error.

Kush gravatar imageKush ( 2018-08-23 03:24:45 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-08-23 03:42:32 -0600

berak gravatar image

i think, you wanted to OR the flags, not make a tuple out of it:

cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC | cv2.fisheye.CALIB_CHECK_COND | cv2.fisheye.CALIB_FIX_SKEW

(no () around it)

edit flag offensive delete link more

Comments

I have tried that it but its not working. It is giving another error.

SystemError: new style getrags format but argument is not a tuple

Kush gravatar imageKush ( 2018-08-23 04:01:41 -0600 )edit

again, we can only help, if you're concise about it.

berak gravatar imageberak ( 2018-08-23 04:46:08 -0600 )edit

(rms, _, _, _, _) = cv2.fisheye.stereoCalibrate( objectPoints, leftImagePoints, rightImagePoints, K_left, D_left, K_right, D_right, imageSize, R, T, flags = calibration_flags, criteria = TERMINATION_CRITERIA) error: TypeError: R is not a numpy array, neither a scalar I have declared R and T R = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(MAX_IMAGES)] T = [np.zeros((1, 1, 3), dtype=np.float64) for i in range(MAX_IMAGES)]

It is giving error with cv2.fisheye.stereocalibrate

Kush gravatar imageKush ( 2018-08-23 06:45:40 -0600 )edit

try like:

flags = cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC | cv2.fisheye.CALIB_CHECK_COND | cv2.fisheye.CALIB_FIX_SKEW
rms, K1, D1, K2, D2, R, T =  cv2.fisheye.stereoCalibrate(objectPoints, leftImagePoints, rightImagePoints, K_left, D_left, K_right, D_right, imageSize, flags=flags)
berak gravatar imageberak ( 2018-08-23 06:53:03 -0600 )edit

rms, K1, D1, K2, D2, R, T all are "return values". you don't need (and you shouldn't try) to preallocate those. just drop them from the argument list, and use an explicit flags=flags at the end.

berak gravatar imageberak ( 2018-08-23 06:57:49 -0600 )edit

Now; I am facing a different when I added ImageSizeerror: (-5:Bad argument) When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function 'arithm_op' code for imageSize

for imagePath in sorted(imagePaths):

    image = cv2.imread(imagePath)
    grayImage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    newSize = grayImage.shape[::-1]
    if imageSize != None and newSize != imageSize:
        raise ValueError(
                "Calibration image at {0} is not the same size as the others"
                .format(imagePath))
    imageSize = newSize
    ret, corners = cv2.findChessboardCorners(grayImage,
            CHESSBOARD_SIZE, cv2.CALIB_CB_FAST_CHECK)
Kush gravatar imageKush ( 2018-08-23 07:11:33 -0600 )edit

maybe you need to start a new question ...

berak gravatar imageberak ( 2018-08-23 07:47:07 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-08-23 03:00:06 -0600

Seen: 1,124 times

Last updated: Aug 23 '18