Skip to content

Commit

Permalink
Refactored example code (#140)
Browse files Browse the repository at this point in the history
* Create complete dynamic clip as modification of recommended dynamic clip

* Create complete static clip as modification of complete dynamic clip plus recommended static clip modifications.

---------

Co-authored-by: James Uren <[email protected]>
  • Loading branch information
JGoldstone and jamesmosys authored Jan 16, 2025
1 parent bdb1a37 commit fb5cda4
Showing 1 changed file with 55 additions and 45 deletions.
100 changes: 55 additions & 45 deletions src/main/python/camdkit/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,37 @@
from camdkit.model import Clip, OPENTRACKIO_PROTOCOL_NAME, OPENTRACKIO_PROTOCOL_VERSION

def get_recommended_static_example():
clip = _get_recommended_dynamic_clip()
clip = _get_recommended_static_clip()
return clip.to_json(0)

def get_complete_static_example():
clip = _get_complete_static_clip()
clip_json = clip.to_json(0)
# Add additional custom data
clip_json["custom"] = {
"pot1": 2435,
"button1": False
}
return clip_json

def _add_recommended_static_clip_parameters(clip: Clip) -> Clip:
clip.camera_label = "A"
clip.lens_make = "LensMaker"
clip.lens_model = "Model15"
clip.active_sensor_physical_dimensions = Dimensions(width=36.0,height=24.0)
return clip.to_json(0)
return clip

def get_complete_static_example():
clip = _get_complete_dynamic_clip()
clip.active_sensor_physical_dimensions = Dimensions(width=36.0,height=24.0)
def _get_recommended_static_clip() -> Clip:
clip: Clip = _get_recommended_dynamic_clip()
_add_recommended_static_clip_parameters(clip)
return clip

def _get_complete_static_clip() -> Clip:
clip: Clip = _get_complete_dynamic_clip()
_add_recommended_static_clip_parameters(clip)
# no augmentations, just additions
clip.active_sensor_resolution = Dimensions(width=3840,height=2160)
clip.anamorphic_squeeze = 1
clip.camera_label = "A"
clip.camera_make = "CameraMaker"
clip.camera_model = "Model20"
clip.camera_firmware = "1.2.3"
Expand All @@ -34,23 +52,15 @@ def get_complete_static_example():
clip.lens_distortion_is_projection = True
clip.lens_distortion_overscan_max = 1.2
clip.lens_undistortion_overscan_max = 1.3
clip.lens_make = "LensMaker"
clip.lens_model = "Model15"
clip.lens_nominal_focal_length = 14
clip.lens_serial_number = "1234567890A"
clip.shutter_angle = 45.0
clip.tracker_model = "Tracker"
clip.tracker_firmware = "1.2.3"
clip.tracker_make = "TrackerMaker"
clip.tracker_serial_number = "1234567890A"

clip_json = clip.to_json(0)
# Add additional custom data
clip_json["custom"] = {
"pot1": 2435,
"button1": False
}
return clip_json
return clip


def get_recommended_dynamic_example():
clip = _get_recommended_dynamic_clip()
Expand All @@ -67,25 +77,29 @@ def get_complete_dynamic_example():
}
return clip_json

def _example_transform_components() -> tuple[Vector3, Rotator3]:
return Vector3(x=1.0, y=2.0, z=3.0), Rotator3(pan=180.0, tilt=90.0, roll=45.0)

def _get_recommended_dynamic_clip():
clip = Clip()
# identity
clip.sample_id = (uuid.uuid4().urn,)
clip.source_id = (uuid.uuid4().urn,)
clip.source_number = (1,)
clip.protocol = (VersionedProtocol(OPENTRACKIO_PROTOCOL_NAME,OPENTRACKIO_PROTOCOL_VERSION,),)

clip.protocol = (VersionedProtocol(OPENTRACKIO_PROTOCOL_NAME,OPENTRACKIO_PROTOCOL_VERSION),)
# tracking
clip.tracker_status = ("Optical Good",)
clip.tracker_recording = (False,)
clip.tracker_slate = ("A101_A_4",)
clip.tracker_notes = ("Example generated sample.",)

# timing
clip.timing_mode = (TimingModeEnum.EXTERNAL,)
clip.timing_sample_rate = (Fraction(24000, 1001),)
clip.timing_timecode = (Timecode(1,2,3,4,TimecodeFormat(Fraction(24000, 1001))),)

