Undistorters
This contains the undistorter structures.
- class Undistorter(camera_file, turn=False)
Abstract class to model an undistortion method to be aplied on images in order to correct the spherical distortion caused by the camera lens. Classes inheriting from this class should implement
undistortmethod.To use an undistorion method you will need to obtain the calibration matrix of your camera. You can follow the guide in opencv docs until the end of the section
Undistortionto compute the matrix of your camera:https://docs.opencv.org/master/dc/dbb/tutorial_py_calibration.html
Then you can save the matrix and other parameters in an npz file using numpy:
>>> np.savez( ... "camera_file.npz", h=h, w=w, mtx=mtx, dist=dist, newcameramtx=newcameramtx ... )
- Parameters:
camera_file (str) – Path to the camera calibration file (“camera_file.npz” in the above example).
turn (bool) – This parameter is used to rotate 90 degrees the frame, before undistorting it. It is useful when the input video is rotated respect the orginal orientation used when the camera was calibrated (Not a very frequent use case). The undistorted result will be rotated -90 degrees before returning. By default is False.
- abstract undistort(frame)
Abstract method that is implemented on inheriting classes. It should compute an undistorted version of frame using the given camera calibration matrix and a method specific to the inheriting class.
- Parameters:
frame (ndarray)
- Return type:
ndarray
- fix(frame)
Fix the distortion.
- Parameters:
frame (np.ndarray) – Frame to be fixed.
- Returns:
Fixed frame.
- Return type:
np.ndarray
- masked(frame)
Apply the mask to a frame to adjust border colors.
- Parameters:
frame (np.ndarray) – Frame to be adjusted.
- Returns:
Adjusted frame.
- Return type:
np.ndarray
- class ClassicUndistorter(camera_file, turn=False)
Undistorter that performs undistortion using
cv2.undistort.- Parameters:
camera_file (str) – Path to the camera calibration file (“camera_file.npz” in the above example).
turn (bool) – This parameter is used to rotate 90 degrees the frame, before undistorting it. It is useful when the input video is rotated respect the orginal orientation used when the camera was calibrated (Not a very frequent use case). The undistorted result will be rotated -90 degrees before returning. By default is False.
- undistort(frame)
Computes the undistorted version of
frameusingcv2.undistort.- Returns:
Undistorted version of frame.
- Return type:
np.ndarray
- Parameters:
frame (ndarray)
- class RemapUndistorter(camera_file, turn=False)
Undistorter that performs undistortion using
cv2.remap.- Parameters:
camera_file (str) – Path to the camera calibration file (“camera_file.npz” in the above example).
turn (bool) – This parameter is used to rotate 90 degrees the frame, before undistorting it. It is useful when the input video is rotated respect the orginal orientation used when the camera was calibrated (Not a very frequent use case). The undistorted result will be rotated -90 degrees before returning. By default is False.
- undistort(frame)
Computes the undistorted version of
frameusingcv2.remap.- Returns:
Undistorted version of frame.
- Return type:
np.ndarray
- Parameters:
frame (ndarray)