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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. cv::Mat rawImage;
  16. cv::Mat processedImage;
  17. FrameData data;
  18. std::vector<float> motorSignals;
  19. };
  20. class LFR
  21. {
  22. public:
  23. using ListenerKey = void const*;
  24. using ExceptionCallback = std::function<bool(std::exception const &ex)>;
  25. using ListenerCallback = std::function<void(LFR_Result)>;
  26. private:
  27. using ListenerPair = std::pair<ListenerKey, ListenerCallback>;
  28. using ListenerVector = std::vector<ListenerPair>;
  29. Input input;
  30. Processing processing;
  31. ControlModule controlModule;
  32. Interpreter interpreter;
  33. IntersectionHandler intersectionHandler;
  34. int thresholdBinary;
  35. int gaussKernelSize;
  36. ListenerVector listeners;
  37. ExceptionCallback cb;
  38. bool stop;
  39. std::unique_ptr<std::thread> thread;
  40. mutable std::mutex mutex;
  41. //void provideOutput(Mat originalImage, Mat processedImage, const FrameData& frameData, const Rect& roi);
  42. void createThread();
  43. void setStop(bool val);
  44. public:
  45. LFR() = delete;
  46. LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, ExceptionCallback cb);
  47. ~LFR();
  48. void startLoop();
  49. void endLoop();
  50. void addListener(ListenerCallback cv, ListenerKey key);
  51. void removeListener(ListenerKey key);
  52. void isStopped() const noexcept;
  53. Mat provideOutput(Mat originalImage, Mat processedImage, const FrameData& frameData, const Rect& roi);
  54. };