def test_parse_echorequest_packet_v3():
    """Test parsing a NatNet 3.0 packet containing an EchoRequest message."""
    data = open('test_data/echorequest_packet_v3.bin', 'rb').read()
    echo_request = deserialize(data, Version(3),
                               strict=True)  # type: EchoRequestMessage

    assert echo_request.timestamp == 278554190
def test_parse_echoresponse_packet_v3():
    """Test parsing a NatNet 3.0 packet containing an EchoResponse message."""
    packet = open('test_data/echoresponse_packet_v3.bin', 'rb').read()
    echo_response = deserialize(packet, Version(3),
                                strict=True)  # type: EchoResponseMessage

    assert echo_response.request_timestamp == 278554190
    assert echo_response.received_timestamp == 1416498545924
Beispiel #3
0
def test_parse_connect_packet_v3():
    """Test parsing a NatNet 3.0 packet containing a Connect message."""
    data = open('test_data/connect_packet_v3.bin', 'rb').read()
    info = deserialize(data, Version(3), strict=True)  # type: ConnectMessage

    assert info.payload == 'NatNetLib'
    assert info.version1 == Version(3)
    assert info.version2 == Version(3)
def test_parse_serverinfo_packet_v2():
    """Test parsing a NatNet 2.10 packet containing a ServerInfo message."""
    packet = open('test_data/serverinfo_packet_v2.bin', 'rb').read()
    info = deserialize(packet, Version(3), strict=True)  # type: ServerInfoMessage

    # These values are verified against SampleClient

    assert info.app_name == u'Motive'
    assert info.app_version == Version(1, 10)
    assert info.natnet_version == Version(2, 10)
    assert info.high_resolution_clock_frequency is None
    assert info.connection_info is None
def test_parse_serverinfo_packet_v3():
    """Test parsing a NatNet 3.0 packet containing a ServerInfo message."""
    packet = open('test_data/serverinfo_packet_v3.bin', 'rb').read()
    info = deserialize(packet, Version(3), strict=True)  # type: ServerInfoMessage

    # These values are verified against SampleClient where easy

    assert info.app_name == u'Motive'
    assert info.app_version == Version(2, 1)
    assert info.natnet_version == Version(3)
    assert info.high_resolution_clock_frequency == 3312787
    assert info.connection_info.data_port == 1511
    assert info.connection_info.multicast == True  # noqa: E712
    assert info.connection_info.multicast_address == u'239.255.42.99'
def test_parse_modeldef_packet_skeleton_v3():
    """Test parsing a NatNet 3.0 packet containing a ModelDefinitions message with skeletons."""
    packet = open('test_data/modeldef_packet_skeleton_v3.bin', 'rb').read()
    modeldef = deserialize(packet, Version(3),
                           strict=True)  # type: ModelDefinitionsMessage

    # TODO: Verify against SampleClient

    assert len(modeldef.models) == 3

    # Skeleton description
    sd = modeldef.models[0]  # type: SkeletonDescription
    assert type(sd) == SkeletonDescription
    assert sd.name == 'Skeleton 002'
    assert sd.id_ == 3
    assert len(sd.rigid_bodies) == 21
    assert [body.name for body in sd.rigid_bodies] == [
        'Skeleton 002_Hip', 'Skeleton 002_Ab', 'Skeleton 002_Chest',
        'Skeleton 002_Neck', 'Skeleton 002_Head', 'Skeleton 002_LShoulder',
        'Skeleton 002_LUArm', 'Skeleton 002_LFArm', 'Skeleton 002_LHand',
        'Skeleton 002_RShoulder', 'Skeleton 002_RUArm', 'Skeleton 002_RFArm',
        'Skeleton 002_RHand', 'Skeleton 002_LThigh', 'Skeleton 002_LShin',
        'Skeleton 002_LFoot', 'Skeleton 002_RThigh', 'Skeleton 002_RShin',
        'Skeleton 002_RFoot', 'Skeleton 002_LToe', 'Skeleton 002_RToe'
    ]

    # Skeleton markerset description
    ms = modeldef.models[1]  # type: MarkersetDescription
    assert type(ms) == MarkersetDescription
    assert ms.name == 'Skeleton 002'
    assert ms.marker_names == [
        'WaistLFront', 'WaistRFront', 'WaistLBack', 'WaistRBack', 'BackTop',
        'Chest', 'BackLeft', 'BackRight', 'HeadTop', 'HeadFront', 'HeadSide',
        'LShoulderBack', 'LShoulderTop', 'LElbowOut', 'LUArmHigh', 'LHandOut',
        'LWristOut', 'LWristIn', 'RShoulderBack', 'RShoulderTop', 'RElbowOut',
        'RUArmHigh', 'RHandOut', 'RWristOut', 'RWristIn', 'LKneeOut', 'LThigh',
        'LAnkleOut', 'LShin', 'LToeOut', 'LToeIn', 'RKneeOut', 'RThigh',
        'RAnkleOut', 'RShin', 'RToeOut', 'RToeIn'
    ]

    # 'all' markerset definition
    ms2 = modeldef.models[2]  # type: MarkersetDescription
    assert type(ms2) == MarkersetDescription
    assert ms2.name == 'all'
    assert ms2.marker_names == ms.marker_names
