[python] 3차원 곡간 νšŒμ „ λ³€ν™˜ | scipy Rotation

2024. 3. 29. 16:12Β·πŸ’» Programming/Computer Vision
λ°˜μ‘ν˜•

scipy의 Rotation ν΄λž˜μŠ€λŠ” 3D κ³΅κ°„μ—μ„œμ˜ νšŒμ „ λ³€ν™˜μ„ λ‹€λ£¨λŠ” 데 μ‚¬μš©λœλ‹€. νšŒμ „μ„ λ‚˜νƒ€λ‚΄λŠ” ν–‰λ ¬λ‘œλΆ€ν„° νšŒμ „μ„ μˆ˜ν–‰ν•˜κ±°λ‚˜, νšŒμ „μ„ λ‚˜νƒ€λ‚΄λŠ” μΆ•κ³Ό 각도λ₯Ό μ‚¬μš©ν•˜μ—¬ νšŒμ „μ„ μˆ˜ν–‰ν•  수 μžˆμ–΄μ„œ 3D geometryλ₯Ό λ‹€λ£° λ•Œ ν•΄λ‹Ή 클래슀λ₯Ό 자주 μ‚¬μš©ν•˜κ³  μžˆλ‹€.

 

κ·Έ 쀑에도 Rotation.apply() λ©”μ„œλ“œλ₯Ό 자주 μ‚¬μš©ν•˜λŠ”λ°, 이 λ©”μ„œλ“œλŠ” νšŒμ „λœ 벑터λ₯Ό λ°˜ν™˜ν•œλ‹€. 

 

ν•΄λ‹Ή λ©”μ„œλ“œμ˜ κΈ°λŠ₯은 벑터에 νšŒμ „ 행렬을 κ³±ν•˜λŠ” 것이며, μˆ˜μ‹μ μœΌλ‘œλŠ” μœ„μ™€ 같이 κΈ°μ‘΄ 벑터에 νšŒμ „ν–‰λ ¬(R)을 κ³±ν•˜λŠ” 것과 κ°™λ‹€. νšŒμ „ 행렬을 벑터에 κ³±ν•¨μœΌλ‘œμ¨ νšŒμ „λœ 벑터λ₯Ό 얻을 수 μžˆλ‹€.

 

Rotation.inv().apply() λ₯Ό μ‚¬μš©ν•˜λ©΄ νšŒμ „ ν–‰λ ¬μ˜ 역행렬을 벑터에 μ μš©ν•˜μ—¬ νšŒμ „ ν–‰λ ¬μ˜ λ°˜λŒ€λ°©ν–₯으둜 νšŒμ „μ‹œν‚¬ μˆ˜λ„ μžˆλ‹€.

 

 

μ½”λ“œ 예제

from scipy.spatial.transform import Rotation as R
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 였일러 각 (yaw, pitch, roll) μ •μ˜ (λΌλ””μ•ˆ λ‹¨μœ„)
yaw = np.pi / 4  # z 좕을 κΈ°μ€€μœΌλ‘œ νšŒμ „ν•˜λŠ” 각도 (yaw)
pitch = np.pi / 6  # y 좕을 κΈ°μ€€μœΌλ‘œ νšŒμ „ν•˜λŠ” 각도 (pitch)
roll = np.pi / 3  # x 좕을 κΈ°μ€€μœΌλ‘œ νšŒμ „ν•˜λŠ” 각도 (roll)

# 였일러 각을 νšŒμ „ 객체둜 λ³€ν™˜
rot = R.from_euler('zyx', [yaw, pitch, roll])

# νšŒμ „μ„ μ μš©ν•  벑터 μ •μ˜
vec = [0.1, 0, 0]

# νšŒμ „ 적용
rotated_vec = rot.apply(vec)

# μ‹œκ°ν™”λ₯Ό μœ„ν•œ μ€€λΉ„
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# μ›λž˜ 벑터λ₯Ό μ‹œκ°ν™”
ax.quiver(0, 0, 0, vec[0], vec[1], vec[2], color='b', label='Original Vector')

# νšŒμ „λœ 벑터λ₯Ό μ‹œκ°ν™”
ax.quiver(0, 0, 0, rotated_vec[0], rotated_vec[1], rotated_vec[2], color='r', label='Rotated Vector')

# μΆ• λ ˆμ΄λΈ” μΆ”κ°€
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# λ²”λ‘€ μΆ”κ°€
ax.legend()

# κ·Έλž˜ν”„ 좜λ ₯
plt.show()

  • 였일러 각을 μ‚¬μš©ν•˜μ—¬ 벑터λ₯Ό νšŒμ „ν•˜λŠ” 예제 μ½”λ“œ
  • scipy.spatial.transform.Rotation 클래슀의 from_euler() λ©”μ„œλ“œλ₯Ό μ‚¬μš© - 였일러 각을 νšŒμ „ 객체둜 λ³€ν™˜
  • apply() λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ νšŒμ „을 μ μš©ν•  λ²‘터에 νšŒμ „을 μ μš©

 

 

λ°˜μ‘ν˜•

'πŸ’» Programming > Computer Vision' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

