# 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 – Jack Feet 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 – Jack Feet 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. – brockmann 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.

Step Tracker allows you to batch-track multiple "steps" of n frames without degrading performance on very long shots. Please read the Readme for instructions.

• Your script is great thanks. I just get an error in line 55 in operatorsList.py that MovieTrackingSettins object has no attribute refine_intrinsics_focal_length. And would it be possible to just let it track, it tries to solve after every step and that annoys me a bit – Phönix 64 Feb 14 at 14:21
• I should give the option for sure. I make it solve step by step because it also uses the clean operator which removes bad trackers based on the solved camera. This way bad trackers get removed on the fly rather than when you're finished and have to process too many trackers at once. I may not find the time to work on this before a few weeks though – ChameleonScales Feb 14 at 15:34