Beispiel #7
0
def test_parse_modeldef_packet_v3():
    """Test parsing a NatNet 3.0 packet containing a ModelDefinitions message."""
    packet = open('test_data/modeldef_packet_v3.bin', 'rb').read()
    modeldef = deserialize(packet, Version(3),
                           strict=True)  # type: ModelDefinitionsMessage

    # These values are verified against SampleClient where easy

    assert len(modeldef.models) == 3

    # RaceQuad rigid body description
    rb = modeldef.models[0]  # type:  RigidBodyDescription
    assert type(rb) == RigidBodyDescription
    assert rb.name == 'RaceQuad'
    assert rb.id_ == 2
    assert rb.parent_id == -1
    assert rb.offset_from_parent == (0.0, 0.0, 0.0)
    assert rb.marker_positions[0] == pytest.approx(
        (0.16115899, 0.0350516, -0.0321813))
    assert rb.marker_positions[1] == pytest.approx(
        (-0.030819, 0.0397819, -0.0219901))
    assert rb.marker_positions[2] == pytest.approx(
        (0.18753099, -0.0333833, 0.148081))
    assert rb.marker_positions[3] == pytest.approx(
        (-0.0748715, 6.68607e-05, 0.0329233))
    assert rb.marker_positions[4] == pytest.approx(
        (-0.0580382, -0.0319419, -0.136807))

    # RaceQuad markerset definition
    ms1 = modeldef.models[1]  # type: MarkersetDescription
    assert type(ms1) == MarkersetDescription
    assert ms1.name == 'RaceQuad'
    assert ms1.marker_names == [
        'Marker1', 'Marker2', 'Marker3', 'Marker4', 'Marker5'
    ]

    # 'all' markerset definition
    ms2 = modeldef.models[2]  # type: MarkersetDescription
    assert type(ms2) == MarkersetDescription
    assert ms2.name == 'all'
    assert ms2.marker_names == [
        'RaceQuad_1', 'RaceQuad_2', 'RaceQuad_3', 'RaceQuad_4', 'RaceQuad_5'
    ]
