1
$\begingroup$

I'm trying to export mask spline points x and y data by using:

bpy.data.masks['Mask'].layers['0'].splines[0].points[0].co

but i get an x, y vector with an unknown coordinates like:

(0.40345168113708496, 0.4609205424785614)

i think they are a percentage of the image i made the mask on, i need to convert it to pixel format where it should show something like:

(402,503)

i tried to do some math, and multiplied it with image the resolution, but the resulting numbers are wrong! i do not get the formula behind this vector after searching many posts, can some please point me to it or how to convert it to image space?

$\endgroup$

1 Answer 1

2
$\begingroup$

Strangely enough, Blender calculates the relativ dimensions with respect to the larger dimension.
These words are not very well choosen. Here is a graphic that show a large orange square. Blender gives us relativ coordinates in this reference frame. The green rectangle is our movie aspect ratio.

graphic

import bpy

render = bpy.context.scene.render

coordinate = bpy.data.masks[0].layers[0].splines[0].points[0].co.copy()
coordinate.x *= render.resolution_x
coordinate.y = coordinate.y * render.resolution_x - (render.resolution_x - render.resolution_y) / 2

# at 100%, this gives us the correct coordinate
print(coordinate)
$\endgroup$
3
  • $\begingroup$ thanks this is the math i was looking for, it worked but it is flipped on the y axis! $\endgroup$
    – bat3a
    Jan 2, 2019 at 8:34
  • $\begingroup$ please see this illustration this imgur.com/a/5QHucjD $\endgroup$
    – bat3a
    Jan 2, 2019 at 8:40
  • $\begingroup$ okay i fixed it by using co_y = res_y - co_y $\endgroup$
    – bat3a
    Jan 2, 2019 at 9:09

You must log in to answer this question.

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