Skip to content

Instantly share code, notes, and snippets.

Created September 20, 2013 07:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save anonymous/31c915d611f0a84e5d33 to your computer and use it in GitHub Desktop.
Save anonymous/31c915d611f0a84e5d33 to your computer and use it in GitHub Desktop.
Small improvment of anonymous / gist:5663418 blender
# http://scummos.blogspot.cz/2012/11/blender-exporting-camera-tracking.html
# https://gist.github.com/anonymous/5663418
import bpy
import csv
D = bpy.data
frameNums = True # include frame numbers in the csv file
relativeCoords = False # marker coords will be relative to the dimensions of the clip
filepath = "/tmp/"
markers = {}
for clip in D.movieclips:
print('Clip {} found'.format(clip.name))
if relativeCoords:
width = 1
height = 1
else:
width = clip.size[0]
height = clip.size[1]
for ob in clip.tracking.objects:
print('Object {} found'.format(ob.name))
for track in ob.tracks:
fn = '{}_{}_tr_{}'.format(clip.name.split('.')[0], ob.name, track.name)
markers[fn] = []
print('track {} found'.format(track.name))
for framenum in range(clip.frame_duration):
markerAtFrame = track.markers.find_frame(framenum)
if markerAtFrame:
coords = list(markerAtFrame.co.xy)
coords = [coords[0] * width, coords[1] * height]
markers[fn].append(coords)
for key, value in markers.items():
print(key)
filename = "{}{}{}".format(filepath, key, ".csv")
open_data = open(filename, 'w', newline='')
with open_data as writer:
writer = csv.writer(writer, delimiter=';', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
if frameNums:
writer.writerow([key, "x", "y"])
for i, data in enumerate(value):
writer.writerow([i] + data)
else:
writer.writerow(["x", "y"])
for data in value:
writer.writerow(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment