I’m new to Mocha and enjoying the experience!
I’d like to parse a .mocha text file exported from Mocha for AE so I can visualise the tracking data in a standalone Python script. (Currently I’m simply using OpenCV’s drawing functions).
I’ve written a script that extracts each Layer’s surface corners:
Surface0X Surface0Y Surface0B Surface1X Surface1Y Surface1B Surface2X Surface2Y Surface2B Surface3X Surface3Y Surface3B
With a few manual tweaks my conversion function from mocha to absolute pixels (Python/OpenCV) looks like this:
- flip coorinates vertically (
frame_h - y1)
- offset vertically by half the bounding box height (
+ bbox_height // 2)
- additionally, when visualising tracking data, I add the
Translation_Yvalues to each surface corner
def convert_mocha_coords(corner1, corner2, frame_h): x1, y1 = corner1 x2, y2 = corner2 bbox_height = y2 - y1 y1 = frame_h - y1 + bbox_height // 2 y2 = frame_h - y2 + bbox_height // 2 return ((x1, y1), (x2, y2)) def offset_corners_int(corner1, corner2, tx, ty): x1, y1 = corner1 x2, y2 = corner2 x1 = int(x1 + tx) y1 = int(y1 + ty) x2 = int(x2 + tx) y2 = int(y2 + ty) return ((x1, y1), (x2, y2))
While it feels I’m close, I’m stabbing in the dark without documentation and I’m only applying data from the translation tracks (but not from rotation, scale, shear, etc.). Additionally I’m multiplying the translation values by 50 (via random trials). This is all guess work at the moment.
This is what tracking looks like in Mocha for AE:
and this is what visualising one layer currently looks like:
Notice the y position starts to drift downwards.
I’ve tried to find documentation online regarding the .mocha format, Layer and Track in particular (including the Mocha Pro Python Guide), but I couldn’t find enough information.
How can I parse a .mocha file and convert surface and track data to pixel coordinates for visualisation ?
- in what coordinate system are the surface coordinates ?
- in which orders should the track transformations be applied ? (e.g. translate first, then rotate, then scale (then shear, then apply perspective (if any) ?)
- do track transformations use different coordinate systems ? (How should transformations be applied to surface coordinates to calculate the absolute pixel coordinates ?)
Thank you so much,