kopia lustrzana https://github.com/OpenDroneMap/ODM
Print calibration parameters in ORB_SLAM2 format
rodzic
a205c38a5b
commit
aa54fd6c60
|
@ -53,7 +53,7 @@ class Calibrator:
|
||||||
"""Run calibration using points extracted by process_image."""
|
"""Run calibration using points extracted by process_image."""
|
||||||
rms, camera_matrix, dist_coefs, rvecs, tvecs = cv2.calibrateCamera(
|
rms, camera_matrix, dist_coefs, rvecs, tvecs = cv2.calibrateCamera(
|
||||||
self.object_points, self.image_points, self.image_size, None, None)
|
self.object_points, self.image_points, self.image_size, None, None)
|
||||||
return rms, camera_matrix, dist_coefs
|
return rms, camera_matrix, dist_coefs.ravel()
|
||||||
|
|
||||||
def _add_points(self, image_points):
|
def _add_points(self, image_points):
|
||||||
if self.image_points:
|
if self.image_points:
|
||||||
|
@ -79,6 +79,24 @@ def video_frames(filename):
|
||||||
cap.release()
|
cap.release()
|
||||||
|
|
||||||
|
|
||||||
|
def orb_slam_calibration_config(camera_matrix, dist_coefs):
|
||||||
|
"""String with calibration parameters in orb_slam config format."""
|
||||||
|
lines = [
|
||||||
|
"# Camera calibration and distortion parameters (OpenCV)",
|
||||||
|
"Camera.fx: {}".format(camera_matrix[0, 0]),
|
||||||
|
"Camera.fy: {}".format(camera_matrix[1, 1]),
|
||||||
|
"Camera.cx: {}".format(camera_matrix[0, 2]),
|
||||||
|
"Camera.cy: {}".format(camera_matrix[1, 2]),
|
||||||
|
"",
|
||||||
|
"Camera.k1: {}".format(dist_coefs[0]),
|
||||||
|
"Camera.k2: {}".format(dist_coefs[1]),
|
||||||
|
"Camera.p1: {}".format(dist_coefs[2]),
|
||||||
|
"Camera.p2: {}".format(dist_coefs[3]),
|
||||||
|
"Camera.k3: {}".format(dist_coefs[4]),
|
||||||
|
]
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Camera calibration from video of a chessboard.")
|
description="Camera calibration from video of a chessboard.")
|
||||||
|
@ -123,12 +141,12 @@ if __name__ == '__main__':
|
||||||
if args.visual:
|
if args.visual:
|
||||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||||
break
|
break
|
||||||
print
|
|
||||||
|
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
|
||||||
rms, camera_matrix, dist_coefs = calibrator.calibrate()
|
rms, camera_matrix, dist_coefs = calibrator.calibrate()
|
||||||
|
|
||||||
|
print
|
||||||
print "RMS:", rms
|
print "RMS:", rms
|
||||||
print "camera matrix:\n", camera_matrix
|
print
|
||||||
print "distortion coefficients: ", dist_coefs.ravel()
|
print orb_slam_calibration_config(camera_matrix, dist_coefs)
|
||||||
|
|
Ładowanie…
Reference in New Issue