6
$\begingroup$

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)
$\endgroup$
13
  • $\begingroup$ I have started over and tried to layout exactly what I am trying to accomplish. Thanks for any help. @brockmann $\endgroup$
    – Jack Feet
    Jun 12 '20 at 8:21
  • $\begingroup$ 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 $\endgroup$
    – Jack Feet
    Jun 12 '20 at 8:26
  • 1
    $\begingroup$ So the idea is to have blender create unique trackers from detected features for every frame? $\endgroup$
    – susu
    Jun 13 '20 at 7:56
  • 3
    $\begingroup$ 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 $\endgroup$
    – susu
    Jun 13 '20 at 15:16
  • 1
    $\begingroup$ 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. $\endgroup$
    – brockmann
    Jun 20 '20 at 13:40
1
$\begingroup$

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
bpy.context.scene.frame_set(frameNumber)
bpy.ops.clip.change_frame (ctx, frame = 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.

Or use this add-on I just made:

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.

$\endgroup$
2
  • $\begingroup$ 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 $\endgroup$
    – Phönix 64
    Feb 14 at 14:21
  • $\begingroup$ 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 $\endgroup$ Feb 14 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.