def test_bbb_get_detections(frame_data, frame_dp_data, frame_cvp_data, frame_truth_data): """Extracts correct detections from old and new pipeline data.""" diffKey = 'candidateIdx' detections = _get_detections(frame_dp_data) assert not hasattr(detections[0], diffKey) detections = _get_detections(frame_cvp_data) assert hasattr(detections[0], diffKey) detections = _get_detections(frame_truth_data) assert hasattr(detections[0], 'readability') # Important note: the default value for detectionsUnion is detectionsCVP assert frame_data.detectionsUnion.which() == 'detectionsCVP'
def bbb_check_frame_data(frame, arr, expected_keys): """Helper to compare frame data to numpy array.""" # check if we have all the expected keys in the array (and only these) expected_keys = set(expected_keys) - set(['detectionsUnion']) assert expected_keys == set(arr.dtype.names) assert len(expected_keys) == len(arr.dtype.names) detection_string_fields = ('readability') detections = _get_detections(frame) for i, detection in enumerate(detections): # check if the values are as expected for key in expected_keys: if key == 'camId': continue elif key == 'decodedId' and frame.detectionsUnion.which( ) == 'detectionsDP': assert np.allclose(arr[key][i], np.array([detection.decodedId[0] / 255.] * len(detection.decodedId)), atol=0.5 / 255.) elif key == 'descriptor': assert np.all(arr[key][i] == getattr(detection, key)) elif key == 'frameId': assert np.all(arr[key] == getattr(frame, 'id')) elif hasattr(frame, key): # all detections are from the same frame # so we expect the whole column to have the same value. assert np.all(arr[key] == getattr(frame, key)) elif key in detection_string_fields: assert arr[key][i].decode('UTF-8') == getattr(detection, key) else: assert arr[key][i] == getattr(detection, key)
def bbb_check_frame_data(frame, arr, expected_keys): """Helper to compare frame data to numpy array.""" # check if we have all the expected keys in the array (and only these) expected_keys = set(expected_keys) - set(['detectionsUnion']) assert expected_keys == set(arr.dtype.names) assert len(expected_keys) == len(arr.dtype.names) detection_string_fields = ('readability') detections = _get_detections(frame) for i, detection in enumerate(detections): # check if the values are as expected for key in expected_keys: if key == 'camId': continue elif key == 'decodedId' and frame.detectionsUnion.which() == 'detectionsDP': assert np.allclose(arr[key][i], np.array([detection.decodedId[0] / 255.] * len(detection.decodedId)), atol=0.5/255.) elif key == 'descriptor': assert np.all(arr[key][i] == getattr(detection, key)) elif key == 'frameId': assert np.all(arr[key] == getattr(frame, 'id')) elif hasattr(frame, key): # all detections are from the same frame # so we expect the whole column to have the same value. assert np.all(arr[key] == getattr(frame, key)) elif key in detection_string_fields: assert arr[key][i].decode('UTF-8') == getattr(detection, key) else: assert arr[key][i] == getattr(detection, key)
def test_bbb_convert_detections(frame_data_all): """Detections are correctly converted to np array and frame is ignored.""" frame = frame_data_all expected_keys = get_detection_keys(frame.detectionsUnion.which()) detections = _get_detections(frame) arr = _convert_detections_to_numpy(detections, keys=expected_keys) bbb_check_frame_data(frame, arr, expected_keys) # now compare behaviour of helper and parent function arr_frame = convert_frame_to_numpy(frame, keys=expected_keys) assert np.all(arr == arr_frame)