[Meta AI] SAM (Segment Anything Model) μ‚¬μš© 방법 | λͺ¨λ“  객체λ₯Ό λΆ„ν• ν•˜λŠ” Vision AI λͺ¨λΈ  (0) 2023.04.21
[OpenCV] Feature Detection & Matching | νŠΉμ§• κ²€μΆœκ³Ό λ§€μΉ­ | μ΄λ―Έμ§€μ—μ„œ μœ μ‚¬ν•œ νŠΉμ§• μ°Ύμ•„λ‚΄κΈ° | 이미지 λŒ€μ‘μ   (0) 2023.04.03
[OpenCV] Template Matching ν…œν”Œλ¦Ώ λ§€μΉ­ | μ΄λ―Έμ§€μ—μ„œ μœ μ‚¬ν•œ λΆ€λΆ„ μ°Ύμ•„λ‚΄κΈ°  (0) 2023.03.31
[OpenCV] Image Contour μΆ”μΆœ | 이미지 μ»¨νˆ¬μ–΄ | 객체 μœ€κ³½μ„  μΆ”μΆœ | 기초적인 segmentation 방법  (0) 2023.03.30
[OpenCV] Morphological Operations λͺ¨ν΄λ‘œμ§€ μ—°μ‚° | 객체의 λ‚΄λΆ€ μ±„μš°κΈ° | 객체의 경계 λΆ€λ“œλŸ½κ²Œ | 객체의 크기 쀄이기 | 객체 μ—°κ²°ν•˜κΈ° | 경계 κ°•μ‘°ν•˜κΈ°  (0) 2023.03.29
'πŸ’» Programming/Computer Vision' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€
  • [Meta AI] SAM (Segment Anything Model) μ‚¬μš© 방법 | λͺ¨λ“  객체λ₯Ό λΆ„ν• ν•˜λŠ” Vision AI λͺ¨λΈ
  • [OpenCV] Feature Detection & Matching | νŠΉμ§• κ²€μΆœκ³Ό λ§€μΉ­ | μ΄λ―Έμ§€μ—μ„œ μœ μ‚¬ν•œ νŠΉμ§• μ°Ύμ•„λ‚΄κΈ° | 이미지 λŒ€μ‘μ 
  • [OpenCV] Template Matching ν…œν”Œλ¦Ώ λ§€μΉ­ | μ΄λ―Έμ§€μ—μ„œ μœ μ‚¬ν•œ λΆ€λΆ„ μ°Ύμ•„λ‚΄κΈ°
  • [OpenCV] Image Contour μΆ”μΆœ | 이미지 μ»¨νˆ¬μ–΄ | 객체 μœ€κ³½μ„  μΆ”μΆœ | 기초적인 segmentation 방법
뭅즀
뭅즀
AI 기술 λΈ”λ‘œκ·Έ
    λ°˜μ‘ν˜•
  • 뭅즀
    CV DOODLE
    뭅즀
  • 전체
    였늘
    μ–΄μ œ
  • 곡지사항

    • ✨ About Me
    • λΆ„λ₯˜ 전체보기 (198)
      • πŸ“– Fundamentals (33)
        • Computer Vision (9)
        • 3D vision & Graphics (6)
        • AI & ML (15)
        • NLP (2)
        • etc. (1)
      • πŸ› Research (64)
        • Deep Learning (7)
        • Image Classification (2)
        • Detection & Segmentation (17)
        • OCR (7)
        • Multi-modal (4)
        • Generative AI (6)
        • 3D Vision (2)
        • Material & Texture Recognit.. (8)
        • NLP & LLM (11)
        • etc. (0)
      • 🌟 AI & ML Tech (7)
        • AI & ML μΈμ‚¬μ΄νŠΈ (7)
      • πŸ’» Programming (85)
        • Python (18)
        • Computer Vision (12)
        • LLM (4)
        • AI & ML (17)
        • Database (3)
        • Apache Airflow (6)
        • Docker & Kubernetes (14)
        • μ½”λ”© ν…ŒμŠ€νŠΈ (4)
        • C++ (1)
        • etc. (6)
      • πŸ’¬ ETC (3)
        • μ±… 리뷰 (3)
  • 링크

  • 인기 κΈ€

  • νƒœκ·Έ

    Python
    GPT
    ν”„λ‘¬ν”„νŠΈμ—”μ§€λ‹ˆμ–΄λ§
    OpenAI
    AI
    객체 κ²€μΆœ
    LLM
    Text recognition
    ChatGPT
    segmentation
    deep learning
    object detection
    κ°μ²΄κ²€μΆœ
    multi-modal
    airflow
    도컀
    pytorch
    pandas
    3D Vision
    파이썬
    material recognition
    컴퓨터비전
    CNN
    nlp
    VLP
    OpenCV
    Image Classification
    Computer Vision
    OCR
    λ”₯λŸ¬λ‹
  • 졜근 λŒ“κΈ€

  • 졜근 κΈ€

  • hELLOΒ· Designed Byμ •μƒμš°.v4.10.3
뭅즀
[python] 3차원 곡간 νšŒμ „ λ³€ν™˜ | scipy Rotation
μƒλ‹¨μœΌλ‘œ

ν‹°μŠ€ν† λ¦¬νˆ΄λ°”