示例#1
0
def _generate_camera_data(camera, lens, frame0):
    camera_data = {}
    cam_num_frames = tde4.getCameraNoFrames(camera)

    img_width = tde4.getCameraImageWidth(camera)
    img_height = tde4.getCameraImageHeight(camera)
    camera_data['resolution'] = (img_width, img_height)

    film_back_x = tde4.getLensFBackWidth(lens)
    film_back_y = tde4.getLensFBackHeight(lens)
    camera_data['film_back_cm'] = (film_back_x, film_back_y)

    lco_x = tde4.getLensLensCenterX(lens)
    lco_y = tde4.getLensLensCenterY(lens)
    camera_data['lens_center_offset_cm'] = (lco_x, lco_y)

    camera_data['per_frame'] = []
    for frame in range(1, cam_num_frames):
        # Note: In 3DEqualizer, film back and lens center is assumed
        # to be static, only focal length can be dynamic.
        focal_length = tde4.getCameraFocalLength(camera, frame)
        frame_data = {
            'frame': frame + frame0,
            'focal_length_cm': focal_length,
        }
        camera_data['per_frame'].append(frame_data)

    return camera_data
示例#2
0
def getOutSize(req, cameraIndex, cameraTmp):
    # get the actual image size from cameraTmp
    imageHeightInTmp = tde4.getCameraImageHeight(cameraTmp)
    imageWidthInTmp = tde4.getCameraImageWidth(cameraTmp)

    lensTmp = tde4.getCameraLens(cameraTmp)

    folcalParameter = getFocalParameters(lensTmp)

    # distorsionMode
    dyndistmode = tde4.getLensDynamicDistortionMode(lensTmp)

    log.debug('dyndistmode : ' + str(dyndistmode))

    if dyndistmode == "DISTORTION_STATIC":
        lensModelParameter = getLensModelParameter(camera=None,
                                                   lens=lensTmp,
                                                   frame=None)
        resOutTmp = get_bounding_box.calculateBoundigBox(
            imageWidthInTmp, imageHeightInTmp, "undistort", folcalParameter,
            lensModelParameter)
        imageWidthOuttmp = resOutTmp.width
        imageHeightOuttmp = resOutTmp.height
    else:
        imageHeightOuttmp = imageHeightInTmp
        imageWidthOuttmp = imageWidthInTmp
        for frame in range(1, tde4.getCameraNoFrames(cameraTmp) + 1):
            lensModelParameter = getLensModelParameter(camera=cameraTmp,
                                                       lens=lensTmp,
                                                       frame=frame)
            resOuttmp = get_bounding_box.calculateBoundigBox(
                imageWidthInTmp, imageHeightInTmp, "undistort",
                folcalParameter, lensModelParameter)
            if imageHeightOuttmp < resOuttmp.height:
                imageHeightOuttmp = resOuttmp.height
            if imageWidthOuttmp < resOuttmp.width:
                imageWidthOuttmp = resOuttmp.width

    if imageHeightInTmp > imageHeightOuttmp:
        imageHeightOuttmp = imageHeightInTmp
    if imageWidthInTmp > imageWidthOuttmp:
        imageWidthOuttmp = imageWidthInTmp

    log.debug('****************** lensModelParameter ********************')
    for key in lensModelParameter.keys():
        log.debug(key + ' : ' + str(lensModelParameter.get(key)))

    return imageHeightOuttmp, imageWidthOuttmp
示例#3
0
文件: tools.py 项目: Rotomator/noid
 def getInfoCam(self):
     cam = self.cam
     index = self.index
     self.offset = tde4.getCameraFrameOffset(cam)
     self.cameraPath = tde4.getCameraPath(cam).replace('\\', '/')
     self.camType = tde4.getCameraType(cam)
     self.noframes = tde4.getCameraNoFrames(cam)
     self.lens = tde4.getCameraLens(cam)
     self.rez_x = tde4.getCameraImageWidth(cam)
     self.rez_y = tde4.getCameraImageHeight(cam)
     self.model = tde4.getLensLDModel(self.lens)
     self.firstFrame = tde4.getCameraSequenceAttr(cam)[0]
     self.name = "%s_%s_1" % (validName(tde4.getCameraName(cam)), index)
     self.lastFrame = '%d' % (self.firstFrame + self.noframes - 1)
     self.firstFrame = '%d' % self.firstFrame
     self.focal_cm = tde4.getCameraFocalLength(cam, 1)
try:
    req = _export_requester_maya
