libwallaby  v24
The wallaby standard library
aruco.hpp
Go to the documentation of this file.
1 /*
2  * arhco.h
3  *
4  * Created on April 4, 2017
5  * Author: Ryan Owens
6  */
7 #ifndef INCLUDE_WALLABY_ARUCO_HPP_
8 #define INCLUDE_WALLABY_ARUCO_HPP_
9 
10 #ifdef ARUCO
11 
12 #include <algorithm>
13 #include <fstream>
14 #include <iostream>
15 #include <opencv2/aruco.hpp>
16 #include <opencv2/calib3d.hpp>
17 #include <opencv2/core.hpp>
18 #include <opencv2/highgui.hpp>
19 #include <opencv2/videoio.hpp>
20 #include <string>
21 #include <unistd.h>
22 
23 namespace aruco {
24 class Aruco;
25 static Aruco *instance;
26 const static int defaultDictionaryID = 1; // TODO default dictionary
27 
28 class Aruco {
29 public:
30  Aruco(int dicionaryId);
31  ~Aruco();
32  static Aruco *getInstance();
33  bool arucoMarkerInView(int arucoId, cv::Mat *frame = nullptr);
34  bool setDictionary(int dictionaryId);
35  std::vector<int> arucoMarkersInView(cv::Mat *frame = nullptr);
36  std::vector<std::vector<cv::Point2f>>
37  arucoMarkerCorners(cv::Mat *frame = nullptr);
38  std::vector<double> getPose(int arucoId, cv::Mat *frame = nullptr);
39  void setChessBoardSize(float sizeInMeters);
40  void setArucoMarkerSize(float sizeInMeters);
41  bool calibrate(std::vector<cv::Mat> images);
42  bool setCameraCalibration(std::string filename);
43 
44 private:
45  float chessBoardSquareSize = 0.0235f; // Meters // TODO pass in this value?
46  float arucoSquareSize = 0.025f; // Meters // TODO pass in this value?
47  int numImagesForCalibration = 15; // TODO appropriate value?
48  cv::Size chessBoardDimensions = cv::Size(6, 9);
49  std::vector<cv::Mat> images;
50  std::vector<std::vector<cv::Point2f>> foundChessboardCorners;
51  cv::Mat cameraMatrix, distortionCoefficients;
52  int dictionaryId;
53  int chessBoardFlags = cv::CALIB_CB_ADAPTIVE_THRESH |
54  cv::CALIB_CB_NORMALIZE_IMAGE | cv::CALIB_CB_FAST_CHECK;
55 
56  std::string currentCalibrationFile = "";
57  std::string customDictionaryFile =
58  "kipr_dictionary.yml"; // TODO need to get the proper path
59  std::string calibrationFilePath = ""; // TODO neet to get the proper path
60  cv::Ptr<cv::aruco::Dictionary> dictionary;
61  cv::Ptr<cv::aruco::DetectorParameters> detectorParams;
62  // Camera::Device *m_camDevice; // no longer needed
63 
64  const std::string WHITE_CAMERA_FILE = "white_2016.yml";
65  const std::string BLACK_CAMERA_FILE = "black_2017.yml";
66 
67  cv::Mat getFrame();
68  bool openCamera();
69  bool saveCalibration();
70  void getImagesFromCamera();
71  bool getCustomDictionary();
72  bool readCameraCalibration(std::string filename);
73  void calculateChessBoardPosition(std::vector<cv::Point3f> &vec);
74  bool vectorContains(std::vector<int> vec, int val);
75  void calculateChessBoardCornersFromImages(
76  std::vector<std::vector<cv::Point2f>> &foundCorners);
77 };
78 }
79 #endif
80 #endif