LCOV - code coverage report
Current view: top level - src/Vision/mock - MockCupDetector.cpp (source / functions) Hit Total Coverage
Test: HLR Lines: 35 36 97.2 %
Date: 2018-01-12 13:58:30 Functions: 8 8 100.0 %

          Line data    Source code
       1             : #include "Vision/mock/MockCupDetector.hpp"
       2             : #include <exception>
       3             : #include <boost/filesystem.hpp>
       4             : 
       5             : namespace HLR
       6             : {
       7             : namespace Vision
       8             : {
       9          40 : MockCupDetector::MockCupDetector()
      10             : {
      11          37 :     boost::system::error_code ec;
      12          74 :     auto path = boost::filesystem::read_symlink("/proc/self/exe", ec);
      13             : 
      14          37 :     if (!ec)
      15             :     {
      16          37 :         path.remove_filename();
      17             :     }
      18             :     else
      19             :     {
      20           0 :         path.clear();
      21             :     }
      22             : 
      23             :     // Read all the yml files to extract the saved mat's.
      24          74 :     cv::FileStorage frgb;
      25          37 :     frgb.open((path / "rgb.yml").native(), cv::FileStorage::READ);
      26          74 :     cv::FileStorage fir;
      27          37 :     fir.open((path / "ir.yml").native(), cv::FileStorage::READ);
      28          74 :     cv::FileStorage fdepth;
      29          37 :     fdepth.open((path / "depth.yml").native(), cv::FileStorage::READ);
      30             : 
      31          37 :     if (!frgb.isOpened() || !fir.isOpened() || !fdepth.isOpened())
      32             :     {
      33             :         throw std::runtime_error(
      34           3 :             "Could not open yml files for Vision MockCupDetector");
      35             :     }
      36             : 
      37             :     // Put the different mats in their respective member value
      38          68 :     cv::Mat d, i, c;
      39          34 :     frgb["Rgb"] >> c;
      40          34 :     fir["IR"] >> i;
      41          34 :     fdepth["DEPTH"] >> d;
      42          34 :     depth = std::make_shared<cv::Mat>(d);
      43          34 :     ir = std::make_shared<cv::Mat>(i);
      44          34 :     color = std::make_shared<cv::Mat>(c);
      45             : 
      46             :     // Create a fake detection with hardcoded cups
      47          34 :     detection.frame = depth;
      48          34 :     detection.cups.emplace_back(cv::Point(237, 209));
      49          34 :     detection.cups.emplace_back(cv::Point(331, 208));
      50          34 : }
      51             : 
      52           1 : std::shared_ptr<cv::Mat> MockCupDetector::get_detected_cups_image()
      53             : {
      54           1 :     return color;
      55             : }
      56             : 
      57           3 : std::shared_ptr<cv::Mat> MockCupDetector::get_latest_depth_frame()
      58             : {
      59           3 :     return detection.frame;
      60             : }
      61             : 
      62           1 : std::shared_ptr<cv::Mat> MockCupDetector::get_latest_ir_frame()
      63             : {
      64           1 :     return ir;
      65             : }
      66             : 
      67           1 : std::shared_ptr<cv::Mat> MockCupDetector::get_latest_color_frame()
      68             : {
      69           1 :     return color;
      70             : }
      71             : 
      72           4 : CupDetection MockCupDetector::detect_cups()
      73             : {
      74           4 :     return detection;
      75             : }
      76             : 
      77             : } // namespace Vision
      78           3 : } // namespace HLR

Generated by: LCOV version 1.12