41 const std::string
LOGNAME =
"handeye_charuco_target";
44 const std::map<std::string, cv::aruco::PREDEFINED_DICTIONARY_NAME>
ARUCO_DICTIONARY = {
45 {
"DICT_4X4_250", cv::aruco::DICT_4X4_250 },
46 {
"DICT_5X5_250", cv::aruco::DICT_5X5_250 },
47 {
"DICT_6X6_250", cv::aruco::DICT_6X6_250 },
48 {
"DICT_7X7_250", cv::aruco::DICT_7X7_250 },
49 {
"DICT_ARUCO_ORIGINAL", cv::aruco::DICT_ARUCO_ORIGINAL }
54 parameters_.push_back(Parameter(
"squares, X", Parameter::ParameterType::Int, 5));
55 parameters_.push_back(Parameter(
"squares, Y", Parameter::ParameterType::Int, 7));
56 parameters_.push_back(Parameter(
"marker size (px)", Parameter::ParameterType::Int, 50));
57 parameters_.push_back(Parameter(
"square size (px)", Parameter::ParameterType::Int, 80));
58 parameters_.push_back(Parameter(
"margin size (px)", Parameter::ParameterType::Int, 2));
59 parameters_.push_back(Parameter(
"marker border (bits)", Parameter::ParameterType::Int, 1));
60 std::vector<std::string> dictionaries;
63 dictionaries.push_back(kv.first);
65 parameters_.push_back(Parameter(
"ArUco dictionary", Parameter::ParameterType::Enum, dictionaries, 1));
66 parameters_.push_back(Parameter(
"longest board side (m)", Parameter::ParameterType::Float, 0.56));
67 parameters_.push_back(Parameter(
"measured marker size (m)", Parameter::ParameterType::Float, 0.06));
76 int marker_size_pixels;
77 int square_size_pixels;
79 int margin_size_pixels;
80 std::string dictionary_id;
81 double board_size_meters;
82 double marker_size_meters;
89 getParameter(
"measured marker size (m)", marker_size_meters) &&
91 margin_size_pixels, dictionary_id) &&
98 int square_size_pixels,
int border_size_bits,
99 int margin_size_pixels,
const std::string& dictionary_id)
101 if (squares_x <= 0 || squares_y <= 0 || marker_size_pixels <= 0 || square_size_pixels <= 0 ||
102 margin_size_pixels < 0 || border_size_bits <= 0 || square_size_pixels <= marker_size_pixels ||
106 "Invalid target intrinsic params.\n"
107 <<
"squares_x " << std::to_string(squares_x) <<
"\n"
108 <<
"squares_y " << std::to_string(squares_y) <<
"\n"
109 <<
"marker_size_pixels " << std::to_string(marker_size_pixels) <<
"\n"
110 <<
"square_size_pixels " << std::to_string(square_size_pixels) <<
"\n"
111 <<
"border_size_bits " << std::to_string(border_size_bits) <<
"\n"
112 <<
"margin_size_pixels " << std::to_string(margin_size_pixels) <<
"\n"
113 <<
"dictionary_id " << dictionary_id <<
"\n");
134 if (board_size_meters <= 0 || marker_size_meters <= 0 ||
138 "Invalid target measured dimensions. Longest board dimension: %f. Marker size: %f",
139 board_size_meters, marker_size_meters);
145 "Set target real dimensions: \n"
146 <<
"board_size_meters " << std::to_string(board_size_meters) <<
"\n"
147 <<
"marker_size_meters " << std::to_string(marker_size_meters) <<
"\n"
165 cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(
dictionary_id_);
166 cv::Ptr<cv::aruco::CharucoBoard> board = cv::aruco::CharucoBoard::create(
172 catch (
const cv::Exception& e)
185 std::lock_guard<std::mutex> base_lock(
base_mutex_);
190 cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(
dictionary_id_);
192 cv::Ptr<cv::aruco::CharucoBoard> board =
195 cv::Ptr<cv::aruco::DetectorParameters> params_ptr(
new cv::aruco::DetectorParameters());
196 #if CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION == 2
197 params_ptr->doCornerRefinement =
true;
199 params_ptr->cornerRefinementMethod = cv::aruco::CORNER_REFINE_NONE;
202 std::vector<int> marker_ids;
203 std::vector<std::vector<cv::Point2f>> marker_corners;
204 cv::aruco::detectMarkers(image, dictionary, marker_corners, marker_ids, params_ptr);
205 if (marker_ids.empty())
212 std::vector<cv::Point2f> charuco_corners;
213 std::vector<int> charuco_ids;
214 cv::aruco::interpolateCornersCharuco(marker_corners, marker_ids, image, board, charuco_corners, charuco_ids,
218 bool valid = cv::aruco::estimatePoseCharucoBoard(charuco_corners, charuco_ids, board,
camera_matrix_,
236 cv::cvtColor(image, image_rgb, cv::COLOR_GRAY2RGB);
237 cv::aruco::drawDetectedMarkers(image_rgb, marker_corners);
241 catch (
const cv::Exception& e)