Skip to content

Commit 25b4ec0

Browse files
Make the image aspect ratio easier for users to set.
Allow users to change the film back aspect with the image width/height. The pixel aspect ratio also allows users of HDV or Anamorphic footage to input a correct aspect ratio for the input image. The calibration maths is very sensitive to the image aspect ratio and will likely fail if it's wrong - even with good line data. Issue #121. Change-Id: I177ceb2abe2773d40248702523a0e550c07265c1
1 parent e6a0be7 commit 25b4ec0

1 file changed

Lines changed: 45 additions & 16 deletions

File tree

  • python/mmSolver/tools/calibratecamera

python/mmSolver/tools/calibratecamera/lib.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ def create_new_setup():
184184
# Create image plane.
185185
img_pl_tfm, img_pl_shp = maya.cmds.imagePlane(camera=cam_shp)
186186

187-
# Using a horizontal fit mode ensures the camera calibration's
188-
# film back is consistent, even if the image plane aspect ratio
189-
# changes.
190-
maya.cmds.setAttr('{}.fit'.format(img_pl_shp), 2) # 2 = Horizontal
187+
# Using a "To Size" fit mode will forcibly change the image to
188+
# stretch it to match the size given. Therefore it is important
189+
# the image plane size (including the aspect ratio) is correct.
190+
maya.cmds.setAttr('{}.fit'.format(img_pl_shp), 4) # 4 = To Size
191191

192192
# Image plane is almost at far-clipping plane distance.
193193
maya.cmds.setAttr('{}.depth'.format(img_pl_shp), 9990)
@@ -240,7 +240,38 @@ def create_new_setup():
240240
decompose_node = maya.cmds.createNode('decomposeMatrix')
241241
maya.cmds.setAttr(
242242
'{}.inputRotateOrder'.format(decompose_node),
243-
2) # 2 = ZXY
243+
2) # 2 = ZXY (good default for cameras aimed at the horizon.)
244+
245+
maya.cmds.addAttr(
246+
calib_node,
247+
attributeType='float',
248+
minValue=0.0,
249+
defaultValue=1920.0,
250+
longName='imageWidth')
251+
maya.cmds.addAttr(
252+
calib_node,
253+
attributeType='float',
254+
minValue=0.0,
255+
defaultValue=1080.0,
256+
longName='imageHeight')
257+
maya.cmds.addAttr(
258+
calib_node,
259+
attributeType='float',
260+
minValue=0.0,
261+
defaultValue=1.0,
262+
longName='imagePixelAspectRatio')
263+
maya.cmds.addAttr(
264+
calib_node,
265+
attributeType='float',
266+
minValue=0.0,
267+
defaultValue=1.0,
268+
longName='imageAspectRatio')
269+
270+
exp = (
271+
'imageAspectRatio = (imageWidth * imagePixelAspectRatio) / imageHeight;'
272+
'verticalFilmAperture = horizontalFilmAperture / imageAspectRatio;'
273+
)
274+
maya.cmds.expression(object=calib_node, string=exp)
244275

245276
maya.cmds.addAttr(
246277
calib_node,
@@ -298,21 +329,19 @@ def create_new_setup():
298329
['{}.message'.format(horizon_line_mkr2_node),
299330
'{}.horizonPointNodeB'.format(calib_node)],
300331

332+
['{}.coverageX'.format(img_pl_shp),
333+
'{}.imageWidth'.format(calib_node)],
334+
['{}.coverageY'.format(img_pl_shp),
335+
'{}.imageHeight'.format(calib_node)],
336+
337+
['{}.horizontalFilmAperture'.format(cam_shp),
338+
'{}.sizeX'.format(img_pl_shp)],
339+
['{}.verticalFilmAperture'.format(cam_shp),
340+
'{}.sizeY'.format(img_pl_shp)],
301341
]
302342
for src, dst in src_dst_attr_list:
303343
if maya.cmds.isConnected(src, dst) is False:
304344
maya.cmds.connectAttr(src, dst)
305-
306-
# TODO: Automatically scale the calibration film back height using
307-
# the input image plane width. Maybe we can do this with an
308-
# expression at first?
309-
310-
# We could use OpenMaya.MImage.readFromFile(), and then
311-
# OpenMaya.MImage.getSize() to get the image size, then save the
312-
# attributes on the mmCameraCalibrate node. Ensure a 'pixel
313-
# aspect' attribute is also added, and used in the expression. It
314-
# is not possible to detect a pixel aspect ratio for an image
315-
# using the Maya API.
316345
return
317346

318347

0 commit comments

Comments
 (0)