當前位置: 首頁>>代碼示例>>Python>>正文


Python Rotation.from_rotvec方法代碼示例

本文整理匯總了Python中scipy.spatial.transform.Rotation.from_rotvec方法的典型用法代碼示例。如果您正苦於以下問題:Python Rotation.from_rotvec方法的具體用法?Python Rotation.from_rotvec怎麽用?Python Rotation.from_rotvec使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.spatial.transform.Rotation的用法示例。


在下文中一共展示了Rotation.from_rotvec方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: estimate_head_pose

# 需要導入模塊: from scipy.spatial.transform import Rotation [as 別名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 別名]
def estimate_head_pose(self, face: Face, camera: Camera) -> None:
        """Estimate the head pose by fitting 3D template model."""
        # If the number of the template points is small, cv2.solvePnP
        # becomes unstable, so set the default value for rvec and tvec
        # and set useExtrinsicGuess to True.
        # The default values of rvec and tvec below mean that the
        # initial estimate of the head pose is not rotated and the
        # face is in front of the camera.
        rvec = np.zeros(3, dtype=np.float)
        tvec = np.array([0, 0, 1], dtype=np.float)
        _, rvec, tvec = cv2.solvePnP(self.LANDMARKS,
                                     face.landmarks,
                                     camera.camera_matrix,
                                     camera.dist_coefficients,
                                     rvec,
                                     tvec,
                                     useExtrinsicGuess=True,
                                     flags=cv2.SOLVEPNP_ITERATIVE)
        rot = Rotation.from_rotvec(rvec)
        face.head_pose_rot = rot
        face.head_position = tvec
        face.reye.head_pose_rot = rot
        face.leye.head_pose_rot = rot 
開發者ID:hysts,項目名稱:pytorch_mpiigaze,代碼行數:25,代碼來源:face_model.py

示例2: from_rv

# 需要導入模塊: from scipy.spatial.transform import Rotation [as 別名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 別名]
def from_rv(rv):
    """Create a direction cosine matrix from a rotation vector.

    The direction of a rotation vector determines the axis of rotation and its
    magnitude determines the angle of rotation.

    The returned DCM projects a vector from the rotated frame to the original
    frame.

    Parameters
    ----------
    rv : array_like, shape (3,) or (n, 3)
        Rotation vectors.

    Returns
    -------
    dcm : ndarray, shape (3, 3) or (n, 3, 3)
        Direction cosine matrices.
    """
    return Rotation.from_rotvec(rv).as_matrix() 
開發者ID:nmayorov,項目名稱:pyins,代碼行數:22,代碼來源:dcm.py

示例3: get_mat_angle

# 需要導入模塊: from scipy.spatial.transform import Rotation [as 別名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 別名]
def get_mat_angle(translation=None, rotation=None, rotation_center=np.array([0., 0, 0])):
    mat1 = np.eye(4)
    mat2 = np.eye(4)
    mat3 = np.eye(4)
    mat1[:3, 3] = -rotation_center
    mat3[:3, 3] = rotation_center
    if translation is not None:
        mat3[:3, 3] += translation
    if rotation is not None:
        mat2[:3, :3] = Rotation.from_rotvec(np.array([0, 0, 1.]) * rotation).as_dcm()
    return np.matmul(np.matmul(mat3, mat2), mat1) 
開發者ID:grossjohannes,項目名稱:AlignNet-3D,代碼行數:13,代碼來源:pointcloud.py

示例4: rotate

# 需要導入模塊: from scipy.spatial.transform import Rotation [as 別名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 別名]
def rotate(self, rotation: Union[ndarray, Rotation]) -> Snap:
        """Rotate snapshot.

        Parameters
        ----------
        rotation
            The rotation as a scipy.spatial.transform.Rotation object
            or ndarray that can be converted to a Rotation object via
            Rotation.from_rotvec.

        Returns
        -------
        Snap
            The rotated Snap. Note that the rotation operation is
            in-place.

        Examples
        --------
        Rotate a Snap by π/3 around [1, 1, 0].

        >>> rot = np.array([1, 1, 0])
        >>> rot = rot * np.pi / 3 * np.linalg.norm(rot)
        >>> snap.rotate(rot)
        """
        logger.debug(f'Rotating snapshot: {self.file_path.name}')
        if isinstance(rotation, (list, tuple, ndarray)):
            rotation = Rotation.from_rotvec(rotation)
        for arr in self._vector_arrays:
            if arr in self.loaded_arrays():
                self._arrays[arr] = rotation.apply(self._arrays[arr])
            if arr in self.loaded_arrays(sinks=True):
                self._sinks[arr] = rotation.apply(self._sinks[arr])
        for arr in self._vector_component_arrays:
            if arr in self.loaded_arrays():
                del self._arrays[arr]
            if arr in self.loaded_arrays(sinks=True):
                del self._sinks[arr]

        if self.rotation is None:
            self.rotation = rotation
        else:
            rot = rotation * self.rotation
            self.rotation = rot

        return self 
