An open API service indexing awesome lists of open source software.

https://github.com/walles/find_bad_motion_tracks

Finds bad tracks when doing motion tracking in Blender
https://github.com/walles/find_bad_motion_tracks

blender blender-addon motiontracking

Last synced: 11 months ago
JSON representation

Finds bad tracks when doing motion tracking in Blender

Awesome Lists containing this project

README

          

[![tox](https://github.com/walles/find_bad_motion_tracks/actions/workflows/main.yml/badge.svg)](https://github.com/walles/find_bad_motion_tracks/actions/workflows/main.yml)

# Find Bad Motion Tracks

This is a [Blender](https://blender.org)
[addon](https://docs.blender.org/manual/en/latest/editors/preferences/addons.html)
for finding bad [motion tracking
tracks](https://docs.blender.org/manual/en/latest/movie_clip/tracking/clip/editing/track.html).

The way it works is that it highlights tracks that move differently from the
others.

Basically, if all tracks move to the right, except one that moves to the left,
then the single track moving to the left is likely wrong and should be evaluated
by a human.

![Example usage](example.png 'Example usage')

## Installation Instructions

1. Go to the [latest release download page](https://github.com/walles/find_bad_motion_tracks/releases/latest)
1. Download the `find_bad_tracks-A_B_C.py` file
1. In Blender, open Preferences (under the Edit menu)
1. Click Add-ons
1. Click the Install... button
1. Find the file you just downloaded and click Install Add-on
1. Check the box next to Video Tools: Find Bad Tracks

## Usage Instructions

1. Follow the Installation Instructions `^` for how to install and enable this addon

1. Do some motion tracking, collect some tracks

1. In the Motion Tracking workspace, Movie Clip Editor on the middle left of
your screen, select the Track tab, expand Find Bad
Tracks
(you may have to scroll down to see this section) and press the
Find Bad Tracks button.

At about 400 tracks and 600 frames the computation takes 5s-10s on my
machine.

1. A list of Bad Tracks will now be displayed just below that button, with each
track's badness score next to it.

Clicking a track in the list will select that track in the clip editor and
take you to the worst frame. Stepping a few frames left or right will show
how the track skips / slides.

1. Another list of Duplicate Tracks comes below the Bad Tracks list. This list
contains track pairs that come close at some point of their lifetimes. The
most divergent track pairs are at the top of this list.

At the bottom of the list you will find tracks that overlap tightly without
diverging.

Clicking a track pair in this list will take you to a frame where the tracks
overlap. Stepping a few frames left or right will show you if the tracks
start diverging. If they do, (at least) one of the tracks are likely bad!

# Comparison to Built-in Functionality

Find Bad Tracks is similar to the built-in [Filter
Tracks](https://docs.blender.org/manual/en/latest/movie_clip/tracking/clip/editing/track.html#filter-tracks)
functionality ([source](https://github.com/blender/blender/blob/04c75c5ce7699a1502a7c2212d4aa57166465514/release/scripts/startup/bl_operators/clip.py#L141-L215)).

| | Find Bad Tracks | Filter Tracks |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| Finding the midpoint | :green_heart: Uses median, resilient to outliers | :broken_heart: Uses average, sensitive to outliers |
| Threshold | :green_heart: N/A, calculates a badness value based on the 80th percentile of track movements, works on both fast and slow moving frames | :broken_heart: 5 pixels, too sensitive on fast moving frames, too lenient on slow moving frames |
| Uses derivative | :green_heart: | :green_heart: |
| Uses 2nd derivative | :green_heart: | :broken_heart: No, which means the Filtering will miss tracks which suddenly move in a new direction |
| Tracks marker shape changes | :green_heart: | :broken_heart: |
| Presentation | :green_heart: List tracks ranked by badness, lets user filter | :broken_heart: Just selects all "bad" tracks, in my case that included lots of good tracks making the signal-to-noise ratio bad |
| Finds duplicate tracks | :green_heart: | :broken_heart: |

## Development

Use [`tox`](https://tox.wiki/en/latest/install.html) to verify your code before
committing / PRing:

```
tox
```

### Testing Locally in Blender

These are first-time instructions. For the second go, you can just regenerate
the plugin and install it from disk again in the Blender Preferences. This will
replace the currently installed version with the new one.

1. `./package-versioned-zip.sh 99.99.99`
1. Start Blender and pick "VFX" under "New File"
1. Install the addon from `find-bad-motion-tracks-99_99_99.zip`:
- Edit ->
- Preferences ->
- Extensions ->
- Click the unlabeled Extension Settings dropdown button on the right ->
- Install from Disk ->
1. Make some tracks to test with
1. In the Motion Tracking workspace (you should already be there), click the
Open button in the middle of the screen and load some video clip
1. Click the "Detect Features" button on the left
1. Under Track, click the "Track the selected markers forward for the entire
clip" button
1. Scroll down to the Find Bad Tracks section and click the "Find Bad Tracks"
button

### Development Environment

I have developed this with:

- [Visual Studio Code](https://code.visualstudio.com/) with its [Blender Development
extension](https://marketplace.visualstudio.com/items?itemName=JacquesLucke.blender-development)
- The [Fake Blender Python API module collection](https://github.com/nutti/fake-bpy-module) in a virtualenv
- Blender 2.93.1

### Icon

To edit the icon, first update [`icon.blend`](icon.blend). Then render the
updated icon into [`icon.png`](icon.png).

![Icon](icon.png)

## Making a New Release

1. Make sure the screenshot and description ^ are both up to date and in sync.
1. Run `release.sh` and follow instructions.

## TODO

- Fix the tracks list tooltips, the current ones make no sense: "Active Bad
Track / Double click to rename."
- Profile and see what can easily be sped up
- Publish on Blender Market

## Next Gen

The current badness algorithm works well when all tracks move in the same
direction (camera pans).

But doesn't work at all when the camera zooms or rotates.

What about this then?

1. Compute the (2D) transformation matrix between two frames
1. For each marker, check how far it is from its computed value given that
matrix

That should work for zooming and rotating camera motion as well. Also, we could
check the whole matrix and see if it makes sense, if the whole image just gets
narrower for example that's probably wrong.

Inspirational code here:

### DONE

- Document a release process
- Make an initial release
- Document install instructions higher up in this document
- Ignore locked tracks, assuming they have been manually vetted by a human
- Announce on BlenderNation
- Fix user reported issues
- Add duplicate tracks detection
- Remove worst-frame column from the bad-tracks list.
- Properly deselect unrelated tracks when switching between duplicate track
pairs in the UI
- Add a `tox.ini` with `mypy`, `pylint` and `black` code formatting. Black
formats locally and verifies in CI.
- Add a `tox` Github action for PRs and pushes