[Bf-extensions-cvs] [9950f0a0] master: auto tracker correct version

meta-androcto noreply at git.blender.org
Tue Jun 6 12:07:50 CEST 2017


Commit: 9950f0a0c210c235d2b33808b768191d57df1ca5
Author: meta-androcto
Date:   Tue Jun 6 20:07:33 2017 +1000
Branches: master
https://developer.blender.org/rBA9950f0a0c210c235d2b33808b768191d57df1ca5

auto tracker correct version

===================================================================

M	space_clip_editor_autotracker.py

===================================================================

diff --git a/space_clip_editor_autotracker.py b/space_clip_editor_autotracker.py
index 1b9df0cf..cd00f2e7 100644
--- a/space_clip_editor_autotracker.py
+++ b/space_clip_editor_autotracker.py
@@ -2,7 +2,7 @@
 #
 #  This program is free software; you can redistribute it and/or
 #  modify it under the terms of the GNU General Public License
-#  as published by the Free Software Foundation; either version 3
+#  as published by the Free Software Foundation; either version 2
 #  of the License, or (at your option) any later version.
 #
 #  This program is distributed in the hope that it will be useful,
@@ -11,304 +11,544 @@
 #  GNU General Public License for more details.
 #
 #  You should have received a copy of the GNU General Public License
-#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 # ##### END GPL LICENSE BLOCK #####
 
 bl_info = {
     "name": "Autotrack",
-    "author": "Miika Puustinen, Matti Kaihola",
-    "version": (0, 0, 95),
+    "author": "Miika Puustinen, Matti Kaihola, Stephen Leger",
+    "version": (0, 0, 99),
     "blender": (2, 78, 0),
     "location": "Movie clip Editor > Tools Panel > Autotrack",
     "description": "Motion Tracking with automatic feature detection.",
     "warning": "",
-    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Motion_Tracking/Auto_Track",
+    "wiki_url": "https://github.com/miikapuustinen/blender_autotracker",
     "category": "Motion Tracking",
     }
 
-
 import bpy
+import bgl
+import blf
 import math
-
-
-class AutotrackerOperator(bpy.types.Operator):
+from mathutils import Vector
+from bpy.types import Operator, Panel, PropertyGroup, WindowManager
+from bpy.props import BoolProperty, FloatProperty, IntProperty, EnumProperty, PointerProperty
+
+# for debug purpose
+import time
+
+# 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
+        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)
+        bgl.glEnable(style)
+        bgl.glEnable(bgl.GL_BLEND)
+        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) 
+        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.glBegin(bgl.GL_POLYGON)
+        for pt in pts:
+            x, y = pt
+            bgl.glVertex2f(x, y)  
+        self._end()
+    def ProgressBar(self, x, y, width, height, start, percent):
+        x1, y1 = x+width, y+height
+        # progress from current point to either start or end
+        xs = x+(x1-x) * float(start)
+        if percent > 0:
+            # going forward
+            xi = xs+(x1-xs) * float(percent)
+        else:
+            # going backward
+            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)
+    
+class OP_Tracking_auto_tracker(Operator):
     """Autotrack. Esc to cancel."""
-    bl_idname = "wm.modal_timer_operator"
-    bl_label = "Modal Timer Operator"
+    bl_idname = "tracking.auto_track"
+    bl_label = "AutoTracking"
 
-    limits = bpy.props.IntProperty(default=0)
     _timer = None
-
-    def active_clip(self):
-        area = [i for i in bpy.context.screen.areas if i.type == 'CLIP_EDITOR'][0]
-        clip = area.spaces.active.clip.name
-        return clip
-
+    _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
+        
+    def find_track_length(self, track):
+        tstart = self.find_track_start(track)
+        tend   = self.find_track_end(track)
+        return tend-tstart
+    
+    def show_tracks(self, context):
+        scene = context.scene
+        clip  = context.area.spaces.active.clip
+        tracks = clip.tracking.tracks
+        for track in tracks:
+            track.hide = False
+        
+    def get_vars_from_context(self, context):    
+        scene = context.scene
+        props = context.window_manager.autotracker_props
+        clip  = context.area.spaces.active.clip
+        tracks = clip.tracking.tracks
+        current_frame = scene.frame_current
+        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)
+        else:
+            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, delete_threshold, limits):
-        tracks = []
+    def auto_features(self, context):
+        """
+            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
+        
         bpy.ops.clip.select_all(action='DESELECT')
-
+        
         # Detect Features
         bpy.ops.clip.detect_features(
-            threshold=bpy.context.scene.autotracker_props.df_threshold,
-            min_distance=bpy.context.scene.autotracker_props.df_distance,
-            margin=bpy.context.scene.autotracker_props.df_margin,
-            placement=bpy.context.scene.autotracker_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
             )
-
-        current_frame = bpy.context.scene.frame_current
-
-        tracks = bpy.data.movieclips[self.active_clip()].tracking.tracks
+            
+        # filter new and old tracks
         for track in tracks:
-            if track.markers.find_frame(current_frame) is not None:
-                if track.select is not True and track.hide is False and track.markers.find_frame(current_frame).mute is False:
+            if track.hide or track.lock:
+                continue
+            marker = track.markers.find_frame(current_frame)
+            if marker is not None:
+                if (not track.select) and (not marker.mute):
                     old.append(track)
-                if track.select is True:
+                if track.select:
                     selected.append(track)
-
+        
+        added_tracks = len(selected)
+        
         # Select overlapping new markers
-        for i in selected:
-            for j in old:
-                i_marker = i.markers.find_frame(current_frame)
-                j_marker = j.markers.find_frame(current_frame)
-                distance = math.sqrt(((i_marker.co[0] - j_marker.co[0])**2) + ((i_marker.co[1] - j_marker.co[1])**2))
-
+        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
                 if distance < delete_threshold:
-                    to_delete.append(i)
+                    to_delete.append(track_new)
+                    added_tracks -= 1
                     break
-
-        # delete short tracks
-        for track in tracks:
-            muted = []
-            active = []
-            # print(track)
-            for marker in track.markers:
-                if marker.mute is True:
-                    muted.append(marker)
-                else:
-                    active.append(marker)
-            if len(muted) > 3 and len(active) < 1:
-                to_delete.append(track)
-
-            if len(track.markers) > 1 and len(active) == 0:
-                to_delete.append(track)
-
+        
         # Delete Overlapping Markers
-        bpy.ops.clip.select_all(action='DESELECT')
-        for track in

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list