Skip to content

Commit 430433d

Browse files
committed
Added support to attach clip to detected object (ObjectDetection) effect
This feature let's the user attach a clip to an object detected by the Object Detection effect, in the same way it is done with the Tracker Effect.
1 parent ceefbf8 commit 430433d

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/windows/views/properties_tableview.py

+18-20
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from functools import partial
3232
from operator import itemgetter
33-
from PyQt5.QtCore import Qt, QRectF, QLocale, pyqtSignal, QTimer
33+
from PyQt5.QtCore import Qt, QRectF, QRect, QLocale, pyqtSignal, QTimer
3434
from PyQt5.QtGui import (
3535
QIcon, QColor, QBrush, QPen, QPalette, QPixmap,
3636
QPainter, QPainterPath, QLinearGradient, QFont, QFontInfo,
@@ -450,28 +450,26 @@ def contextMenuEvent(self, event):
450450
clip_instance_icon = clip_index.data(Qt.DecorationRole)
451451
# Get the pixmap of the clip icon
452452
icon_size = 64
453-
icon_pixmap = clip_instance_icon.pixmap(icon_size)
453+
icon_pixmap = clip_instance_icon.pixmap(icon_size, icon_size)
454454
# Add tracked objects to the selection menu
455455
tracked_objects = []
456456
for effect in clip_instance_data["effects"]:
457-
# Check if the effect has the "box_id" property, i.e., is the Tracker effect
458-
if ("box_id" in effect.keys()):
459-
# Get the Tracker properties from the timeline
460-
tracker_effect = timeline_instance.GetClipEffect(effect["id"])
461-
tracker_effect_properties = json.loads(tracker_effect.PropertiesJSON(1))
462-
x1 = tracker_effect_properties["x1"]["value"]
463-
x2 = tracker_effect_properties["x2"]["value"]
464-
y1 = tracker_effect_properties["y1"]["value"]
465-
y2 = tracker_effect_properties["y2"]["value"]
466-
# Get the tracked object's icon from the clip's icon - different adjustment if it's an image or video file
467-
if clip_instance_data["reader"]["has_single_image"]:
468-
tracked_object_icon = QIcon(icon_pixmap.copy(x1*icon_size, y1*icon_size, (x2-x1)*icon_size, (y2-y1)*icon_size*(2/3)))
469-
else:
470-
tracked_object_icon = QIcon(icon_pixmap.copy(x1*icon_size, y1*icon_size, (x2-x1)*icon_size, (y2-y1)*icon_size/2))
471-
tracked_objects.append({"name": effect["box_id"],
472-
"value": effect["box_id"],
473-
"selected": False,
474-
"icon": tracked_object_icon})
457+
# Iterate through the effect properties
458+
for effect_key in effect.keys():
459+
# 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 the Tracked Object properties from the timeline
462+
tracked_object_properties = json.loads(timeline_instance.GetTrackedObjectValues(effect[effect_key]))
463+
x1 = tracked_object_properties["x1"]
464+
x2 = tracked_object_properties["x2"]
465+
y1 = tracked_object_properties["y1"]
466+
y2 = tracked_object_properties["y2"]
467+
# Get the tracked object's icon from the clip's icon
468+
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)
469+
tracked_objects.append({"name": effect[effect_key],
470+
"value": effect[effect_key],
471+
"selected": False,
472+
"icon": QIcon(tracked_object_icon)})
475473
clips_choices.append({"name": clip_instance_data["title"],
476474
"value": tracked_objects,
477475
"selected": False,

src/windows/views/webview.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3023,10 +3023,11 @@ def callback(self, effect_names, callback_data):
30233023

30243024
effect_json = json.loads(effect.Json())
30253025

3026-
# Generate box_id for the Tracker Keyframe
3027-
if "box_id" in effect_json:
3028-
boxId = get_app().project.generate_id()
3029-
effect_json["box_id"] = boxId
3026+
# Generate box_id for the TrackedObjectBBox object
3027+
for effect_key in effect_json.keys():
3028+
if effect_key.startswith("box_id"):
3029+
boxId = get_app().project.generate_id()
3030+
effect_json[effect_key] = boxId
30303031

30313032
# Append effect JSON to clip
30323033
clip.data["effects"].append(effect_json)

0 commit comments

Comments
 (0)