Skip to content

Commit

Permalink
add publishing PoseCentroid
Browse files Browse the repository at this point in the history
  • Loading branch information
alecive committed Sep 12, 2019
1 parent 3a4c582 commit 5e25156
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
14 changes: 7 additions & 7 deletions aruco/include/aruco/marker.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ class ARUCO_EXPORTS Marker: public std::vector<cv::Point2f>
* @param setYPerpendicular If set the Y axis will be perpendicular to the surface. Otherwise, it will be the Z axis
*/
void calculateExtrinsics(float markerSize, cv::Mat CameraMatrix, cv::Mat Distorsion=cv::Mat(), bool setYPerpendicular=true)throw(cv::Exception);

/**Given the extrinsic camera parameters returns the GL_MODELVIEW matrix for opengl.
* Setting this matrix, the reference coordinate system will be set in this marker
*/
void glGetModelViewMatrix( double modelview_matrix[16])throw(cv::Exception);

/**
* Returns position vector and orientation quaternion for an Ogre scene node or entity.
* Use:
Expand All @@ -97,8 +97,8 @@ class ARUCO_EXPORTS Marker: public std::vector<cv::Point2f>
* mySceneNode->setOrientation( ogreOrient );
* ...
*/
void OgreGetPoseParameters( double position[3], double orientation[4] )throw(cv::Exception);
void OgreGetPoseParameters( double position[3], double orientation[4] )throw(cv::Exception);

/**Returns the centroid of the marker
*/
cv::Point2f getCenter()const;
Expand Down Expand Up @@ -132,11 +132,11 @@ class ARUCO_EXPORTS Marker: public std::vector<cv::Point2f>

return str;
}


private:
void rotateXAxis(cv::Mat &rotation);

};

}
Expand Down
8 changes: 7 additions & 1 deletion aruco/src/aruco/marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,18 @@ namespace aruco {

cv::Mat ImagePoints(4,2,CV_32FC1);

//Set image points from the marker
//Set image points from the marker and calculate the centroid on image
// Point cent(0,0);
for (int c=0;c<4;c++)
{
ImagePoints.at<float>(c,0)=((*this)[c%4].x);
ImagePoints.at<float>(c,1)=((*this)[c%4].y);

// cent.x += ImagePoints.at<float>(c,0);
// cent.y += ImagePoints.at<float>(c,1)
}
// cent.x/=4.;
// cent.y/=4.;

cv::Mat raux,taux;
cv::solvePnP(ObjPoints, ImagePoints, camMatrix, distCoeff,raux,taux);
Expand Down
2 changes: 1 addition & 1 deletion aruco_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ find_package(catkin REQUIRED COMPONENTS
geometry_msgs
std_msgs)

add_message_files( FILES Marker.msg MarkerArray.msg )
add_message_files( FILES Marker.msg MarkerArray.msg PoseWithCentroid.msg)
generate_messages( DEPENDENCIES std_msgs geometry_msgs )

catkin_package(
Expand Down
3 changes: 3 additions & 0 deletions aruco_msgs/msg/PoseWithCentroid.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Header header
geometry_msgs/Pose pose
geometry_msgs/Point image_centroid
23 changes: 17 additions & 6 deletions aruco_ros/src/simple_single.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ or implied, of Rafael Muñoz Salinas.
#include <tf/transform_broadcaster.h>
#include <tf/transform_listener.h>

#include <aruco_msgs/PoseWithCentroid.h>

using namespace aruco;

class ArucoSimple
Expand All @@ -62,7 +64,8 @@ class ArucoSimple
image_transport::Publisher image_pub;
image_transport::Publisher debug_pub;
ros::Publisher pose_pub;
ros::Publisher transform_pub;
ros::Publisher pose_with_centroid_pub;
ros::Publisher transform_pub;
ros::Publisher position_pub;
std::string marker_frame;
std::string camera_frame;
Expand Down Expand Up @@ -91,8 +94,8 @@ class ArucoSimple
else if ( refinementMethod == "HARRIS" )
mDetector.setCornerRefinementMethod(aruco::MarkerDetector::HARRIS);
else if ( refinementMethod == "NONE" )
mDetector.setCornerRefinementMethod(aruco::MarkerDetector::NONE);
else
mDetector.setCornerRefinementMethod(aruco::MarkerDetector::NONE);
else
mDetector.setCornerRefinementMethod(aruco::MarkerDetector::LINES);

float min_size;
Expand All @@ -108,6 +111,7 @@ class ArucoSimple
image_pub = it.advertise("result", 1);
debug_pub = it.advertise("debug", 1);
pose_pub = nh.advertise<geometry_msgs::PoseStamped>("pose", 100);
pose_with_centroid_pub = nh.advertise<aruco_msgs::PoseWithCentroid>("pose_with_centroid", 100);
transform_pub = nh.advertise<geometry_msgs::TransformStamped>("transform", 100);
position_pub = nh.advertise<geometry_msgs::Vector3Stamped>("position", 100);

Expand Down Expand Up @@ -198,9 +202,9 @@ class ArucoSimple
cameraToReference);
}

transform =
static_cast<tf::Transform>(cameraToReference)
* static_cast<tf::Transform>(rightToLeft)
transform =
static_cast<tf::Transform>(cameraToReference)
* static_cast<tf::Transform>(rightToLeft)
* transform;

tf::StampedTransform stampedTransform(transform, curr_stamp,
Expand All @@ -216,6 +220,13 @@ class ArucoSimple
tf::transformStampedTFToMsg(stampedTransform, transformMsg);
transform_pub.publish(transformMsg);

aruco_msgs::PoseWithCentroid poseWithCentroidMsg;
poseWithCentroidMsg.header = transformMsg.header;
poseWithCentroidMsg.pose = poseMsg.pose;
poseWithCentroidMsg.image_centroid.x = markers[i].getCenter().x;
poseWithCentroidMsg.image_centroid.y = markers[i].getCenter().y;
pose_with_centroid_pub.publish(poseWithCentroidMsg);

geometry_msgs::Vector3Stamped positionMsg;
positionMsg.header = transformMsg.header;
positionMsg.vector = transformMsg.transform.translation;
Expand Down

0 comments on commit 5e25156

Please sign in to comment.