HLR  0.0.1
CupDetector.hpp
1 #pragma once
2 
3 #include <array>
4 #include <atomic>
5 #include <mutex>
6 #include <thread>
7 #include <vector>
8 #include <Vision/ICupDetector.hpp>
9 #include <libfreenect2/registration.h>
10 #include <opencv2/opencv.hpp>
11 
12 namespace HLR
13 {
14 namespace Vision
15 {
20 class CupDetector : public ICupDetector
21 {
22 public:
23  CupDetector();
24 
25  ~CupDetector() override;
26 
32  CupDetector(CupDetector&& cup_detector) = delete;
33 
39  CupDetector(const CupDetector& cup_detector) = delete;
40 
47  CupDetector& operator=(const CupDetector& cup_detector) = delete;
48 
55  CupDetector& operator=(CupDetector&& cup_detector) = delete;
56 
57  CupDetection detect_cups() override;
58 
59  std::shared_ptr<cv::Mat> get_detected_cups_image() override;
60 
61  std::shared_ptr<cv::Mat> get_latest_depth_frame() override;
62 
63  std::shared_ptr<cv::Mat> get_latest_ir_frame() override;
64 
65  std::shared_ptr<cv::Mat> get_latest_color_frame() override;
66 
67 private:
73  void update_frames();
74 
79  void detect();
80 
90  std::vector<cv::Point> find_cups_in_binary_canny(cv::Mat& input);
91 
99  void depth_to_binary_canny(const cv::Mat& src, cv::Mat& dst);
100 
109  void colour_to_binary(const cv::Mat& src,
110  cv::Mat& dst,
111  const cv::Point& ref_point);
112 
122  std::vector<cv::Point> get_cups_color_image(
123  const cv::Mat& src,
124  std::vector<cv::Point> ref_points);
125 
126  std::shared_ptr<cv::Mat> latest_color_frame;
127  std::shared_ptr<cv::Mat> latest_ir_frame;
128  std::shared_ptr<cv::Mat> latest_depth_frame;
129  CupDetection latest_cup_detection;
130  std::atomic_bool shutdown;
131  std::atomic_bool new_frame;
132  std::mutex frame_lock;
133  std::thread frame_update_thread;
134  std::thread detect_thread;
135  cv::Mat modified_depth_mat;
136  cv::Mat detected_cups_image;
137  std::vector<std::vector<cv::Point>> reference_contours;
138  std::unique_ptr<libfreenect2::Registration> registration;
139 };
140 } // namespace Vision
141 } // namespace HLR
CupDetection detect_cups() override
Detects cups using the Kinect Detects cups using the camera&#39;s of the Kinect. This function returns th...
std::shared_ptr< cv::Mat > get_detected_cups_image() override
Returns an image wich has outlined and identified the detected cups.
Can detect cups using the Kinect color and depth camera. This class allows its user to detect cups in...
Definition: ICupDetector.hpp:39
std::shared_ptr< cv::Mat > get_latest_depth_frame() override
Returns the latest depth frame of the Kinect.
std::shared_ptr< cv::Mat > get_latest_color_frame() override
Returns the latest color frame of the Kinect color camera.
Collection of detected cups Collection of detected cups where the location of the cups is described i...
Definition: ICupDetector.hpp:17
std::shared_ptr< cv::Mat > get_latest_ir_frame() override
Returns the latest IR frame of the Kinect IR camera.
Implementation of CupDetector.
Definition: CupDetector.hpp:20
CupDetector & operator=(const CupDetector &cup_detector)=delete
Deleted assignment operator.