except (ValueError, NameError, TypeError):
    _export_requester_maya = tde4.createCustomRequester()
    req = _export_requester_maya
    tde4.addFileWidget(req, "file_browser", "Exportfile...", "*.mel")
    tde4.addTextFieldWidget(req, "startframe_field", "Startframe", "1")
    # tde4.addOptionMenuWidget(req,"mode_menu","Orientation","Y-Up", "Z-Up")
    tde4.addToggleWidget(req, "hide_ref_frames", "Hide Reference Frames", 0)

cam = tde4.getCurrentCamera()
offset = tde4.getCameraFrameOffset(cam)
tde4.setWidgetValue(req, "startframe_field", str(offset))

FootageWidth = tde4.getCameraImageWidth(cam)
FootageHeight = tde4.getCameraImageHeight(cam)

lens = tde4.getFirstLens()
CameraApertureWidth = tde4.getLensFBackWidth(lens) / 2.54
CameraApertureHeight = tde4.getLensFBackHeight(lens) / 2.54

#about lens distortion.
LensDistortionValid = False
camList = tde4.getCameraList()
for cam in camList:
    lens = tde4.getCameraLens(cam)
    for id in tde4.getLensList():
        focus = tde4.getLensFocalLength(id)
        lensmodel = tde4.getLensLDModel(id)
        focallength = tde4.getLensFocalLength(id)
        paraNumber = tde4.getLDModelNoParameters(lensmodel)
示例#5
0
 def image_height(self):
     return tde4.getCameraImageHeight(self._cam_id)
def getDistortionBoundingBox(camera, lco_x, lco_y):
    # We genererate a number of samples around the image in normalized coordinates.
    # These samples are later unwarped, and the unwarped points
    # will be used to create a bounding box. In general, it is *not* sufficient to
    # undistort only the corners, because distortion might be moustache-shaped.
    # This is our list of samples:
    warped = []
    for i in range(10):
        warped.append([i / 10.0,0.0])
        warped.append([(i + 1) / 10.0,1.0])
        warped.append([0.0,i / 10.0])
        warped.append([1.0,(i + 1) / 10.0])

    # The lens center is by definition the fixed point of the distortion mapping.
    elc = [0.5 + lco_x,0.5 + lco_y]

    # Image size
    w_px = tde4.getCameraImageWidth(camera)
    h_px = tde4.getCameraImageHeight(camera)

    # The bounding boxes for non-symmetrized and symmetrized cased.
    bb_nonsymm = bbdld_bounding_box()
    bb_symm = bbdld_bounding_box()

    # Run through the frames of this camera
    n_frames = tde4.getCameraNoFrames(camera)
    for i_frame in range(n_frames):
        # 3DE4 counts from 1.
        frame = i_frame + 1

        # Now we undistort all edge points for the given
        # camera and frame and extend the bounding boxes.
        for p in warped:
            p_unwarped = tde4.removeDistortion2D(camera,frame,p)
            # Accumulate bounding boxes
            bb_nonsymm.extend(p_unwarped[0],p_unwarped[1])
            bb_symm.extend_symm(p_unwarped[0],p_unwarped[1],elc[0],elc[1])

    # Scale to pixel coordinates and extend to pixel-aligned values
    bb_nonsymm.scale(w_px,h_px)
    bb_nonsymm.extend_to_integer()

    # Image width and height for the non-symmetrized case
    w_nonsymm_px = bb_nonsymm.dx()
    h_nonsymm_px = bb_nonsymm.dy()

    # Lower left corner for the symmetrized case. This tells us
    # how the undistorted image is related to the distorted image.
    x_nonsymm_px = bb_nonsymm.x_min()
    y_nonsymm_px = bb_nonsymm.y_min()

    # Scale to pixel coordinates and extend to pixel-aligned values
    bb_symm.scale(w_px,h_px)
    bb_symm.extend_to_integer()

    # Image width and height for the symmetrized case
    w_symm_px = bb_symm.dx()
    h_symm_px = bb_symm.dy()

    # Lower left corner for the symmetrized case. This tells us
    # how the undistorted image is related to the distorted image.
    x_symm_px = bb_symm.x_min()
    y_symm_px = bb_symm.y_min()

    return x_symm_px,y_symm_px,w_symm_px,h_symm_px