def test_parse_modeldef_packet_v3_2():
    """Test parsing a NatNet 3.0 packet from Motive 2.1 containing mystery id=5 models."""
    packet = open('test_data/modeldef_packet_v3_2.bin', 'rb').read()
    modeldef = deserialize(packet, Version(3),
                           strict=True)  # type: ModelDefinitionsMessage

    assert len(modeldef.models) == 7

    # Crossbow rigid body description
    rb = modeldef.models[0]  # type:  RigidBodyDescription
    assert type(rb) == RigidBodyDescription
    assert rb.name == 'crossbow'

    # Crossbow markerset definition
    ms1 = modeldef.models[1]  # type: MarkersetDescription
    assert type(ms1) == MarkersetDescription
    assert ms1.name == 'crossbow'

    # 'all' markerset definition
    ms2 = modeldef.models[2]  # type: MarkersetDescription
    assert type(ms2) == MarkersetDescription
    assert ms2.name == 'all'

    # Camera definitions
    cam1 = modeldef.models[3]  # type: CameraDescription
    assert type(cam1) == CameraDescription
    assert cam1.name == "Prime 13 #28108"

    cam2 = modeldef.models[4]  # type: CameraDescription
    assert type(cam1) == CameraDescription
    assert cam2.name == "Prime 13 #28107"

    cam3 = modeldef.models[5]  # type: CameraDescription
    assert type(cam1) == CameraDescription
    assert cam3.name == "Prime 13 #28105"

    cam4 = modeldef.models[6]  # type: CameraDescription
    assert type(cam1) == CameraDescription
    assert cam4.name == "Prime 13 #28106"
Beispiel #9
0
def test_parse_requestmodeldef_packet_v3():
    """Test parsing a NatNet 3.0 packet containing a RequestModelDefinitions message."""
    data = open('test_data/requestmodeldef_packet_v3.bin', 'rb').read()
    deserialize(data, Version(3), strict=True)
def test_parse_modeldef_packet_v2():
    """Test parsing a NatNet 2.10 packet containing a ModelDefinitions message."""
    packet = open('test_data/modeldef_packet_v2.bin', 'rb').read()
    modeldef = deserialize(packet, Version(2, 10),
                           strict=True)  # type: ModelDefinitionsMessage

    # TODO: Verify against SampleClient

    assert len(modeldef.models) == 5

    # RigidBody 1 rigid body description
    rb = modeldef.models[0]  # type: RigidBodyDescription
    assert type(rb) == RigidBodyDescription
    assert rb.name == 'RigidBody 1'
    assert rb.id_ == 1
    assert rb.parent_id == -1
    assert rb.offset_from_parent == (0.0, 0.0, 0.0)

    # RigidBody 1 markerset description
    ms1 = modeldef.models[1]  # type: MarkersetDescription
    assert type(ms1) == MarkersetDescription
    assert ms1.name == 'RigidBody 1'
    assert ms1.marker_names == ['Marker1', 'Marker2', 'Marker3']

    # Karlie skeleton description
    sd = modeldef.models[2]  # type: SkeletonDescription
    assert type(sd) == SkeletonDescription
    assert sd.name == 'Karlie'
    assert sd.id_ == 4
    assert len(sd.rigid_bodies) == 21
    assert [body.name for body in sd.rigid_bodies] == [
        'Karlie_Hip', 'Karlie_Ab', 'Karlie_Chest', 'Karlie_Neck',
        'Karlie_Head', 'Karlie_LShoulder', 'Karlie_LUArm', 'Karlie_LFArm',
        'Karlie_LHand', 'Karlie_RShoulder', 'Karlie_RUArm', 'Karlie_RFArm',
        'Karlie_RHand', 'Karlie_LThigh', 'Karlie_LShin', 'Karlie_LFoot',
        'Karlie_RThigh', 'Karlie_RShin', 'Karlie_RFoot', 'Karlie_LToe',
        'Karlie_RToe'
    ]

    # Karlie markerset description
    ms2 = modeldef.models[3]  # type: MarkersetDescription
    assert type(ms2) == MarkersetDescription
    assert ms2.name == 'Karlie'
    assert ms2.marker_names == [
        'Karlie_WaistLFront', 'Karlie_WaistRFront', 'Karlie_WaistLBack',
        'Karlie_WaistRBack', 'Karlie_BackTop', 'Karlie_Chest',
        'Karlie_BackLeft', 'Karlie_BackRight', 'Karlie_HeadTop',
        'Karlie_HeadFront', 'Karlie_HeadSide', 'Karlie_LShoulderBack',
        'Karlie_LShoulderTop', 'Karlie_LElbowOut', 'Karlie_LUArmHigh',
        'Karlie_LHandOut', 'Karlie_LWristOut', 'Karlie_LWristIn',
        'Karlie_RShoulderBack', 'Karlie_RShoulderTop', 'Karlie_RElbowOut',
        'Karlie_RUArmHigh', 'Karlie_RHandOut', 'Karlie_RWristOut',
        'Karlie_RWristIn', 'Karlie_LKneeOut', 'Karlie_LThigh',
        'Karlie_LAnkleOut', 'Karlie_LShin', 'Karlie_LToeOut', 'Karlie_LToeIn',
        'Karlie_RKneeOut', 'Karlie_RThigh', 'Karlie_RAnkleOut', 'Karlie_RShin',
        'Karlie_RToeOut', 'Karlie_RToeIn'
    ]

    # 'all' markerset definition
    ms3 = modeldef.models[4]  # type: MarkersetDescription
    assert type(ms3) == MarkersetDescription
    assert ms3.name == 'all'
    assert ms3.marker_names == [
        'RigidBody 1_1', 'RigidBody 1_2', 'RigidBody 1_3',
        'Karlie_WaistLFront', 'Karlie_WaistRFront', 'Karlie_WaistLBack',
        'Karlie_WaistRBack', 'Karlie_BackTop', 'Karlie_Chest',
        'Karlie_BackLeft', 'Karlie_BackRight', 'Karlie_HeadTop',
        'Karlie_HeadFront', 'Karlie_HeadSide', 'Karlie_LShoulderBack',
        'Karlie_LShoulderTop', 'Karlie_LElbowOut', 'Karlie_LUArmHigh',
        'Karlie_LHandOut', 'Karlie_LWristOut', 'Karlie_LWristIn',
        'Karlie_RShoulderBack', 'Karlie_RShoulderTop', 'Karlie_RElbowOut',
        'Karlie_RUArmHigh', 'Karlie_RHandOut', 'Karlie_RWristOut',
        'Karlie_RWristIn', 'Karlie_LKneeOut', 'Karlie_LThigh',
        'Karlie_LAnkleOut', 'Karlie_LShin', 'Karlie_LToeOut', 'Karlie_LToeIn',
        'Karlie_RKneeOut', 'Karlie_RThigh', 'Karlie_RAnkleOut', 'Karlie_RShin',
        'Karlie_RToeOut', 'Karlie_RToeIn'
    ]
