upsp.cam_cal_utils.parsers
¶
- convert_cv2_cm_to_uPSP_cm(cameraMatrix, dims)[source]¶
Converts a standard camera matrix to a uPSP camera matrix
OpenCV (and the standard) cameraMatrix uses the absolute position of the optical principal point. Since uPSP often crops images, the absoulte position varies from configuration to configuration even if the optics haven’t changed. So instead, the position of the principal point relative to the image center is saved.
- Parameters
cameraMatrix (
numpy.ndarray
,shape (3
,3)
) – Camera matrix of the form:[[fx, 0, cx], [0, fy, cy], [0, 0, 1]]
where f is the focal length and (cx, cy) is the absolute position of the optical principal pointdims (
tuple
,length 2
) – Image dimensions (width, height)
- Returns
uPSP_cameraMatrix – Converted camera matrix of the form:
[[fx, 0, dcx], [0, fy, dcy], [0, 0, 1]]
cx = w/2 + dcx and cy = h/2 + dcy where w and h are the image width and height- Return type
numpy.ndarray
,shape (3
,3)
See also
convert_uPSP_cm_to_cv2_cm
inverse conversion
- convert_uPSP_cm_to_cv2_cm(uPSP_cameraMatrix, dims)[source]¶
Converts a uPSP camera matrix to a standard camera matrix
OpenCV (and the standard) cameraMatrix uses the absolute position of the optical principal point. Since uPSP often crops images, the absoulte position varies from configuration to configuration even if the optics haven’t changed. So instead, the position of the principal point relative to the image center is saved. To use OpenCV functions, it has to be converted back to the standard OpenCV camera matrix.
- Parameters
uPSP_cameraMatrix (
numpy.ndarray
,shape (3
,3)
) – Camera matrix of the form:[[fx, 0, cx], [0, fy, cy], [0, 0, 1]]
where f is the focal length and (cx, cy) is the absolute position of the optical principal pointdims (
tuple
,length 2
) – Image dimensions (width, height)
- Returns
cameraMatrix – Converted camera matrix of the form:
[[fx, 0, cx], [0, fy, cy], [0, 0, 1]]
cx = w/2 + dcx and cy = h/2 + dcy where w and h are the image width and height- Return type
numpy.ndarray
,shape (3
,3)
See also
convert_uPSP_cm_to_cv2_cm
inverse conversion
- read_camera_tunnel_cal(cal_path, dims, read_sensor=False)[source]¶
Returns the internal (intrinsic) and external (extrinsic) camera calibration parameters
- Parameters
- Returns
cameraMatrix (
numpy.ndarray
,shape (3
,3)
) – Camera matrix of the form[[fx, 0, cx], [0, fy, cy], [0, 0, 1]]
where f is the focal length and (cx, cy) is the position of the optical principal point relative to the image centerdistCoeffs (
numpy.ndarray
,shape (5,)
) – Distortion coefficients of the form[k1, k2, p1, p2, k3]
where k1, k2, and k3 are the radial distortion terms and p1 and p2 are the tangential distortion termsrmat (
numpy.ndarray
,shape (3
,3)
) – Rotation matrix from camera to tunneltvec (
numpy.ndarray
,shape (3,)
) – Translation vector from camera to tunnelsensor_resolution (
numpy.ndarray
,shape (2,)
) – Sensor size of camera in pixels, only returned if read_sensor is Truesensor_size (
numpy.ndarray
,shape (2,)
) – Sensor size of camera in inches, only returned if read_sensor is True
- read_internal_params(internal_cal_path, dims, read_sensor=False)[source]¶
Returns the internal (intrinsic) camera parameters
- Parameters
- Returns
cameraMatrix (
numpy.ndarray
,shape (3
,3)
) – Camera matrix of the form[[fx, 0, cx], [0, fy, cy], [0, 0, 1]]
where f is the focal length and (cx, cy) is the position of the optical principal point relative to the image centerdistCoeffs (
numpy.ndarray
,shape (5,)
) – Distortion coefficients of the form[k1, k2, p1, p2, k3]
where k1, k2, and k3 are the radial distortion terms and p1 and p2 are the tangential distortion termssensor_resolution (
numpy.ndarray
,shape (3,)
) – Camera sensor resolution, only returned if read_sensor is Truesensor_size (
numpy.ndarray
,shape (2,)
) – Camera sensor physical size, only returned if read_sensor is True
- read_pascal_voc(annot_path)[source]¶
Return image objects from a PASCAL VOC XML file
Reads the input file(s) and returns an list of dicts, where each dict contains the class, bounding box, and flags of an image object.
- Parameters
annot_path (
list
orstr
) – This can be a string, or a list of strings (or list-like). Each string is the path to a label- Returns
out – If annot_path is a single label path, the output is a list of dicts. If annot_path is a list of label paths (or list-like), the output is a list of lists, where each inner list if a list of dicts. Each dict is represents an image object and has the keys ‘class’, ‘x1’, ‘x2’, ‘y1’, ‘y2’, ‘difficult’, and ‘truncated’.
- Return type
- read_test_config(path)[source]¶
Safely reads a test config file and returns the associated dict with arrays
- read_tgts(tgts_file_path, output_target_types=None)[source]¶
Returns the targets in the tgts file
- Parameters
- Returns
targets –
List of targets. Each target is of the form:
{ 'target_type' : class_string, 'tvec' : [x, y, z], 'norm', : [x, y, z], 'size': float, 'name': str, 'idx': int, 'zones': [i, j, k] }
- Return type