marker_detection.cpp
Go to the documentation of this file.
1 
19 #include "marker_detection.h"
20 #include <ros/console.h>
21 #include <opencv2/core/core.hpp>
22 #include <opencv2/highgui/highgui.hpp>
23 
24 namespace aruco_marker_recognition {
25 
26 MarkerDetection::MarkerDetection(double marker_size) : marker_size_(marker_size) {
27 
28 }
29 
30 std::vector<aruco::Marker> MarkerDetection::detect(const cv::Mat &image, CameraId id, const ArucoMarkerRecognitionConfig &config) {
31  aruco::MarkerDetector mDetector;
32 
33 
34  mDetector.setMinMaxSize(config.minSize, config.maxSize);
35  switch (config.thresholdMethod) {
36  case 0:
38  break;
39  case 1:
41  break;
42  case 2:
44  break;
45  }
46  mDetector.setThresholdParams(config.minThreshold, config.maxThreshold);
47 
48  std::vector<aruco::Marker> markers;
49  if (id == CameraId::cam_left) {
50  if (cam_params_left_.isValid()) {
51  mDetector.detect(image, markers, cam_params_left_, marker_size_);
52 
53  if (config.showThresholdImage) {
54  //cv::imshow("ThresholdImage", mDetector.getThresholdedImage());
55  //cv::waitKey(10);
56  }
57  ROS_DEBUG_STREAM("Found " << markers.size() << " marker(s) in left camera image");
58  } else {
59  ROS_ERROR_STREAM("Left camera parameters (aruco) are not valid");
60  }
61  } else {
62  if (cam_params_right_.isValid()) {
63  mDetector.detect(image, markers, cam_params_right_, marker_size_);
64  ROS_DEBUG_STREAM("Found " << markers.size() << " marker(s) in right camera image");
65  } else {
66  ROS_ERROR_STREAM("Right camera parameters (aruco) are not valid");
67  }
68  }
69 
70  return markers;
71 }
72 
73 void MarkerDetection::setCameraParameters(const sensor_msgs::CameraInfo &cam_params_left, const sensor_msgs::CameraInfo &cam_params_right) {
74  cv::Mat cameraMatrix(3, 3, CV_32FC1);
75  cv::Mat distorsionCoeff(4, 1, CV_32FC1);
76  //transform camera paramters from ros message to aruco representation (left)
77  cv::Size size(cam_params_left.height, cam_params_left.width);
78  for (int i=0; i<9; ++i) {
79  cameraMatrix.at<float>(i%3, i-(i%3)*3) = cam_params_left.K[i];
80  }
81  if (cam_params_left.D.size() >= 4) {
82  for (int i=0; i<4; ++i) {
83  distorsionCoeff.at<float>(i, 0) = cam_params_left.D[i];
84  }
85  }
86  cam_params_left_ = aruco::CameraParameters(cameraMatrix, distorsionCoeff, size);
87 
88  //transform camera paramters from ros message to aruco representation (right)
89  size = cv::Size(cam_params_right.height, cam_params_right.width);
90  for (int i=0; i<9; ++i) {
91  cameraMatrix.at<float>(i%3, i-(i%3)*3) = cam_params_right.K[i];
92  }
93  if (cam_params_right.D.size() >= 4) {
94  for (int i=0; i<4; ++i) {
95  distorsionCoeff.at<float>(i, 0) = cam_params_right.D[i];
96  }
97  }
98  cam_params_right_ = aruco::CameraParameters(cameraMatrix, distorsionCoeff, size);
99 }
100 
101 }
102 
void setThresholdParams(double param1, double param2)
void detect(const cv::Mat &input, std::vector< Marker > &detectedMarkers, cv::Mat camMatrix=cv::Mat(), cv::Mat distCoeff=cv::Mat(), float markerSizeMeters=-1, bool setYPerperdicular=false)
void setCameraParameters(const sensor_msgs::CameraInfo &cam_params_left, const sensor_msgs::CameraInfo &cam_params_right)
Set the camera parameters of the two cameras.
MarkerDetection()
The default constructor of this class.
void setMinMaxSize(float min=0.03, float max=0.5)
Main class for marker detection.
#define ROS_DEBUG_STREAM(args)
Parameters of the camera.
std::vector< aruco::Marker > detect(const cv::Mat &image, CameraId id, const ArucoMarkerRecognitionConfig &config)
Detects markers in the given image with the camera parameters of the camera with the given id...
#define ROS_ERROR_STREAM(args)
void setThresholdMethod(ThresholdMethods m)


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