# Script to auto-detect features to track using Python

I am attempting to make these GUI steps into a script. When I follow this process manually, I get a tracking error under 1 and I get some great matches. This is far better than autotrack.

import bpy


Step 1 - Set tracking settings extra correlation to .99:

bpy.data.movieclips["Name.png"].(null) = 0.99


Step 2 - Loop through 1000 times

When in loop, it loops but only tracks one frame forward:

for loopv in range (1000):


Step 3 - Detect Features

bpy.ops.clip.detect_features(ctx)


Step 4 - Track Features 1 Frame

bpy.ops.clip.track_markers(ctx,backwards=False, sequence=False)


Step 5 - Deselect all features

bpy.ops.clip.select_all(ctx,action='TOGGLE')


or

bpy.ops.object.select_all(ctx,action='DESELECT')


Step 6 - End Indentation of loop and Return to Step 2

This is my current code. I have to hit Run Script. over and over, for it to work and go through all the frames of the clip.

import bpy
import random

#for loopv in range (1000):
ctx = bpy.context.copy()
for area in bpy.context.screen.areas:
if area.type == 'CLIP_EDITOR':
ctx['area'] = area

bpy.ops.clip.select_all(ctx,action='DESELECT')
bpy.ops.clip.detect_features(ctx)
bpy.ops.clip.track_markers(ctx,backwards=False, sequence=False)

• I have started over and tried to layout exactly what I am trying to accomplish. Thanks for any help. @brockmann Jun 12 '20 at 8:21
• I have also tried this import bpy import random ctx = bpy.context.copy() for area in bpy.context.screen.areas: if area.type == 'CLIP_EDITOR': ctx['area'] = area bpy.ops.clip.select_all(ctx,action='DESELECT') for loopv in range (10): bpy.ops.clip.detect_features(ctx) bpy.ops.clip.track_markers(ctx,backwards=False, sequence=False) @batFinger Jun 12 '20 at 8:26
• So the idea is to have blender create unique trackers from detected features for every frame?
– susu
Jun 13 '20 at 7:56
• I'm not sure, I am of the opinion that a few well placed but accurate tracking points is all that is needed, instead of a whole bunch of them. But I know that other tracking and 3d reconstruction software does track every possible feature the same way you are trying to implement. I'm curious of the results. There is a long post on tips on motion traking on this site, you might want to check it out: blender.stackexchange.com/questions/42329 . There is also a wonderful script to work with weights in order to refine camera solving here: blender.stackexchange.com/a/71785/92768
– susu
Jun 13 '20 at 15:16
• Same issue, I guess the frame of the clip does not update. Test operator to execute in the clip editor: pastebin.com/sweqpsRJ Just switch to tracking workspace, load up any clip of your choice and eg. this one and run the script. Idea is to perform the script itself frame by frame, will add more markers each frame by calling detect_features() and track them per frame which apparently gives better results @batFINGER OP just wants to avoid clicking run script over and over again. Jun 20 '20 at 13:40

You have to update the frame with the right command:

⚠ Note that none of these will properly do it for the tracker operators:

bpy.context.scene.frame_current = frameNumber


The one you have to use is:

area.spaces[0].clip_user.frame_current = frameNumber


Then you can un-comment and set up your for loop.

The area here is just bpy.context.screen.areas[number] or bpy.context.area but area alone works in the OP's script.