0

I am trying to do fish-eye stereo calibration using Opencv and Python at first I have done stereo calibration of the single camera

print("Calibrating left fisheye camera...")
rms, _, _, _, _ = cv2.fisheye.calibrate(objectPoints,leftImagePoints,imageSize, K_left,D_left,R,T,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,flags, (cv2.TERM_CRITERIA_EPS+cv2.TERM_CRITERIA_MAX_ITER, 30, 1e-6))

but in next step when I am trying to do stereofisheye calibration:

print("calibrating both fisheye cameras together...")
(rms,K1, D1, K2, D2, R, T) = cv2.fisheye.stereoCalibrate(
    objectPoints,
    leftImagePoints,
    rightImagePoints,
    K_left,
    D_left,
    K_right,
    D_right,
    imageSize)

It is throwing an error:

Traceback (most recent call last): File "fisheye_calib1.py", line 177, in imageSize) cv2.error: OpenCV(4.0.0-pre) /home/compute/OpenCV-tmp/opencv- 3/modules/core/src/arithm.cpp:683: error: (-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'

As I am new to OpenCV. I am really confused what step should I take to avoid this error.

Talha Junaid
  • 2,351
  • 20
  • 29
Kush
  • 11
  • 3

1 Answers1

0

Welcome to Stack Overflow!

Seems like the arrays you sending to stereoCalibrate is not of the same type. For example see this question where someone struggled with the same error message. I found it after a quick Google search of your error code.

So my guess is that the fix would be to make sure all your matrices are of the same type. Make sure that you initialize them in the same way. For example, are they created as lists ([4,4,5]) or as Numpy-arrays (typical outputs of OpenCV)? These two won't work together.

If you are still struggling you could force it just before stereoCalibrate with:

objectPoints = numpy.array(K_left, np.float)
...
K_left = ... # Do the above operation on each one
...
D_right = ...

I hope this helps!

Note: for my solution you will need the Numpy package imported

Hein Wessels
  • 937
  • 5
  • 15
  • I saw you asked another question, which means you fixed the bug you asked about here. Please post the answer to your question, of "Accept as Answer" the appropriate answer, so that others may know how to fix similar problems. – Hein Wessels Aug 28 '18 at 10:59