Skip to content

Commit f94ccb5

Browse files
committed
Added support to show the transform handler for the selected object
When using the ObjectDetection effect, it's now possible to select one detected object and update it's properties through it's transform handler.
1 parent 2ef5c07 commit f94ccb5

File tree

2 files changed

+47
-18
lines changed

2 files changed

+47
-18
lines changed

src/windows/video_widget.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,20 @@ def paintEvent(self, event, *args):
310310
# Get properties of clip at current frame
311311
raw_properties_effect = json.loads(self.transforming_effect_object.PropertiesJSON(clip_frame_number))
312312
for effect_key in raw_properties_effect.keys():
313-
if effect_key.startswith("box_id"):
313+
if effect_key.startswith("x1-"):
314314
# Get current tracked object index
315315
tracked_obj_idx = effect_key.split("-", 2)[1]
316316
# Check if the tracked object is visible in this frame
317-
visible = raw_properties_effect.get('visible-'+tracked_obj_idx).get('value')
317+
visible = raw_properties_effect['visible-'+tracked_obj_idx]['value']
318318
if visible:
319319
# Get current bounding box values
320-
r = raw_properties_effect.get('rotation-'+tracked_obj_idx).get('value')
321-
x1 = raw_properties_effect.get('x1-'+tracked_obj_idx).get('value')
322-
y1 = raw_properties_effect.get('y1-'+tracked_obj_idx).get('value')
323-
x2 = raw_properties_effect.get('x2-'+tracked_obj_idx).get('value')
324-
y2 = raw_properties_effect.get('y2-'+tracked_obj_idx).get('value')
320+
rotation = raw_properties_effect['rotation-'+tracked_obj_idx]['value']
321+
x1 = raw_properties_effect['x1-'+tracked_obj_idx]['value']
322+
y1 = raw_properties_effect['y1-'+tracked_obj_idx]['value']
323+
x2 = raw_properties_effect['x2-'+tracked_obj_idx]['value']
324+
y2 = raw_properties_effect['y2-'+tracked_obj_idx]['value']
325325
self.drawTransformHandler(painter, sx, sy, source_width, source_height, origin_x, origin_y,
326-
x1, y1, x2, y2, r)
326+
x1, y1, x2, y2, rotation)
327327
else:
328328
self.drawTransformHandler(painter, sx, sy, source_width, source_height, origin_x, origin_y)
329329

@@ -828,7 +828,7 @@ def mouseMoveEvent(self, event):
828828
raw_properties = json.loads(self.transforming_effect_object.PropertiesJSON(clip_frame_number))
829829

830830
for raw_property_key in raw_properties.keys():
831-
if raw_property_key.startswith("box_id"):
831+
if raw_property_key.startswith("x1-"):
832832
# Get current tracked object index
833833
tracked_obj_idx = raw_property_key.split("-", 2)[1]
834834
# Check if the tracked object is visible in this frame

src/windows/views/properties_tableview.py

+38-9
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,34 @@ def contextMenuEvent(self, event):
419419
self.choices = []
420420
self.menu_reset = False
421421

422+
# Handle selected object options (ObjectDetection effect)
423+
if property_key == "selected_object_index" and not self.choices:
424+
# Add visible objects as choices - initialize with the first visible object
425+
object_index_choices = [{
426+
"name": str(0),
427+
"value": str(0),
428+
"selected": False,
429+
"icon": QIcon()
430+
}]
431+
# Get all visible object's indexes
432+
timeline_instance = get_app().window.timeline_sync.timeline
433+
# Instantiate the effect
434+
effect = timeline_instance.GetClipEffect(clip_id)
435+
# Get effect's properties JSON
436+
effect_properties = json.loads(effect.PropertiesJSON(frame_number))
437+
for effect_key in effect_properties.keys():
438+
if effect_key.startswith("visible-"):
439+
if effect_properties[effect_key]["value"]:
440+
# Get visible object index
441+
object_index = effect_key.split("-", 2)[1]
442+
object_index_choices.append({
443+
"name": object_index,
444+
"value": object_index,
445+
"selected": False,
446+
"icon": QIcon()
447+
})
448+
self.choices.append({"name": _("Detected Objects"), "value": object_index_choices, "selected": False, "icon": None})
449+
422450
# Handle clip attach options
423451
if property_key == "attached_id" and not self.choices:
424452
# Add all Clips as choices - initialize with None
@@ -457,20 +485,21 @@ def contextMenuEvent(self, event):
457485
# Iterate through the effect properties
458486
for effect_key in effect.keys():
459487
# Check if the effect has the "box_id" property, i.e., is the Tracker or ObjectDetection effect
460-
if effect_key.startswith("box_id"):
461-
# Get effect's JSON properties for this frame
462-
effect_instance = timeline_instance.GetClipEffect(effect["id"])
463-
raw_properties_effect = json.loads(effect_instance.PropertiesJSON(frame_number))
488+
if effect_key.startswith("box_id-"):
464489
# Get current tracked object index
465490
tracked_obj_idx = effect_key.split("-", 2)[1]
466-
# Check if the tracked object is visible in this frame
491+
effect_instance = timeline_instance.GetClipEffect(effect["id"])
492+
raw_properties_effect = json.loads(effect_instance.PropertiesJSON(frame_number))
467493
visible = raw_properties_effect.get('visible-'+tracked_obj_idx).get('value')
494+
# Check if the tracked object is visible in this frame
468495
if visible:
469496
# Get the Tracked Object properties
470-
x1 = raw_properties_effect.get('x1-'+tracked_obj_idx).get('value')
471-
y1 = raw_properties_effect.get('y1-'+tracked_obj_idx).get('value')
472-
x2 = raw_properties_effect.get('x2-'+tracked_obj_idx).get('value')
473-
y2 = raw_properties_effect.get('y2-'+tracked_obj_idx).get('value')
497+
tracked_obj_id = effect['box_id-'+tracked_obj_idx]
498+
tracked_obj_properties = json.loads(timeline_instance.GetTrackedObjectValues(tracked_obj_id, 0))
499+
x1 = tracked_obj_properties['x1']
500+
y1 = tracked_obj_properties['y1']
501+
x2 = tracked_obj_properties['x2']
502+
y2 = tracked_obj_properties['y2']
474503
# Get the tracked object's icon from the clip's icon
475504
tracked_object_icon = icon_pixmap.copy(QRect(x1*icon_size, y1*icon_size, (x2-x1)*icon_size, (y2-y1)*icon_size/2)).scaled(icon_size, icon_size)
476505
tracked_objects.append({"name": effect[effect_key],

0 commit comments

Comments
 (0)