38 #include <aruco/aruco.h> 39 #include <aruco/cvdrawingutils.h> 45 #include <aruco_ros/aruco_ros_utils.h> 49 #include <dynamic_reconfigure/server.h> 50 #include <aruco_ros/ArucoThresholdConfig.h> 53 using namespace aruco;
77 double ticksBefore = cv::getTickCount();
90 ROS_WARN(
"normalizeImageIllumination is unimplemented!");
101 for(
unsigned int i=0; i<
markers.size(); ++i)
109 geometry_msgs::Pose poseMsg;
118 geometry_msgs::Pose poseMsg;
132 float x[2],
y[2], u[2], v[2];
133 for (
unsigned int i = 0; i < 2; ++i)
136 <<
markers[i].Tvec.at<
float>(0,0) <<
", " 137 <<
markers[i].Tvec.at<
float>(1,0) <<
", " 138 <<
markers[i].Tvec.at<
float>(2,0));
140 x[i] =
markers[i].Tvec.at<
float>(0,0)/
markers[i].Tvec.at<
float>(2,0);
141 y[i] =
markers[i].Tvec.at<
float>(1,0)/
markers[i].Tvec.at<
float>(2,0);
150 << (x[0]+x[1])/2 <<
", " << (y[0]+y[1])/2 <<
")");
160 for (
unsigned int i = 0; i < 3; ++i )
161 midPoint3D[i] = (
markers[0].Tvec.at<
float>(i,0) +
162 markers[1].Tvec.at<
float>(i,0) ) / 2;
164 float midPointNormalized[2];
165 midPointNormalized[0] = midPoint3D[0]/midPoint3D[2];
166 midPointNormalized[1] = midPoint3D[1]/midPoint3D[2];
167 u[0] = midPointNormalized[0]*camParam.
CameraMatrix.at<
float>(0,0) +
169 v[0] = midPointNormalized[1]*camParam.
CameraMatrix.at<
float>(1,1) +
172 ROS_DEBUG_STREAM(
"3D Mid point between the two markers in undistorted pixel coordinates = (" 173 << u[0] <<
", " << v[0] <<
")");
177 cv::Point(u[0], v[0]),
178 3, cv::Scalar(0,0,255), cv::FILLED);
185 for(
unsigned int i=0; i<
markers.size(); ++i)
195 out_msg.
header.stamp = curr_stamp;
205 debug_msg.
header.stamp = curr_stamp;
212 1000*(cv::getTickCount() - ticksBefore)/cv::getTickFrequency());
216 ROS_ERROR(
"cv_bridge exception: %s", e.what());
243 dynamic_reconfigure::Server<aruco_ros::ArucoThresholdConfig> server;
244 dynamic_reconfigure::Server<aruco_ros::ArucoThresholdConfig>::CallbackType f_;
246 server.setCallback(f_);
259 pose_pub1 = nh.
advertise<geometry_msgs::Pose>(
"pose", 100);
260 pose_pub2 = nh.
advertise<geometry_msgs::Pose>(
"pose2", 100);
267 if(dctComponentsToRemove == 0)
268 normalizeImageIllumination =
false;
273 if(parent_name ==
"" || child_name1 ==
"" || child_name2 ==
"")
275 ROS_ERROR(
"parent_name and/or child_name was not set!");
279 ROS_INFO(
"Aruco node started with marker size of %f meters and marker ids to track: %d, %d",
280 marker_size, marker_id1, marker_id2);
281 ROS_INFO(
"Aruco node will publish pose to TF with (%s, %s) and (%s, %s) as (parent,child).",
282 parent_name.c_str(), child_name1.c_str(), parent_name.c_str(), child_name2.c_str());
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
void detect(const cv::Mat &input, std::vector< Marker > &detectedMarkers, cv::Mat camMatrix=cv::Mat(), cv::Mat distCoeff=cv::Mat(), float markerSizeMeters=-1, bool setYPerpendicular=true)
void setThresholdParams(double param1, double param2)
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void reconf_callback(aruco_ros::ArucoThresholdConfig &config, uint32_t level)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
void image_callback(const sensor_msgs::ImageConstPtr &msg)
TFSIMD_FORCE_INLINE const tfScalar & y() const
uint32_t getNumSubscribers() const
ROSCPP_DECL void spin(Spinner &spinner)
pcl::PointCloud< myPointXYZRID > transform(pcl::PointCloud< myPointXYZRID > pc, float x, float y, float z, float rot_x, float rot_y, float rot_z)
ros::Subscriber cam_info_sub
int dctComponentsToRemove
tf::Transform arucoMarker2Tf(const aruco::Marker &marker, bool rotate_marker_axis=true)
void publish(const sensor_msgs::Image &message) const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
image_transport::Publisher image_pub
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
bool normalizeImageIllumination
image_transport::Publisher debug_pub
TFSIMD_FORCE_INLINE const tfScalar & x() const
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
Main class for marker detection.
aruco::CameraParameters rosCameraInfo2ArucoCamParams(const sensor_msgs::CameraInfo &cam_info, bool useRectifiedParameters)
rosCameraInfo2ArucoCamParams gets the camera intrinsics from a CameraInfo message and copies them to ...
#define ROS_DEBUG_STREAM(args)
const cv::Mat & getThresholdedImage()
Parameters of the camera.
void cam_info_callback(const sensor_msgs::CameraInfo &msg)
static void poseTFToMsg(const Pose &bt, geometry_msgs::Pose &msg)
#define ROS_INFO_STREAM(args)
sensor_msgs::ImagePtr toImageMsg() const
aruco::CameraParameters camParam