@@ -419,6 +419,34 @@ def contextMenuEvent(self, event):
419
419
self .choices = []
420
420
self .menu_reset = False
421
421
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
+
422
450
# Handle clip attach options
423
451
if property_key == "attached_id" and not self .choices :
424
452
# Add all Clips as choices - initialize with None
@@ -457,20 +485,21 @@ def contextMenuEvent(self, event):
457
485
# Iterate through the effect properties
458
486
for effect_key in effect .keys ():
459
487
# 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-" ):
464
489
# Get current tracked object index
465
490
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 ))
467
493
visible = raw_properties_effect .get ('visible-' + tracked_obj_idx ).get ('value' )
494
+ # Check if the tracked object is visible in this frame
468
495
if visible :
469
496
# 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' ]
474
503
# Get the tracked object's icon from the clip's icon
475
504
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 )
476
505
tracked_objects .append ({"name" : effect [effect_key ],
0 commit comments