def exportDistortionParameters(tde4, cam, lens, f, offset):
    """Add undistort attributes to the Maya camera"""

    model   = tde4.getLensLDModel(lens)

    f.write('addAttr -longName "tde4_lens_model" -dataType "string" -storable 1 -readable 1 -writable 1 $cameraShape;\n')
    f.write('addAttr -longName "tde4_focal_length_cm" -attributeType "double" -storable 1 -readable 1 -writable 1 $cameraShape;\n')
    f.write('addAttr -longName "tde4_filmback_width_cm" -attributeType "double" -storable 1 -readable 1 -writable 1 $cameraShape;\n')
    f.write('addAttr -longName "tde4_filmback_height_cm" -attributeType "double" -storable 1 -readable 1 -writable 1 $cameraShape;\n')
    f.write('addAttr -longName "tde4_lens_center_offset_x_cm" -attributeType "double" -storable 1 -readable 1 -writable 1 $cameraShape;\n')
    f.write('addAttr -longName "tde4_lens_center_offset_y_cm" -attributeType "double" -storable 1 -readable 1 -writable 1 $cameraShape;\n')
    f.write('addAttr -longName "tde4_pixel_aspect" -attributeType "double" -storable 1 -readable 1 -writable 1 $cameraShape;\n')
    f.write('addAttr -longName "tde4_bbox_scale_factor" -attributeType "double" -storable 1 -readable 1 -writable 1 $cameraShape;\n')
    f.write('addAttr -longName "tde4_animated_distortion" -attributeType "short" -storable 1 -readable 1 -writable 1 $cameraShape;\n')

    for para in (getLDmodelParameterList(model)):
        f.write('addAttr -longName "'+ getLDmodelNukeParameterName(para) + '" -attributeType "double" -storable 1 -readable 1 -writable 1 $cameraShape;\n')

    lensModel = getLDmodelNukeNodeName(model)
    f.write('setAttr ($cameraShape+".tde4_lens_model") -type "string" "%s";\n' % lensModel)

    numberFrames = tde4.getCameraNoFrames(cam)
    if tde4.getCameraZoomingFlag(cam):
        # dynamic focal length
        for frame in range(1,numberFrames+1):
            f.write('setKeyframe -at "tde4_focal_length_cm" -t %d -v %.7f $cameraTransform; '%(frame+offset,tde4.getCameraFocalLength(cam,frame)))
    else:
        # static focal length
        f.write("setAttr ($cameraShape+\".tde4_focal_length_cm\") %7f;\n" % tde4.getCameraFocalLength(cam,1))

    fbw = tde4.getLensFBackWidth(lens)
    fbh = tde4.getLensFBackHeight(lens)
    lcx = tde4.getLensLensCenterX(lens)
    lcy = tde4.getLensLensCenterY(lens)
    pxa = tde4.getLensPixelAspect(lens)

    f.write('setAttr ($cameraShape+\".tde4_filmback_width_cm\") %.7f;\n'%fbw)
    f.write('setAttr ($cameraShape+\".tde4_filmback_height_cm\") %.7f;\n'%fbh)
    f.write('setAttr ($cameraShape+\".tde4_lens_center_offset_x_cm\") %.7f;\n'%lcx)
    f.write('setAttr ($cameraShape+\".tde4_lens_center_offset_y_cm\") %.7f;\n'%lcy)
    f.write('setAttr ($cameraShape+\".tde4_pixel_aspect\") %.7f;\n'%pxa)

    # compute the bounding box scale factor (animation taken into account)
    bbox_x, bbox_y, bbox_w, bbox_h = getDistortionBoundingBox(cam, lcx, lcy)
    w_px = tde4.getCameraImageWidth(cam)
    h_px = tde4.getCameraImageHeight(cam)
    # print "%dx%d => %dx%d" % (w_px, h_px, bbox_w, bbox_h)
    distortion_scale_x = float(bbox_w+2) / float(w_px)
    distortion_scale_y = float(bbox_h+2) / float(h_px)
    # print "distortion scale factor x: %f" % distortion_scale_x
    # print "distortion scale factor y: %f" % distortion_scale_y
    distortion_scale = max(distortion_scale_x, distortion_scale_y)
    f.write('setAttr ($cameraShape+\".tde4_bbox_scale_factor\") %.7f;\n' % distortion_scale)

    if tde4.getLensDynamicDistortionFlag(lens):
        # dynamic distortion
        for para in (getLDmodelParameterList(model)):
            for frame in range(1,numberFrames):
                focal = tde4.getCameraFocalLength(cam,frame)
                f.write('setKeyframe -at "%s" -t %d -v %.7f $cameraTransform; '%(getLDmodelNukeParameterName(para),frame+offset,tde4.getLensLDAdjustableParameter(lens, para, focal)))
        f.write('setAttr ($cameraShape+\".tde4_animated_distortion\") 1;\n')
    else:
        # static distortion
        for para in (getLDmodelParameterList(model)):
            f.write('setAttr ($cameraShape+\".'+getLDmodelNukeParameterName(para)+'\") %.7f;\n' % tde4.getLensLDAdjustableParameter(lens, para, 1))
        f.write('setAttr ($cameraShape+\".tde4_animated_distortion\") 0;\n')