Beispiel #11
0
def test_parse_mocapframe_packet_v3():
    """Test parsing a NatNet 3.0 packet containing a MocapFrame."""
    packet = open('test_data/mocapframe_packet_v3.bin', 'rb').read()
    frame = deserialize(packet, Version(3),
                        strict=True)  # type: MocapFrameMessage

    # These values are verified against SampleClient where easy

    assert frame.frame_number == 162734
    assert len(frame.markersets) == 0

    assert len(frame.rigid_bodies) == 1
    body = frame.rigid_bodies[0]
    assert body.id_ == 2
    assert body.position == pytest.approx((0.1744466, 1.4471314, -0.7343040))
    assert body.orientation == pytest.approx(
        (-0.05459423, 0.5099482, 0.04370357, -0.8573577))
    assert body.mean_error == pytest.approx(0.0005152203)
    assert body.tracking_valid

    assert len(frame.skeletons) == 0

    assert len(frame.labelled_markers) == 6
    marker0 = frame.labelled_markers[0]  # type: LabelledMarker
    assert marker0.model_id == 2
    assert marker0.marker_id == 1
    assert marker0.position == pytest.approx(
        (0.1272162, 1.5050275, -0.8858284))
    assert marker0.size == pytest.approx(0.02143982)
    assert marker0._params == 10
    assert not marker0.occluded
    assert marker0.point_cloud_solved
    assert not marker0.model_solved
    assert marker0.has_model
    assert not marker0.unlabelled
    assert not marker0.active
    assert marker0.residual == pytest.approx(0.0002074828)
    # Assume markers 1-4 are correct if 0 and 5 are
    marker5 = frame.labelled_markers[5]
    assert marker5.model_id == 0
    assert marker5.marker_id == 50007
    assert marker5.position == pytest.approx(
        (0.1708117, 1.5076591, -0.8402346))
    assert marker5.size == pytest.approx(0.02015734)
    assert marker5._params == 18
    assert not marker5.occluded
    assert marker5.point_cloud_solved
    assert not marker5.model_solved
    assert not marker5.has_model
    assert marker5.unlabelled
    assert not marker5.active
    assert marker5.residual == pytest.approx(0.0005593782)

    assert len(frame.force_plates) == 0
    assert len(frame.devices) == 0

    assert frame.timing_info.timecode == 0
    assert frame.timing_info.timecode_subframe == 0
    assert frame.timing_info.timestamp == pytest.approx(1356.117)
    assert frame.timing_info.camera_mid_exposure_timestamp == 1416497730518
    assert frame.timing_info.camera_data_received_timestamp == 1416497745808
    assert frame.timing_info.transmit_timestamp == 1416497748722

    assert not frame.is_recording
    assert not frame.tracked_models_changed