開發者ID:dmentipl,項目名稱:plonk,代碼行數:47,代碼來源:snap.py

示例5: goniometer_rotation

# 需要導入模塊: from scipy.spatial.transform import Rotation [as 別名]
# 或者: from scipy.spatial.transform.Rotation import from_rotvec [as 別名]
def goniometer_rotation(experiment, reflections):
    # type: (Experiment, flex.reflection_table) -> Rotation
    """
    Calculate the goniometer rotation operator for each reflection.

    Following the DXTBX model of a goniometer, whereby a scan is only possible
    around one physical axis at a time, the rotation operation (conventionally
    denoted R, here denoted R' to avoid confusion with the notation of
    dxtbx/model/goniometer.h) can be calculated as R' = S · R · F.
    Here:
        * S is the 'setting rotation', the operator denoting the position of all parent
        axes of the scan axis, which hence defines the orientation of the scan axis;
        * R is the the operator denoting the scan rotation as if it were performed with
        all parent axes at zero datum, it has a different value for each reflection,
        according to the reflection centroid positions.
        * F is the 'fixed rotation', denoting the orientation of all child axes of the
        scan axis as if they were performed with all parent axes at zero datum.

    Args:
        experiment:  The DXTBX experiment object corresponding to the scan.
        reflections:  A table of reflections at which to calculate the rotations.

    Returns:
        An array of rotation operators, one per reflection in the reflection table.
    """
    # Get the axis of the scan rotation.
    rotation_axis = experiment.goniometer.get_rotation_axis_datum()
    # For each reflection, get the angle of the scan rotation.
    angles = reflections["xyzobs.mm.value"].parts()[2]
    # Construct a rotation vector (parallel with the rotation axis and with
    # magnitude equal to the rotation angle) for each reflection.
    # The shape of this array is (N, 3), where N is the number of reflections.
    rotvecs = np.outer(angles, rotation_axis)
    # Create a rotation operator for each scan rotation (i.e. one per reflection).
    # In the notation of dxtbx/model/goniometer.h, this is R.
    scan_rotation = Rotation.from_rotvec(rotvecs)

    # Get the setting rotation.
    # In the notation of dxtbx/model/goniometer.h, this is S.
    set_rotation = np.array(experiment.goniometer.get_setting_rotation()).reshape(3, 3)
    if hasattr(Rotation, "from_matrix"):
        set_rotation = Rotation.from_matrix(set_rotation)
    else:
        # SciPy < 1.4.0. Can be removed after 15th of September 2020
        set_rotation = Rotation.from_dcm(set_rotation)

    # Create a rotation operator for those axes that are fixed throughout the scan.
    # In the notation of dxtbx/model/goniometer.h, this is F.
    fixed_rotation = np.array(experiment.goniometer.get_fixed_rotation()).reshape(3, 3)
    if hasattr(Rotation, "from_matrix"):
        fixed_rotation = Rotation.from_matrix(fixed_rotation)
    else:
        # SciPy < 1.4.0. Can be removed after 15th of September 2020
        fixed_rotation = Rotation.from_dcm(fixed_rotation)

    # Calculate the rotation operator representing the goniometer orientation for each
    # reflection.  In the notation of dxtbx/model/goniometer.h this is S × R × F.
    return set_rotation * scan_rotation * fixed_rotation 
開發者ID:dials,項目名稱:dials,代碼行數:60,代碼來源:anvil_correction.py


注:本文中的scipy.spatial.transform.Rotation.from_rotvec方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。