v = Vector3(x=1.0, y=2.0, z=3.0)
r = Rotator3(pan=180.0, tilt=90.0, roll=45.0)
# transforms
v, r = _example_transform_components()
clip.transforms = ((Transform(translation=v, rotation=r, id="Camera"),),)
# lens
clip.lens_f_number = (4.0,)
clip.lens_focal_length = (24.305,)
clip.lens_focus_distance = (10.0,)
Expand All @@ -96,25 +110,26 @@ def _get_recommended_dynamic_clip():
return clip

def _get_complete_dynamic_clip():
clip = Clip()
clip.sample_id = (uuid.uuid4().urn,)
clip.source_id = (uuid.uuid4().urn,)
clip.source_number = (1,)
clip.protocol = (VersionedProtocol(OPENTRACKIO_PROTOCOL_NAME, OPENTRACKIO_PROTOCOL_VERSION),)
clip.related_sample_ids = ((uuid.uuid4().urn,uuid.uuid4().urn),)
clip.global_stage = (GlobalPosition(100.0,200.0,300.0,100.0,200.0,300.0),)

clip.tracker_status = ("Optical Good",)
clip.tracker_recording = (False,)
clip.tracker_slate = ("A101_A_4",)
clip.tracker_notes = ("Example generated sample.",)

clip = _get_recommended_dynamic_clip()
# augmenting recommended values
# timing
clip.timing_mode = (TimingModeEnum.INTERNAL,)
# transforms
v, r = _example_transform_components()
clip.transforms = ((Transform(translation=v, rotation=r, id="Dolly"),
Transform(translation=v, rotation=r, scale=v, id="Crane Arm", parentId="Dolly"),
Transform(translation=v, rotation=r, scale=v, id="Camera", parentId="Crane Arm")
),)
# lens
clip.lens_distortions = ((Distortion([1.0,2.0,3.0,4.0,5.0,6.0], [1.0,2.0], "Brown-Conrady D-U"), Distortion([1.0,2.0,3.0,4.0,5.0,6.0], [1.0,2.0], "Brown-Conrady U-D"),),)

# additions
# identity
clip.related_sample_ids = ((uuid.uuid4().urn,uuid.uuid4().urn),)
# timing
clip.timing_sample_timestamp = (Timestamp(1718806554, 500000000),)
clip.timing_recorded_timestamp = (Timestamp(1718806000, 500000000),)
clip.timing_sequence_number = (0,)
clip.timing_sample_rate = (Fraction(24000, 1001),)
clip.timing_timecode = (Timecode(1,2,3,4,TimecodeFormat(Fraction(24000, 1001))),)
clip.timing_synchronization = (Synchronization(
frequency=Fraction(24000,1001),
present=True,
Expand All @@ -127,26 +142,21 @@ def _get_complete_dynamic_clip():
),
offsets=SynchronizationOffsets(1.0,2.0,3.0)
),)

# transforms
clip.global_stage = (GlobalPosition(100.0,200.0,300.0,100.0,200.0,300.0),)
v = Vector3(x=1.0, y=2.0, z=3.0)
r = Rotator3(pan=180.0, tilt=90.0, roll=45.0)
clip.transforms = ((Transform(translation=v, rotation=r, id="Dolly"),
Transform(translation=v, rotation=r, scale=v, id="Crane Arm"),
Transform(translation=v, rotation=r, scale=v, id="Camera")
),)

# lens
clip.lens_f_number = (4.0,)
clip.lens_t_number = (4.1,)
clip.lens_focal_length = (24.305,)
clip.lens_focus_distance = (10.0,)
clip.lens_entrance_pupil_offset = (0.123,)
clip.lens_encoders = (FizEncoders(focus=0.1, iris=0.2, zoom=0.3),)
clip.lens_raw_encoders = (RawFizEncoders(focus=1000, iris=2000, zoom=3000),)
clip.lens_distortion_overscan = (1.1,)
clip.lens_undistortion_overscan = (1.2,)
clip.lens_exposure_falloff = (ExposureFalloff(1.0, 2.0, 3.0),)
clip.lens_distortions = ((Distortion([1.0,2.0,3.0,4.0,5.0,6.0], [1.0,2.0], "Brown-Conrady D-U"), Distortion([1.0,2.0,3.0,4.0,5.0,6.0], [1.0,2.0], "Brown-Conrady U-D"),),)
clip.lens_distortion_offset = (DistortionOffset(1.0, 2.0),)
clip.lens_projection_offset = (ProjectionOffset(0.1, 0.2),)
clip.lens_custom = ((1.0,2.0),)
return clip

0 comments on commit fb5cda4

Please sign in to comment.