[Bf-extensions-cvs] [88918dce] master: Autotrack: Cleanup, add some report messages
lijenstina
noreply at git.blender.org
Sun Jul 23 15:02:47 CEST 2017
Commit: 88918dcef321754ebb0a1859e88b2d538f7c87d4
Author: lijenstina
Date: Sun Jul 23 15:02:05 2017 +0200
Branches: master
https://developer.blender.org/rBA88918dcef321754ebb0a1859e88b2d538f7c87d4
Autotrack: Cleanup, add some report messages
Bumped version to 0.1.1
Pep8 cleanup
Imports as tuples, remove unused ones
Simplify the UI code
Change the Cancel tip to Stop as it has different
meaning for Operators (as the results are kept)
Use a debug_print instead of regular print
enabled / disabled by a DEBUG global as from the code
it seems that is for debugging purposes
Add some operator report messages to be more clear
what happens
===================================================================
M space_clip_editor_autotracker.py
===================================================================
diff --git a/space_clip_editor_autotracker.py b/space_clip_editor_autotracker.py
index 9dea7e54..1cd20886 100644
--- a/space_clip_editor_autotracker.py
+++ b/space_clip_editor_autotracker.py
@@ -19,7 +19,7 @@
bl_info = {
"name": "Autotrack",
"author": "Miika Puustinen, Matti Kaihola, Stephen Leger",
- "version": (0, 1, 0),
+ "version": (0, 1, 1),
"blender": (2, 78, 0),
"location": "Movie clip Editor > Tools Panel > Autotrack",
"description": "Motion Tracking with automatic feature detection.",
@@ -31,35 +31,58 @@ bl_info = {
import bpy
import bgl
import blf
-import math
-from mathutils import Vector
-from bpy.types import Operator, Panel, PropertyGroup, WindowManager
-from bpy.props import BoolProperty, FloatProperty, IntProperty, EnumProperty, PointerProperty
+from bpy.types import (
+ Operator,
+ Panel,
+ PropertyGroup,
+ WindowManager,
+ )
+from bpy.props import (
+ BoolProperty,
+ FloatProperty,
+ IntProperty,
+ EnumProperty,
+ PointerProperty,
+ )
-# for debug purpose
+# for debug purposes
import time
+# set to True to enable debug prints
+DEBUG = False
+
+
+# pass variables just like for the regular prints
+def debug_print(*args, **kwargs):
+ global DEBUG
+ if DEBUG:
+ print(*args, **kwargs)
+
+
# http://blenderscripting.blogspot.ch/2011/07/bgl-drawing-with-opengl-onto-blender-25.html
class GlDrawOnScreen():
black = (0.0, 0.0, 0.0, 0.7)
white = (1.0, 1.0, 1.0, 0.5)
progress_colour = (0.2, 0.7, 0.2, 0.5)
+
def String(self, text, x, y, size, colour):
''' my_string : the text we want to print
pos_x, pos_y : coordinates in integer values
size : font height.
colour : used for definining the colour'''
- dpi, font_id = 72, 0 # dirty fast assignment
+ dpi, font_id = 72, 0 # dirty fast assignment
bgl.glColor4f(*colour)
blf.position(font_id, x, y, 0)
blf.size(font_id, size, dpi)
blf.draw(font_id, text)
+
def _end(self):
bgl.glEnd()
bgl.glPopAttrib()
bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
+
def _start_line(self, colour, width=2, style=bgl.GL_LINE_STIPPLE):
bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
bgl.glLineStipple(1, 0x9999)
@@ -68,123 +91,127 @@ class GlDrawOnScreen():
bgl.glColor4f(*colour)
bgl.glLineWidth(width)
bgl.glBegin(bgl.GL_LINE_STRIP)
+
def Rectangle(self, x0, y0, x1, y1, colour, width=2, style=bgl.GL_LINE):
- self._start_line(colour, width, style)
+ self._start_line(colour, width, style)
bgl.glVertex2i(x0, y0)
bgl.glVertex2i(x1, y0)
bgl.glVertex2i(x1, y1)
bgl.glVertex2i(x0, y1)
bgl.glVertex2i(x0, y0)
self._end()
+
def Polygon(self, pts, colour):
bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
bgl.glEnable(bgl.GL_BLEND)
- bgl.glColor4f(*colour)
+ bgl.glColor4f(*colour)
bgl.glBegin(bgl.GL_POLYGON)
for pt in pts:
x, y = pt
- bgl.glVertex2f(x, y)
+ bgl.glVertex2f(x, y)
self._end()
+
def ProgressBar(self, x, y, width, height, start, percent):
- x1, y1 = x+width, y+height
+ x1, y1 = x + width, y + height
# progress from current point to either start or end
- xs = x+(x1-x) * float(start)
+ xs = x + (x1 - x) * float(start)
if percent > 0:
# going forward
- xi = xs+(x1-xs) * float(percent)
+ xi = xs + (x1 - xs) * float(percent)
else:
# going backward
- xi = xs-(x-xs) * float(percent)
+ xi = xs - (x - xs) * float(percent)
self.Polygon([(xs, y), (xs, y1), (xi, y1), (xi, y)], self.progress_colour)
self.Rectangle(x, y, x1, y1, self.white, width=1)
-
+
+
def draw_callback(self, context):
- #print("draw_callback : %s" % (self.progress))
self.gl.ProgressBar(10, 24, 200, 16, self.start, self.progress)
- self.gl.String(str(int(100*abs(self.progress)))+"% ESC to Cancel", 14, 28, 10, self.gl.white)
-
+ self.gl.String(str(int(100 * abs(self.progress))) + "% ESC to Stop", 14, 28, 10, self.gl.white)
+
+
class OP_Tracking_auto_tracker(Operator):
- """Autotrack. Esc to cancel."""
bl_idname = "tracking.auto_track"
bl_label = "AutoTracking"
+ bl_description = ("Start Autotracking, Press Esc to Stop \n"
+ "When stopped, the added Track Markers will be kept")
_timer = None
_draw_handler = None
-
+
gl = GlDrawOnScreen()
progress = 0
limits = 0
t = 0
-
+
def find_track_start(self, track):
for m in track.markers:
if not m.mute:
return m.frame
return track.markers[0].frame
-
+
def find_track_end(self, track):
for m in reversed(track.markers):
if not m.mute:
return m.frame
- return track.markers[-1].frame-1
-
+ return track.markers[-1].frame - 1
+
def find_track_length(self, track):
tstart = self.find_track_start(track)
- tend = self.find_track_end(track)
- return tend-tstart
-
+ tend = self.find_track_end(track)
+ return tend - tstart
+
def show_tracks(self, context):
- scene = context.scene
- clip = context.area.spaces.active.clip
+ clip = context.area.spaces.active.clip
tracks = clip.tracking.tracks
for track in tracks:
track.hide = False
-
- def get_vars_from_context(self, context):
+
+ def get_vars_from_context(self, context):
scene = context.scene
props = context.window_manager.autotracker_props
- clip = context.area.spaces.active.clip
+ clip = context.area.spaces.active.clip
tracks = clip.tracking.tracks
current_frame = scene.frame_current
- clip_end = clip.frame_start+clip.frame_duration
+ clip_end = clip.frame_start + clip.frame_duration
clip_start = clip.frame_start
if props.track_backwards:
- last_frame = min(clip_end, current_frame+props.frame_separation)
+ last_frame = min(clip_end, current_frame + props.frame_separation)
else:
- last_frame = max(clip_start, current_frame-props.frame_separation)
+ last_frame = max(clip_start, current_frame - props.frame_separation)
return scene, props, clip, tracks, current_frame, last_frame
-
+
def delete_tracks(self, to_delete):
bpy.ops.clip.select_all(action='DESELECT')
for track in to_delete:
track.select = True
bpy.ops.clip.delete_track()
-
+
# DETECT FEATURES
def auto_features(self, context):
"""
- Detect features
+ Detect features
"""
t = time.time()
-
+
scene, props, clip, tracks, current_frame, last_frame = self.get_vars_from_context(context)
-
+
selected = []
old = []
to_delete = []
width = clip.size[0]
- delete_threshold = float(props.delete_threshold)/100.0
-
+ delete_threshold = float(props.delete_threshold) / 100.0
+
bpy.ops.clip.select_all(action='DESELECT')
-
+
# Detect Features
bpy.ops.clip.detect_features(
- threshold=props.df_threshold,
- min_distance=props.df_distance/100.0*width,
- margin=props.df_margin/100.0*width,
- placement=props.placement_list
- )
-
+ threshold=props.df_threshold,
+ min_distance=props.df_distance / 100.0 * width,
+ margin=props.df_margin / 100.0 * width,
+ placement=props.placement_list
+ )
+
# filter new and old tracks
for track in tracks:
if track.hide or track.lock:
@@ -195,41 +222,40 @@ class OP_Tracking_auto_tracker(Operator):
old.append(track)
if track.select:
selected.append(track)
-
+
added_tracks = len(selected)
-
+
# Select overlapping new markers
for track_new in selected:
marker0 = track_new.markers.find_frame(current_frame)
for track_old in old:
marker1 = track_old.markers.find_frame(current_frame)
- distance = (marker1.co-marker0.co).length
+ distance = (marker1.co - marker0.co).length
if distance < delete_threshold:
to_delete.append(track_new)
added_tracks -= 1
break
-
+
# Delete Overlapping Markers
self.delete_tracks(to_delete)
- print("auto_features %.4f seconds add:%s tracks." % (time.time()-t, added_tracks))
-
+ debug_print("auto_features %.4f seconds, add: %s tracks" % (time.time() - t, added_tracks))
+
# AUTOTRACK FRAMES
def track_frames_backward(self):
# INVOKE_DEFAULT to show progress and take account of frame_limit
t = time.time()
res = bpy.ops.clip.track_markers('INVOKE_DEFAULT', backwards=True, sequence=True)
- print("track_frames_backward %.2f seconds %s" % (time.time()-t, res))
-
+ debug_print("track_frames_backward %.2f seconds %s" % (time.time() - t, res))
+
def track_frames_forward(self):
# INVOKE_DEFAULT to show progress and take account of frame_limit
t = time.time()
res = bpy.ops.clip.track_markers('INVOKE_DEFAULT', backwards=False, sequence=True)
- print("track_frames_forward %.2f seconds %s" % (time.time()-t, res))
-
+ debug_print("track_frames_forward %.2f seconds %s" % (time.time() - t, res))
+
def get_active_tracks(self, context):
scene, props, clip, tracks, current_frame, last_frame = self.get_vars_from_context(context)
- # Select active
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list