Need help on Exporting 2D marker from blender to syntheyes

Hi, all
I’m recently try blender camera tracker and found it working great with 2D tracking with it new affine, perspective track.
I’m very please with it easy to use, accurate track quality.

Now I’m thinking about buying Syntheyes to solve for my 3D track camera, for many reasons(ex: stereo track, rolling shutter, after effect export, Nuke pipeline)

I thinking about having blender export its 2D markers to syntheyes by scripting

from my seach over the internet I came across some script that doing exporting 1 marker to 1 .csv file, but not syntheyes import friendly(txt).

import bpy
D = bpy.data


for clip in D.movieclips:
    for track in clip.tracking.tracks:
        fn = 'data/tr_{0}_{1}.csv'.format(clip.name.split('.')[0], track.name)
        with open(fn, 'w') as f:
            frameno = 0
            while True:
                markerAtFrame = track.markers.find_frame(frameno)
                if not markerAtFrame:
                    break
                frameno += 1
                coords = markerAtFrame.co.xy
                f.write('{0} {1}
'.format(coords[0], coords[1]))
from __future__ import print_functionimport bpy
D = bpy.data


printFrameNums = False # include frame numbers in the csv file
relativeCoords = False # marker coords will be relative to the dimensions of the clip


f2=open('export-markers.log', 'w')
print('First line test', file=f2)
for clip in D.movieclips:
    print('clip {0} found
'.format(clip.name), file=f2)
    width=clip.size[0]
    height=clip.size[1]
    for ob in clip.tracking.objects:
        print('object {0} found
'.format(ob.name), file=f2)
        for track in ob.tracks:
            print('track {0} found
'.format(track.name), file=f2)
            fn = 'data/{0}_{1}_tr_{2}.csv'.format(clip.name.split('.')[0], ob.name, track.name)
            with open(fn, 'w') as f:
                framenum = 0
                while framenum < clip.frame_duration:
                    markerAtFrame = track.markers.find_frame(framenum)
                    if markerAtFrame:
                        coords = markerAtFrame.co.xy
                        if relativeCoords:
                            if printFrameNums:
                                print('{0},{1},{2}'.format(framenum, coords[0], coords[1]), file=f)
                            else:
                                print('{0},{1}'.format(coords[0], coords[1]), file=f)
                        else:
                            if printFrameNums:
                                print('{0},{1},{2}'.format(framenum, coords[0]*width, coords[1]*height), file=f)
                            else:
                                print('{0},{1}'.format(coords[0]*width, coords[1]*height), file=f)


                    framenum += 1
f2.close()
# 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)

Now that I get to run in blender, export to csv files I run into a few problems.
first, How syntheyes import 2D markers
this is a format syntheyes read:
[tracker name] [frameNo.] [Y] [(15 or 7) syntheyes indicator of what kind of tracker it is, I think 15 is keyframe, 7 is autotrack]

Tracker1 0 -0.063593 -0.980128 15
Tracker1 1 -0.062930 -0.980384 15
Tracker1 2 -0.061996 -0.980213 15
Tracker1 3 -0.061261 -0.980586 15
Tracker1 4 -0.060288 -0.980562 15
Tracker1 5 -0.059261 -0.980830 15
Tracker2 0 0.942089 -0.964297 15
Tracker2 1 0.942862 -0.965292 15
Tracker2 2 0.943611 -0.965809 15
Tracker2 3 0.945039 -0.965019 15
Tracker2 4 0.945803 -0.965856 15
Tracker2 5 0.947087 -0.965811 15

syntheyes use coordinate X,Y as -1,1. center of the image is 0,0 which is not the same as blender coordinate X, Y 0-1 which I think 0,0 is lower left of the image

so I edit the script to fix that by edit this line

f.write('{0} {1} {2} {3} 15
'.format(track.name, frameno, (coords[0]*2) -1, (coords[1]*2 -1)*(-1)))
import bpy
D = bpy.data




for clip in D.movieclips:
    for track in clip.tracking.tracks:
        fn = 'C:/Users/user/Documents/Tracking/blender/tr_{0}_{1}.csv'.format(clip.name.split('.')[0], track.name)
        with open(fn, 'w') as f:
            frameno = 0
            while True:
                markerAtFrame = track.markers.find_frame(frameno)
                if not markerAtFrame:
                    break
                frameno += 1
                coords = markerAtFrame.co.xy
                f.write('{0} {1} {2} {3} 15
'.format(track.name, frameno, (coords[0]*2) -1, (coords[1]*2 -1)*(-1)))

now that the first problem is solve, come to the second problem

I have trouble get markers from blender, by that I mean markers have duplicate position on 2-3 frame(some at begining of the frame, some at the end of frame) which I don’t understand why and also from the script export csv the frame numbers is not match. my image sequence is 188 frame but some how it write out the csv file with extra fews frames.

track using this plate “UHAUL WALK”
http://www.hollywoodcamerawork.us/trackingplates.html
I attach blend file to you all here (use above image sequence) tracked 10 markers to test the export script to see what I mean
MM_UHaul Walk.blend (610 KB)

also from the script come another problem
Track.009 track from 0-59 then disable and then re-enable to continue track at frame 84-188
the script fail to reflect that in the export file. it just stop write at frame 59

now Im very limited at python scripting or any programing if at all.
I kinda stuck here
So Im here to ask any of you that can write code to help me, and the community on this.
I think if we can do this, we can submit the exporter to include in blender as add-on for anyone that might need this function.

Thank you

Don’t seem to get any help on the topic. Does anyone know where else I could ask for help?
Thank