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.cpp 1003B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "lfr.h"
  2. const int threshold_binary = 110;
  3. LFR::LFR(int video_height, int video_width, int threshold_binary)
  4. : iAmLooping(false), input(video_height, video_width), processing(), controlModule(), interpreter(), intersectionHandler()
  5. {
  6. this->iAmLooping = false;
  7. this->threshold_binary = threshold_binary;
  8. }
  9. LFR::~LFR()
  10. {
  11. if(iAmLooping)
  12. {
  13. this->endLoop();
  14. }
  15. }
  16. void LFR::loop()
  17. {
  18. namedWindow("Display window");
  19. while(iAmLooping)
  20. {
  21. Mat image = input.readWebcam();
  22. processing.calculate_binaray(image, this->threshold_binary);
  23. std::vector<LFRLine> lines = processing.calculate_line_segments(image);
  24. imshow("Display window", image);
  25. char c = (char)waitKey(1);
  26. }
  27. destroyWindow("Display window");
  28. input.freeWebcam();
  29. }
  30. void LFR::startLoop()
  31. {
  32. iAmLooping = true;
  33. this->loopThread=thread(&LFR::loop, this);
  34. }
  35. void LFR::endLoop()
  36. {
  37. iAmLooping = false;
  38. this->loopThread.join();
  39. return;
  40. }