This README provides a conceptual overview of Pose Estimation using PnP, focusing on the transformation matrix that converts 3D world points to 2D image points in the camera frame. It addresses the scenario where the transformation matrix is unknown but can be estimated using camera parameters and distortion coefficients.
Consider the following transformation process:
The object is represented by 3D points in a world coordinate frame.
There exists a transformation matrix that converts these world points to 2D image points in the camera frame. However, the matrix is initially unknown.
Camera parameters (intrinsic matrix) and distortion coefficients are known. These parameters define the camera's characteristics.
Using the known camera parameters and distortion coefficients, the 3D world points are transformed into 2D image points in the camera image frame.
Corresponding 2D image points are also known and represent the projections of the world points onto the image plane.
Pose Estimation using PnP is employed to estimate the unknown transformation matrix. This involves finding the rotation and translation vectors that best align the known 2D image points with the transformed 3D points.
The PnP algorithm yields a transformation matrix that accurately converts 3D world points to 2D image points in the camera frame.
The rotation vector provides information about the yaw angle (orientation), and the translation vector gives insight into the distance to travel in the camera frame.
For more info refer - https://docs.opencv.org/4.x/d5/d1f/calib3d_solvePnP.html
This ROS workspace, named robot_perception_ws
, contains a package named robot_perception
with nodes for image points publishing and pose estimation.
These instructions will guide you through setting up and running the nodes in this ROS workspace.
- ROS (Robot Operating System) installed. You can follow the installation instructions here.
-
Create a ROS Workspace:
mkdir -p ~/robot_perception_ws/src cd ~/robot_perception_ws/src catkin_init_workspace
-
Create a Package and Nodes:
cd ~/robot_perception_ws/src catkin_create_pkg robot_perception rospy std_msgs sensor_msgs cv_bridge
-
Place Nodes in the Package:
- Create two scripts,
image_points_publisher.py
andpose_estimation_node.py
, inside thesrc/robot_perception
directory.
- Create two scripts,
-
Edit CMakeLists.txt:
- Open
CMakeLists.txt
inrobot_perception
and modify it as follows:find_package(catkin REQUIRED COMPONENTS rospy std_msgs sensor_msgs cv_bridge ) catkin_python_setup() catkin_package() install(PROGRAMS scripts/image_points_pub.py scripts/pnp_sub.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} )
- Open
-
Build the Workspace:
cd ~/robot_perception_ws catkin_make
-
Source the Workspace:
source devel/setup.bash
Open multiple terminals:
- Terminal 1:
roscore
- Terminal 2:
rosrun robot_perception image_points_pub.py
- Terminal 3:
rosrun robot_perception pnp_sub.py
Adjust the names, scripts, and dependencies based on your project's requirements.
Also, here I have generated some random 2d points to simulate the process, but in real time it has to retrieve those 2d points from the object detected in the image.