# Cv2.omnidir.calibrate() error

**URL:** <https://forum.opencv.org/t/cv2-omnidir-calibrate-error/7308>\
**Category:** Python\
**Created:** [January 27, 2022, 9:48am UTC](https://forum.opencv.org/t/cv2-omnidir-calibrate-error/7308 "2022-01-27T09:48:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lind3](https://avatars.discourse-cdn.com/v4/letter/l/a87d85/32.png) [@Lind3](https://forum.opencv.org/u/Lind3)\
**Post date:** [January 27, 2022, 9:48am UTC](https://forum.opencv.org/t/cv2-omnidir-calibrate-error/7308/1 "2022-01-27T09:48:24Z")

</div>

Hi! I’m working on my master thesis and want to calibrate a camera with 194 deg FOV, therefore I’m using the omnidirectional calibration method in OpenCV as I’ve understood that this is recommended for cameras with a FOV \>180 deg. When trying to compile I get the following error thrown:

```auto
  Message=OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv_contrib\modules\ccalib\src\omnidir.cpp:854: error: (-215:Assertion failed) !objectPoints.empty() && objectPoints.type() == CV_64FC3 in function 'cv::omnidir::internal::computeJacobian'

  Source=C:\Users\SLINDE\source\repos\Test.py
  StackTrace:
  File "C:\Users\SLINDE\source\repos\Test.py", line 66, in getOmnidirectionalCalibrationParams
    ret, K, xi, D, rvecs, tvecs, idx = cv2.omnidir.calibrate(objectpoints, imagepoints, image_size, K, xi, D, calibration_flag, subpixel_criteria)
  File "C:\Users\SLINDE\source\repos\Test.py", line 74, in <module> (Current frame)
    ret, K, xi, D, rvecs, tvecs, idx = getOmnidirectionalCalibrationParams(objectpoints, imagepoints, omnidir_calibration_flags, subpixel_criteria)

```

I’ve googled around and found similar errors but nothing have helped me solve this issue. I would highly appreciate if anyone could try to guide me. Below you can see my code, the error is thrown at line 66.

import glob  
import os  
import numpy as np  
import matplotlib.pyplot as plt  
import cv2  
assert cv2. **version** [0] \>= ‘3’

#Globals  
image\_path = ‘C:/Users/SLINDE/Documents/Checkboard/’  
output\_path = ‘C:/Users/SLINDE/Documents/Checkboard/output/’  
image\_extension = ‘jpg’  
image\_size = (4032, 3024)  
checkerboard\_size = (10,15)  
subpixel\_criteria = (cv2.TERM\_CRITERIA\_EPS+cv2.TERM\_CRITERIA\_MAX\_ITER, 30, 0.1)  
fisheye\_calibration\_flags = cv2.fisheye.CALIB\_RECOMPUTE\_EXTRINSIC+cv2.fisheye.CALIB\_CHECK\_COND+cv2.fisheye.CALIB\_FIX\_SKEW  
omnidir\_calibration\_flags = cv2.omnidir.CALIB\_USE\_GUESS  
draw\_chessboard\_marked\_images = False

#OpenCV Checkboard setup  
def getObjectAndImagePoints(imagePath, imageExtension, checkerboardSize, subpixelCriteria, drawChessboardMarkedImages):  
objp = np.zeros((1, checkerboardSize[0]\*checkerboardSize[1], 3), np.float32)  
objp[0,:,:2] = np.mgrid[0:checkerboardSize[0], 0:checkerboardSize[1], ].T.reshape(-1, 2)  
\_img\_shape = None  
objpoints = [] #3d point in real world space  
imgpoints = [] #2d points in image plane.

```
images = glob.glob(imagePath + '*.' + imageExtension)
for fname in images:
    img = cv2.imread(fname)
    if _img_shape == None:
        _img_shape = img.shape[:2]
    else:
        assert _img_shape == img.shape[:2], "All images must share the same size."
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    #Find the chess board corners
    ret, corners = cv2.findChessboardCorners(gray, checkerboardSize, cv2.CALIB_CB_ADAPTIVE_THRESH+cv2.CALIB_CB_FAST_CHECK+cv2.CALIB_CB_NORMALIZE_IMAGE)

    print(corners.shape)

    #If found, add object points, image points (after refining them)
    if ret == True:
        cv2.cornerSubPix(gray, corners, (5,5), (-1,-1), subpixelCriteria)
        #corners = corners.reshape((35,2)) # This is necessary only for omnidirectional calibration
        imgpoints.append(corners)
        objpoints.append(objp)

        if drawChessboardMarkedImages:
            gray2 = gray
            cv2.drawChessboardCorners(gray2, checkerboardSize, corners, ret)
            cv2.imwrite(os.path.splitext(fname)[0] + '_' + 'CHESSCORNERS.png', gray2)

return (objpoints, imgpoints)

```

def getOmnidirectionalCalibrationParams(objectpoints, imagepoints, calibration\_flag, subpixel\_criteria):  
K = np.zeros((3,3))  
D = np.zeros((1,4))  
xi = np.array([])  
idx = np.array([])

```
no_images = len(imagepoints)
no_points = len(imagepoints[0])
objectpoints = np.reshape(objectpoints, (no_images, 1, no_points, 3))
imagepoints = np.reshape(imagepoints, (no_images, 1, no_points, 2))
 
ret, K, xi, D, rvecs, tvecs, idx = cv2.omnidir.calibrate(objectpoints, imagepoints, image_size, K, xi, D, calibration_flag, subpixel_criteria)
 
return ret, K, xi, D, rvecs, tvecs, idx

```

#Find camera calibration parameters  
objectpoints, imagepoints = getObjectAndImagePoints(image\_path, image\_extension, checkerboard\_size, subpixel\_criteria, draw\_chessboard\_marked\_images)  
print(imagepoints)  
ret, K, xi, D, rvecs, tvecs, idx = getOmnidirectionalCalibrationParams(objectpoints, imagepoints, omnidir\_calibration\_flags, subpixel\_criteria)

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [January 27, 2022, 10:23am UTC](https://forum.opencv.org/t/cv2-omnidir-calibrate-error/7308/2 "2022-01-27T10:23:33Z")

</div>

please, no images of code or errors (entirely useless here), replace with TEXT, thanks !

the error you show complains about objectPoints being either empty or in the wrong format. print out shape, type, dtype, and tell us !

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [January 27, 2022, 9:37pm UTC](https://forum.opencv.org/t/cv2-omnidir-calibrate-error/7308/3 "2022-01-27T21:37:34Z")

</div>

related: [Opencv-contrib-python Assertion error](https://forum.opencv.org/t/opencv-contrib-python-assertion-error/7311)
