Skip to content

Instantly share code, notes, and snippets.

@dbaldwin
Last active August 8, 2016 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbaldwin/21d55b134d71fd66e06dce8b91651a03 to your computer and use it in GitHub Desktop.
Save dbaldwin/21d55b134d71fd66e06dce8b91651a03 to your computer and use it in GitHub Desktop.
Basic script to undistort wide angle photo taken by Phantom 4 for use in Open Drone Map
# Original howto article: http://www.janeriksolem.net/2014/05/how-to-calibrate-camera-with-opencv-and.html
# Original phantom 4 photos and calibrated output is here: https://www.dropbox.com/sh/w0cnw6u3b511eth/AACqFDhnvMAB3YTFRD_BZnONa?dl=0
# Read all about it in this ODM issue: https://github.com/OpenDroneMap/OpenDroneMap/issues/350
import numpy as np
import cv2
# The following parameters come from running the OpenCV calibrate.py script
K = np.array([[2365.85284, 0, 1970.24146],[0, 2364.17864, 1497.37745], [0, 0, 1]])
d = np.array([.0181517127, .134277087, 0, 0, 0])
# read one of your images
img = cv2.imread("/vagrant/calibration_images/DJI_0118.JPG")
h, w = img.shape[:2]
# undistort
newcamera, roi = cv2.getOptimalNewCameraMatrix(K, d, (w,h), 0)
newimg = cv2.undistort(img, K, d, None, newcamera)
cv2.imwrite("/vagrant/output/DJI_0118_original.JPG", img)
cv2.imwrite("/vagrant/output/DJI_0118_undistorted.JPG", newimg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment