4
$\begingroup$

I'm new to Blender and the Python language and I'm trying to extract the coordinates of the corners of a plane track from all the frames of a clip. I'm having trouble even accessing(?) the plane track object/variable. I hover over the text field containing the name of the plane track and it says

...
bpy.data.movieclips["1340wbdc0000.jpeg"].tracking.plane_tracks["pt"].name

I type that line into the console, but then I get the error

Traceback (most recent call last):
 File "<blender_console>", line 1, in <module>
KeyError: 'bpy_prop_collection[key]: key "pt" not found'

However, if I enter

D.movieclips["1340wbdc0000.jpeg"].tracking.plane_tracks.active

The console "responds" with

bpy.data.movieclips['1340wbdc0000.jpeg'].tracking.plane_tracks["pt"]

This is really making me very confused and frustrated. What am I doing wrong? Could this be a bug since plane tracking is a new feature?

$\endgroup$

1 Answer 1

4
$\begingroup$

Works for me in 2.69:

>>> bpy.data.movieclips[0].tracking.plane_tracks.active.markers[0].corners[0][:]
#(0.12633077800273895, 0.4383348524570465)

plane_tracks.active gives me the correct name, even if I rename it in the right sidebar of the movieclip editor. You could try plane_tracks["Plane Track"] or plane_tracks[0] instead.

Do should deselect all in the movieclip editor and re-select the tracking plane and see if plane_track.active changes to the correct name.

clip = bpy.data.movieclips["1100wbdc0000.jpeg"]
print("\nMovie Clip %s" % clip.name)

for i, ob in enumerate(clip.tracking.objects):
    print("\n\tTracking Object %s" % ob.name)

    for j, pt in enumerate(ob.plane_tracks):
        print("\t\tPlane Track %i" % j)

        for k, marker in enumerate(pt.markers):
            print("\t\t\tMarker %i" % k)

            for l, corner in enumerate(marker.corners):
                print("\t\t\t\tCorner %i = %f / %f" % (l, corner[0], corner[1]))
$\endgroup$
9
  • $\begingroup$ Yes, plane_tracks.active does give me the correct name. However if no plane track is selected, using plane_tracks["Plane Track"] or plane_tracks[0] gives me an error. I was hoping to write a script to automate the process since I have around 60 plane tracks to extract. $\endgroup$
    – user1726
    Dec 2, 2013 at 23:47
  • $\begingroup$ Of course it gives an error if there's no active plane track. If you need to access all plane tracks, why not loop over all of them? There's no need to make them / one active. for pt in Clip.tracking.plane_tracks: pt.markers... $\endgroup$
    – CodeManX
    Dec 3, 2013 at 20:18
  • $\begingroup$ That's my problem. I can't loop over all of them. I tried the following code: import bpy i=0 clip=bpy.data.movieclips["1100wbdc0000.jpeg"] print(clip.tracking.plane_tracks.active.name) for track in clip.tracking.plane_tracks: ` print(i)` ` i=i+1` $\endgroup$
    – user1726
    Dec 4, 2013 at 10:53
  • $\begingroup$ If a plane track is selected, Plane Track 0 is printed on the console. However, if no plane track is selected, it returns AttributeError: 'NoneType' object has no attribute 'name' $\endgroup$
    – user1726
    Dec 4, 2013 at 11:01
  • $\begingroup$ There's no point in accessing plane_tracks.active if you wanna loop for all Plane Tracks, their markers and their Corners. See my answer above, added example code. $\endgroup$
    – CodeManX
    Dec 4, 2013 at 15:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .