OpenCV fisheye calibration cuts too much of the resulting image

前端 未结 5 779
长情又很酷
长情又很酷 2020-12-03 15:28

I am using OpenCV to calibrate images taken using cameras with fish-eye lenses.

The functions I am using are:

  • findChessboardCorners(...);
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 15:55

    I think I have ran into a similar issue, looking for the "alpha" knot in getOptimalNewCameraMatrix for fisheye.

    Original shot:

    I calibrated it with cv2.fisheye.calibrate, got the K and D parameters

    K = [[ 329.75951163    0.          422.36510555]
     [   0.          329.84897388  266.45855056]
     [   0.            0.            1.        ]]
    
    D = [[ 0.04004325]
     [ 0.00112638]
     [ 0.01004722]
     [-0.00593285]]
    

    This is what I get with

    map1, map2 = cv2.fisheye.initUndistortRectifyMap(K, d, np.eye(3), k, (800,600), cv2.CV_16SC2)
    nemImg = cv2.remap( img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
    

    And I think it chops too much. I want to see the whole Rubik's cube

    I fix it with

    nk = k.copy()
    nk[0,0]=k[0,0]/2
    nk[1,1]=k[1,1]/2
    # Just by scaling the matrix coefficients!
    
    map1, map2 = cv2.fisheye.initUndistortRectifyMap(k, d, np.eye(3), nk, (800,600), cv2.CV_16SC2)  # Pass k in 1st parameter, nk in 4th parameter
    nemImg = cv2.remap( img, map1, map2, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
    

    TADA!

提交回复
热议问题