ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Obtain position of the object data from Homography matrix

asked 2023-07-10 12:13:18 -0600

updated 2023-07-11 07:13:49 -0600

Mike Scheutzow gravatar image

Hi community! Im using ros noetic and gazebo 11 in unbuntu 20.04.

Im using rosbot packages and running find_objects_2d package present in its tutorial. The issue is that this package uses reads Homography matrix data received to obtain object's orientation with some processing on the pixels.

We understand that the Homography matrix should bring us to the position of the object refered to robot's base_link, but the question is, how to process the data from this matrix? Is a 9x9 one. Our objective is to obtain object position so we can send a goal to move_base package, because we want move_base to be in charge of the motion of our robot.

Here are some examples, knowing robot's position ( 0,0,0) and object position, the results are wrong, they were obtained with the code below that we were trying to apply. The desired result is the indicated by x and y (that are the real coordenates where our object was located):

//Object 2
//0.6100760698318481, -0.059579864144325256, -0.0003138711617793888, 
//-0.02506314031779766, 0.6501667499542236, -9.795412915991619e-05, 
//188.61143493652344, 101.26304626464844, 1.0

//x = 3
//y= 0
// Result: 
//Distance: 0.396946
// Angle: -0.097351

//Object 3
//0.37898701429367065, -0.0909111276268959, -0.00037208336289040744, 
//0.022685814648866653, 0.5084739327430725, 9.063976176548749e-05, 
//245.93141174316406, 139.2412109375, 1.0
//Result:
//Distance: 0.192897
//Angle: -0.235431

#include <iostream>
#include <vector>
#include <cmath> // Incluir cmath para utilizar la función abs y atan2

using namespace std;

int main() {
  vector<double> matrix = {
    0.37898701429367065, -0.0909111276268959, -0.00037208336289040744, 
    0.022685814648866653, 0.5084739327430725, 9.063976176548749e-05, 
    245.93141174316406, 139.2412109375, 1.0
  };

  double norm = sqrt(matrix[3]*matrix[3] + matrix[4]*matrix[4] + matrix[5]*matrix[5]); // Cálculo de la norma

  double distance = abs(matrix[0]) * norm;
  double angle = atan2(matrix[1], matrix[0]);

  cout << "Distance: " << distance << endl;
  cout << "Angle: " << angle << endl;

  return 0;
}

Could you tell me another option to detect object position referd to my robot using camera, tof sensor or lidar?

Thanks!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2023-07-11 07:44:58 -0600

Mike Scheutzow gravatar image

This approach is not capable of estimating the distance to an "object". If all you have is one 2D-image and a homography matrix, you do not have enough information to calculate a distance. However, for a specific pixel within the image, you can estimate the horizontal and vertical angles relative to the optical center line.

edit flag offensive delete link more
0

answered 2023-07-11 08:21:07 -0600

bluegiraffe-sc gravatar image

If I have got it correctly, you are using the find_object_2d with the ~subscribe_depth parameter set to True (which is, you have RGB and registered depth information). You should then see one TF per detected object being published. You can check it out in Rviz.

If that is the case, I see two main options:

  • Look into this script to understand how to use tf to transform the origin of the object reference frame into the robot's base reference frame.

  • Directly give to move_base a point (e.g. the origin) in the objects' reference frame (i.e. specifying the objects' reference frame in the PoseStamped header).

I acknowledge that this is more an alternative solution than an answer to your question about homographic transforms, but I hope it will be helpful!

edit flag offensive delete link more

Question Tools

Stats

Asked: 2023-07-10 12:13:18 -0600

Seen: 153 times

Last updated: Jul 11 '23