marker_creator.cpp
Go to the documentation of this file.
1 
19 #include "marker_creator.h"
20 #include <ros_uri/ros_uri.hpp>
21 #include <iostream>
22 #include <fstream>
23 #include <string>
24 #include <opencv2/highgui/highgui.hpp>
25 #include "aruco/arucofidmarkers.h"
26 
27 namespace aruco_marker_recognition {
28 
30  ROS_DEBUG_STREAM("Initialize parameters");
31 
32  nh_.getParam("marker_ids", marker_ids_);
33  nh_.getParam("marker_pixel_size", marker_pixel_size_);
34  nh_.getParam("output_rel_path", output_rel_path_);
35 
36  ROS_DEBUG_STREAM("Initializing done");
37 
38  createMarkers();
39 }
40 
42  ROS_DEBUG_STREAM("Creating markers");
43  std::string output_path = ros::package::getPath(PACKAGE_NAME) + output_rel_path_;
44 
45  for (int id : marker_ids_) {
46  if (id >= 0 && id <= 1023) {
47  std::ofstream marker_file;
48  std::string marker_path = output_path + "marker_" + std::to_string(id) + ".png";
49  marker_file.open (marker_path);
50  if (marker_file.is_open()) {
51  marker_file.close();
52  cv::Mat marker = aruco::FiducidalMarkers::createMarkerImage(id, marker_pixel_size_, true, false);
53  cv::imwrite(marker_path, marker);
54  } else {
55  ROS_ERROR_STREAM("Could not find the given output directory");
56  break;
57  }
58  } else {
59  ROS_ERROR_STREAM("Can't create a marker with id " << id << " (only ids from 0-1023 are allowed");
60  }
61  }
62 
63  ROS_DEBUG_STREAM("Marker creation completed");
64 
65 }
66 
67 }
68 
69 int main(int argc, char** argv) {
70 
71  ros::init(argc, argv, "marker_creator");
72 
74 
75  return 0;
76 }
static cv::Mat createMarkerImage(int id, int size, bool writeIdWaterMark=true, bool locked=false)
Creates an ar marker with the id specified using a modified version of the hamming code...
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
static const std::string NODE_NAME("asr_aruco_marker_recognition")
void createMarkers()
Creates the markers with the parameters set in this class&#39; members.
This class is used to create marker images which can be recognized with this package.
#define ROS_DEBUG_STREAM(args)
ROSLIB_DECL std::string getPath(const std::string &package_name)
MarkerCreator()
The constructor of this class.
static const std::string PACKAGE_NAME("asr_aruco_marker_recognition")
bool getParam(const std::string &key, std::string &s) const
#define ROS_ERROR_STREAM(args)


asr_aruco_marker_recognition
Author(s): Allgeyer Tobias, Meißner Pascal, Qattan Mohamad
autogenerated on Mon Jun 10 2019 12:40:21