Skip to content

calibration

coord_transform(obj_coord_pixels, cal_vec) ¤

Calculate x and y coordinates (in cm) based on the coefficients (c_1 - c_8) from the fractional transformation and the pixel coordinates of each point x = (c_1u + c_2v + c_3)/(1 + c_7u + c_8v) y = (c_4u + c_5v + c_6)/(1 + c_7u + c_8v)

Parameters:

Name Type Description Default
obj_coord_pixels tuple

the (row, col) tuple of the pixel. Note that Y comes first

required
cal_vec list

Parameters of DLT

required

Returns:

Name Type Description
list

The [x,y] coordiate in local space. Note that X comes first!

Source code in motiontracker\calibration.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
def coord_transform(obj_coord_pixels, cal_vec):
    """Calculate x and y coordinates (in cm) based on the coefficients (c_1 - c_8) from
        the fractional transformation and the pixel coordinates of each point
        x = (c_1*u + c_2*v + c_3)/(1 + c_7*u + c_8*v)
        y = (c_4*u + c_5*v + c_6)/(1 + c_7*u + c_8*v)

    Args:
        obj_coord_pixels (tuple): the (row, col) tuple of the pixel. Note that Y comes first
        cal_vec (list): Parameters of DLT

    Returns:
        list: The [x,y] coordiate in local space. Note that X comes first!
    """    

    obj_x = (cal_vec[0]*obj_coord_pixels[1] + cal_vec[1]*obj_coord_pixels[0] + cal_vec[2])/\
    (1.0 + cal_vec[6]*obj_coord_pixels[1] + cal_vec[7]*obj_coord_pixels[0])

    obj_y = (cal_vec[3]*obj_coord_pixels[1] + cal_vec[4]*obj_coord_pixels[0] + cal_vec[5])/\
    (1.0 + cal_vec[6]*obj_coord_pixels[1] + cal_vec[7]*obj_coord_pixels[0])

    return [obj_x, obj_y]

get_hsl_lo_hi(hsv, px, py, **kwargs) ¤

Get the lo and hi hsl values that should threshold the pixel at (py,px)

Source code in motiontracker\calibration.py
49
50
51
52
53
54
55
56
57
58
def get_hsl_lo_hi(hsv:np.ndarray, px:int, py:int, **kwargs):
    """ Get the lo and hi hsl values that should threshold the pixel at (py,px)"""
    binary_image = np.zeros(shape=(hsv.shape[0], hsv.shape[1]), dtype=np.uint8)
    binary_image = region_growing(hsv, (py, px), binary_image, **kwargs)
    binary_image = binary_image.astype(bool)
    mean = hsv[binary_image, :].mean(axis=0)
    std = hsv[binary_image, :].std(axis=0)
    hsv_lo = np.clip(mean - 3 * std, a_min=[0, 0, 0], a_max=[180, 255, 255]).astype(int)
    hsv_hi = np.clip(mean + 3 * std, a_min=[0, 0, 0], a_max=[180, 255, 255]).astype(int)
    return hsv_lo, hsv_hi