Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

rvec tvec ros message

import numpy as np
import cv2
import tf
from geometry_msgs.msg import PoseStamped

rvec, tvec = cv2.some_function()

# we need a homogeneous matrix but OpenCV only gives us a 3x3 rotation matrix
rotation_matrix = np.array([[0, 0, 0, 0],
                            [0, 0, 0, 0],
                            [0, 0, 0, 0],
                            [0, 0, 0, 1]],
                            dtype=float)
rotation_matrix[:3, :3], _ = cv2.Rodrigues(rvec)

# convert the matrix to a quaternion
quaternion = tf.transformations.quaternion_from_matrix(rotation_matrix)

# To visualize in rviz, you can, for example, publish a PoseStamped message:
pose = PoseStamped()
pose.header.frame_id = "camera_frame"
pose.pose.position.x = tvec[0]
pose.pose.position.y = tvec[1]
pose.pose.position.z = tvec[2]
pose.pose.orientation.x = quaternion[0]
pose.pose.orientation.y = quaternion[1]
pose.pose.orientation.z = quaternion[2]
pose.pose.orientation.w = quaternion[3]

pose_publisher.publish(pose)
Comment

PREVIOUS NEXT
Code Example
Python :: find geomean of a df 
Python :: print(DATA.popitem()) 
Python :: find index of max value in 2d array python 
Python :: make python look good 
Python :: flower not implemented error 
Python :: olst = [] a = int(input()) b = int(input()) for ele in range(a,b+1): if ele%2 != 0: olst.append(ele) print(olst[::-1]) 
Python :: SerialClient.py", line 41, in <module import queue ImportError: No module named queue 
Python :: using-len-for-text-but-discarding-spaces-in-the-count 
Python :: DateTime object representing DateTime in Python 
Python :: subplot adjust python 
Python :: how to set the location on a pygame window 
Python :: ask a question on python 
Python :: change name of column pandas 
Python :: sha256 pandas 
Python :: multiple loss pytorch 
Python :: most occurring string in column pandas 
Python :: python immutable default parameters 
Python :: how to lock writing to a variable thread python 
Python :: is int python 
Python :: drop duplicates pandas first column 
Python :: pandas dataframe creation column names 
Python :: how to create a cube in ursina 
Python :: numpy multiply by inverse square root of value 
Python :: matplotlib display axis in scientific notation 
Python :: how to fill an array with consecutive numbers 
Python :: python die 
Python :: who is elcharitas 
Python :: python sort list of lists by second element 
Python :: how to get started with python 
Python :: how to reverse a number in python 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =