34 int main(
int argc,
char **argv) {
58 cv::namedWindow(
"aruco_node_debug", CV_WINDOW_NORMAL | CV_GUI_NORMAL);
66 float camera_matrix_data[9];
67 for(
int i = 0; i < 9; i++)
68 camera_matrix_data[i] = camer_info->K[i];
69 cv::Mat camera_matrix = cv::Mat(3, 3, CV_32F, camera_matrix_data);
71 float distortion_coefficients_data[5];
72 for(
int i = 0; i < 5; i++)
73 distortion_coefficients_data[i] = camer_info->D[i];
74 cv::Mat distortion_coefficients = cv::Mat(1, 5, CV_32F, distortion_coefficients_data);
76 return aruco::CameraParameters(camera_matrix, distortion_coefficients, cv::Size(camer_info->width, camer_info->height));
89 m.at<
float>(0, 0), m.at<
float>(0, 1), m.at<
float>(0, 2),
90 m.at<
float>(1, 0), m.at<
float>(1, 1), m.at<
float>(1, 2),
91 m.at<
float>(2, 0), m.at<
float>(2, 1), m.at<
float>(2, 2)
95 sprintf(markerLabel,
"t%i", markerPose.
getMarkerId());
100 marker_msgs::MarkerDetection msg;
103 msg.distance_min = 0;
104 msg.distance_max = 8;
105 msg.distance_max_id = 5;
106 msg.view_direction.x = 0;
107 msg.view_direction.y = 0;
108 msg.view_direction.z = 0;
109 msg.view_direction.w = 1;
110 msg.fov_horizontal = 6;
111 msg.fov_vertical = 0;
113 msg.markers = marker_msgs::MarkerDetection::_markers_type();
115 for (
auto &markerPose:markerPoses) {
123 marker_msgs::Marker marker;
125 marker.ids.resize(1);
126 marker.ids_confidence.resize(1);
127 marker.ids[0] = markerPose.getMarkerId();
128 marker.ids_confidence[0] = 1;
131 msg.markers.push_back(marker);
139 void ArUcoNode::publishFiducials(
const std_msgs::Header &header, vector<aruco::Marker> &markers,
const sensor_msgs::CameraInfoConstPtr &camer_info_) {
140 marker_msgs::FiducialDetection msg;
142 msg.camera_k = camer_info_->K;
143 msg.camera_d = camer_info_->D;
145 for (
auto &marker:markers) {
146 marker_msgs::Fiducial fiducial;
150 geometry_msgs::Point point;
154 fiducial.object_points.push_back(point);
158 for (cv::Point2f &p2d: marker) {
159 geometry_msgs::Point point;
163 fiducial.image_points.push_back(point);
166 fiducial.ids.resize(1);
167 fiducial.ids_confidence.resize(1);
168 fiducial.ids[0] = marker.id;
169 fiducial.ids_confidence[0] = 1;
171 msg.fiducial.push_back(fiducial);
188 vector<aruco::Marker> markers;
197 vector<ArUcoMarkerPose> markerPoses;
209 cvtColor(imgPtr->image, debugImage, cv::COLOR_GRAY2BGR);
211 for (
unsigned int i = 0; i < markers.size(); i++) {
213 markers[i].draw(debugImage, cv::Scalar(0, 0, 255), 1);
220 cv::imshow(
"aruco_node_debug", debugImage);
224 ROS_ERROR (
"cv_bridge exception: %s", e.what());
void setPublishFiducials(bool b)
static tf::StampedTransform markerPoseToStampedTransform(ArUcoMarkerPose &markerPose, const std_msgs::Header &header)
void publish(const boost::shared_ptr< M > &message) const
image_transport::ImageTransport imageTransport_
CameraSubscriber subscribeCamera(const std::string &base_topic, uint32_t queue_size, const CameraSubscriber::Callback &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
image_transport::CameraSubscriber cameraSubscriber_
void publishMarkers(const std_msgs::Header &header, vector< ArUcoMarkerPose > &markerPoses)
bool getPoseEstimationEnabled()
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
static aruco::CameraParameters cameraInfoToCameraParameters(const sensor_msgs::CameraInfoConstPtr &camer_info)
static void draw3dAxis(cv::Mat &Image, const CameraParameters &CP, const cv::Mat &Rvec, const cv::Mat &Tvec, float axis_size)
ROSCPP_DECL void spin(Spinner &spinner)
tf::TransformBroadcaster transformBroadcaster_
void setPublishMarkers(bool b)
void imageCallback(const sensor_msgs::ImageConstPtr &image_msg, const sensor_msgs::CameraInfoConstPtr &camer_info_)
void setPoseEstimationEnabled(bool b)
void setShowDebugImage(bool b)
void configCallback(tuw_aruco::ArUcoConfig &config, uint32_t level)
ros::Publisher pub_fiducials_
CvImagePtr cvtColor(const CvImageConstPtr &source, const std::string &encoding)
void estimatePose(vector< ArUcoMarkerPose > &markerPoses, vector< aruco::Marker > &markers, aruco::CameraParameters cameraParams)
dynamic_reconfigure::Server< tuw_aruco::ArUcoConfig >::CallbackType configCallbackFnct_
CvImagePtr toCvCopy(const sensor_msgs::ImageConstPtr &source, const std::string &encoding=std::string())
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
Parameters of the camera.
static void draw3dCube(cv::Mat &Image, Marker &m, const CameraParameters &CP, bool setYperpendicular=false)
void setPublishTf(bool b)
int main(int argc, char **argv)
bool getPublishFiducials()
static void poseTFToMsg(const Pose &bt, geometry_msgs::Pose &msg)
void setDictionary(std::string dictionary)
ros::Publisher pub_markers_
void setMarkerSize(float mSize)
void detectMarkers(vector< aruco::Marker > &markers, cv::Mat image)
void publishFiducials(const std_msgs::Header &header, vector< aruco::Marker > &markers, const sensor_msgs::CameraInfoConstPtr &camer_info_)
ArUcoParameters & getParameters()
dynamic_reconfigure::Server< tuw_aruco::ArUcoConfig > configServer_
ArUcoNode(ros::NodeHandle &n)