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 point

  • dims (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 point

  • dims (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
  • cal_path (str) – Path to camera calibration

  • dims (tuple) – Image dimensions (image height, image width)

  • read_sensor (bool, optional) – If True, additionally read and return the sensor resolution and size

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 center

  • distCoeffs (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 terms

  • rmat (numpy.ndarray, shape (3, 3)) – Rotation matrix from camera to tunnel

  • tvec (numpy.ndarray, shape (3,)) – Translation vector from camera to tunnel

  • sensor_resolution (numpy.ndarray, shape (2,)) – Sensor size of camera in pixels, only returned if read_sensor is True

  • sensor_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
  • internal_cal_dir (str) – Path to internal calibrations

  • dims (tuple) – Image dimensions (image height, image width)

  • read_sensor (bool, optional) – If True, additionally read and return the sensor resolution and size

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 center

  • distCoeffs (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 terms

  • sensor_resolution (numpy.ndarray, shape (3,)) – Camera sensor resolution, only returned if read_sensor is True

  • sensor_size (numpy.ndarray, shape (2,)) – Camera sensor physical size, only returned if read_sensor is True

read_json(path)[source]

Safely reads a json file and returns the associated dict

Parameters

path (path-like) – File path to the tgts file

Returns

dict of json file items

Return type

dict

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 or str) – 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

dict or list

read_test_config(path)[source]

Safely reads a test config file and returns the associated dict with arrays

Parameters

path (path-like) – File path to the tgts file

Returns

dict of json file items

Return type

dict

read_tgts(tgts_file_path, output_target_types=None)[source]

Returns the targets in the tgts file

Parameters
  • tgts_file_path (str) – File path to the tgts file

  • output_target_types (str, list of str, optional) – If not None, only targets with a type of or in output_target_types will be read. If None, all target types will be read

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

list of dict

read_wind_tunnel_data(wtd_file_path, items=('ALPHA', 'BETA', 'PHI', 'STRUTZ'))[source]

Read specified wind tunnel data from wtd_file_path

Parameters
  • wtd_file_path (str) – Filepath to wind tunnel data file

  • items (container, optional) – Items requested from the file. By default ALPHA, BETA, PHI and STRUTZ are returned.

Returns

tunnel_vals – Dictionary with keys of specified items and values of associated wtd values.

Return type

dict