upsp.cam_cal_utils.camera_tunnel_calibrate

camera_to_tunnel_calibrate(ctc_dir, imgs, internal_cals, manual_detections, tunnel_vals, tgts_all, test_config, vis_checker, match_thresh=0.8)[source]

Performs camera to tunnel calibration for the given cameras

Generates camera_to_tunnel json files for each given camera and saved in ctc_dir.

Any number of cameras can be given to this function. Each camera needs its own entry in imgs, internal_cals, and manual_detections. If there are 10 cameras, each of those inputs will be a list of length 10.

If debug_show_matches or debug_show_img_targets are True, the debug images will be saved to the current directory. Each image will be appended with ‘_?’ where ? is the index of the camera (If ? is 0, it corresponds to imgs[0], internal_cals[0], and manual_detections[0])

All inputs should correspond to the same test configuration. The inputs tunnel_vals, tgts_all, test_config, and vis_checker will be used across all cameras.

Parameters
  • ctc_dir (string) – Directory to save the camera-to-tunnel calibrations

  • imgs (list) – Each image should be np.array of shape (height, width) and 8-bit. imgs[i] should correspond to internal_cals[i] and manual_detections[i]

  • internal_cals (list) –

    Each internal calibration should be of the form:

    [cameraMatrix, distCoeffs, sensor_resolution, sensor_size]
    
    • cameraMatrix is the (openCV formatted) camera matrix for the camera

    • distCoeffs is the (openCV formatted) distortion coefficients for the camera

    • sensor_resolution is a tuple of the full pixel resolution of the camera (which can be larger than the images of the imgs input)

    • sensor_size is a tuple of the physical sensor size in inches

    internal_cals[i] should correspond to imgs[i] and manual_detections[i]

  • manual_detections (list) –

    Each manual detection using PASCAL VOC format. Each manual detection is a dict with following the keys:

    • ’class’ denoting the target_type

    • ’x1’ denoting the left edge of the bounding box

    • ’y1’ denoting the top edge of the bounding box

    • ’x2’ denoting the right edge of the bounding box

    • ’y2’ denoting the bottom edge of the bounding box

    manual_detections[i] should correspond to imgs[i] and internal_cals[i]

  • tunnel_vals (dict) – tunnel_vals has the keys ALPHA, BETA, PHI, and STRUTZ which denote the model’s commanded position in the UPWT. For tests without this type of model positioning mechanism, set all values to 0.0

  • tgts_all (list) – Each target is a dict with (at a minimum) a ‘target_type’, ‘tvec’, and ‘norm’ attribute. The ‘target_type’ is a string for the type of target, usually ‘dot’. Currently, only targets with the ‘dot’ type are used. The ‘tvec’ attribute gives the target’s location and the ‘norm’ attribute gives the target’s normal vector Both are np.array vectors with shape (3, 1)

  • test_config (dict) –

    The dict must contain the following keys and values:
    • ’oblique_angle’ : maximum allowable oblique viewing angle

    • ’max_match_dist’ : maximum allowable matching distance between tgt projection and image target

    • ’dot_pad’ : pixel padding distance around center of dot target to use for sub-pixel localization

    • ’tunnel-cor_to_tgts_tvec’ : translation vector from center of rotation to tgts origin. For tests that do not have a center of rotation like the UPWT, set this value to [0.0, 0.0, 0.0]

    • ’tunnel-cor_to_tgts_rmat’ : rotation matrix from center of rotation to tgts origin. For tests that do not have a center of rotation like the UPWT, set this value to [[1, 0, 0], [0, 1, 0], [0, 0, 1]]

    • ’tunnel-cor_to_tunnel-origin_tvec’ : translation vector from center of rotation to tunnel origin. This can be [0.0, 0.0, 0.0]

    • ’tunnel-cor_to_tunnel-origin_rmat’ : rotation matrix from center of rotation to tunnel origin. This can be [[1, 0, 0], [0, 1, 0], [0, 0, 1]]

  • vis_checker (VisibilityChecker) – Visibility checker object with the relevant BVH and oblique viewing angle

  • match_thresh (int or float, default = 0.80) – Proportion of matched needed to form a consensus, optional default=0.8

tf_camera_tgts_thru_tunnel(camera_tunnel_cal, wtd, test_config)[source]

Returns the transformation from the camera to the model (tgts frame)

Parameters
  • camera_cal (list) –

    camera calibration in the form:

    [rmat__camera_tunnel, tvec__camera_tunnel, cameraMatrix, distCoeffs]
    

  • wtd (dict) – wind tunnel data as a dict with (at a minimum) the keys ‘ALPHA’, ‘BETA’, ‘PHI’, and ‘STRUTZ’. ALPHA, BETA, and PHI are tunnel angles in degrees. STRUTZ is the offset of the tunnel center of rotation for the z axis in inches

  • test_config (dict) – test configuration data as a dict with (at a minimum) the key ‘tunnel-cor_to_tgts_tvec’ representing the translation vector from the tunnel center of rotation to the model frame

Returns

  • rmat__camera_tgts (numpy.ndarray, shape (3, 3)) – Rotation matrix

  • tvec__camera_tgts (numpy.ndarray, shape (3, 1)) – Translation vector

tunnel_transform(ALPHA, BETA, PHI, STRUTZ, tvec__cor_tgts__tgts_frame)[source]

Calculates the transformation from the tunnel coordinate frame to the tgts frame

Note: This is not necessarily to the tunnel origin, just some fixed point in the tunnel (fixed within a tunnel test). If STRUTZ = STRUTZ_abs then it will be the tunnel origin

Parameters
  • ALPHA (float) – Tunnel alpha in degrees

  • BETA (float) – Tunnel beta in degrees

  • PHI (float) – Tunnel phi in degrees

  • STRUTZ (float) – STRUTZ location of the UPWT strut

  • tvec__cor_tgts__tgts_frame (numpy.ndarray, shape (3, 1), dtype float) – Translation vector from the tunnel center of rotation to the tgts frame in the tgts frame. The tgts frame is a fixed distance from the tunnel point of rotation from the tgts frame’s point of view, that translation vector is always along the x axis

Returns

  • rotation_matrix (numpy.ndarray, shape (3, 3)) – Rotation matrix from tgts frame to tunnel frame

  • tvec__tunnel_tgts__tunnel_frame (numpy.ndarray, shape (3, 1)) – Translation vector from tgts frame to tunnel frame