No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

calibrate.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435
  1. import numpy as np
  2. import cv2
  3. import glob
  4. def calculareCameraCalibration():
  5. # termination criteria
  6. criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 23, 0.001)
  7. # prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
  8. objp = np.zeros((6*7,3), np.float32)
  9. objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
  10. # Arrays to store object points and image points from all the images.
  11. objpoints = [] # 3d point in real world space
  12. imgpoints = [] # 2d points in image plane.
  13. images = glob.glob('./img_calibrate/*.jpg')
  14. for fname in images:
  15. img = cv2.imread(fname)
  16. gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  17. # Find the chess board corners
  18. ret, corners = cv2.findChessboardCorners(gray, (7,6),None)
  19. # If found, add object points, image points (after refining them)
  20. if ret == True:
  21. objpoints.append(objp)
  22. corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
  23. imgpoints.append(corners2)
  24. ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)
  25. return ret, mtx, dist, rvecs, tvecs