Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lfr.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include <iostream>
  3. #include <future>
  4. #include <thread>
  5. #include <functional>
  6. #include <opencv2/opencv.hpp>
  7. #include <input.h>
  8. #include <processing.h>
  9. #include <control_module.h>
  10. #include <interpreter.h>
  11. #include <intersection_handler.h>
  12. using namespace cv;
  13. struct LFR_Result
  14. {
  15. bool validLane;
  16. cv::Mat rawImage;
  17. cv::Mat processedImage;
  18. FrameData data;
  19. std::vector<float> motorSignals;
  20. };
  21. class LFR
  22. {
  23. public:
  24. using ListenerKey = void const*;
  25. using ExceptionCallback = std::function<bool(std::exception const &ex)>;
  26. using ListenerCallback = std::function<void(LFR_Result)>;
  27. private:
  28. using ListenerPair = std::pair<ListenerKey, ListenerCallback>;
  29. using ListenerVector = std::vector<ListenerPair>;
  30. Input input;
  31. Processing processing;
  32. ControlModule controlModule;
  33. Interpreter interpreter;
  34. IntersectionHandler intersectionHandler;
  35. int thresholdBinary;
  36. int gaussKernelSize;
  37. ListenerVector listeners;
  38. ExceptionCallback cb;
  39. bool stop;
  40. std::unique_ptr<std::thread> thread;
  41. mutable std::mutex mutex;
  42. //void provideOutput(Mat originalImage, Mat processedImage, const FrameData& frameData, const Rect& roi);
  43. void createThread();
  44. void setStop(bool val);
  45. public:
  46. LFR() = delete;
  47. LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, double maxSpeed, ExceptionCallback cb);
  48. ~LFR();
  49. void startLoop();
  50. void endLoop();
  51. void addListener(ListenerCallback cv, ListenerKey key);
  52. void removeListener(ListenerKey key);
  53. void isStopped() const noexcept;
  54. Mat provideOutput(Mat originalImage, Mat processedImage, const FrameData& frameData, const Rect& roi);
  55. };