Beispiel #12
0
def test_parse_mocapframe_packet_v2():
    """Test parsing a NatNet 2.10 packet containing a MocapFrame."""
    # Packet 778 from Omar's data
    packet = open('test_data/mocapframe_packet_v2.bin', 'rb').read()
    frame = deserialize(packet, Version(2, 10),
                        strict=True)  # type: MocapFrameMessage

    # These values are verified against SampleClient where easy

    assert frame.frame_number == 109238
    assert len(frame.markersets) == 3
    assert frame.markersets[0].name == 'RigidBody 1'
    assert frame.markersets[1].name == 'Karlie'
    assert frame.markersets[2].name == 'all'

    assert len(frame.rigid_bodies) == 1
    body = frame.rigid_bodies[0]
    assert body.id_ == 1
    assert body.position == pytest.approx((1.38, 1.21, 1.62), abs=0.005)
    assert body.orientation == pytest.approx((-0.74, 0.51, 0.12, -0.42),
                                             abs=0.005)
    assert body.mean_error == pytest.approx(0.0)
    assert not body.tracking_valid

    assert len(frame.skeletons) == 1
    skeleton = frame.skeletons[0]
    assert skeleton.id_ == 4
    assert len(skeleton.rigid_bodies) == 21
    bone0 = skeleton.rigid_bodies[0]
    assert bone0.id_ == 262145
    assert bone0.position == pytest.approx((0.50, 0.85, 0.43), abs=0.005)
    assert bone0.orientation == pytest.approx((0.02, 0.80, 0.01, 0.60),
                                              abs=0.005)
    # skip 19 bones
    bone20 = skeleton.rigid_bodies[20]
    assert bone20.id_ == 262165
    assert bone20.position == pytest.approx((-0.00, -0.06, 0.13), abs=0.005)
    assert bone20.orientation == pytest.approx((-0.00, 0.00, 0.00, -1.00),
                                               abs=0.005)

    assert len(frame.labelled_markers) == 44
    marker0 = frame.labelled_markers[0]
    assert marker0.model_id == 4
    assert marker0.marker_id == 5
    assert marker0.position == pytest.approx((0.54, 0.93, 0.28), abs=0.005)
    assert marker0.size == pytest.approx(0.02, abs=0.005)
    assert not marker0.occluded
    assert marker0.point_cloud_solved
    assert not marker0.model_solved
    # Skip 42 markers
    marker43 = frame.labelled_markers[43]
    assert marker43.model_id == 0
    assert marker43.marker_id == 7637
    assert marker43.position == pytest.approx((1.13, 1.48, 1.42), abs=0.005)
    assert marker43.size == pytest.approx(0.01, abs=0.005)
    # assert marker5._params == 18
    assert not marker43.occluded
    assert marker43.point_cloud_solved
    assert not marker43.model_solved

    assert len(frame.force_plates) == 0
    assert len(frame.devices) == 0

    assert frame.timing_info.timecode == 0
    assert frame.timing_info.timecode_subframe == 0
    assert frame.timing_info.timestamp == pytest.approx(910.32, abs=0.005)

    assert not frame.is_recording
    assert not frame.tracked_models_changed