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 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "lfr.h"
  2. LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny)
  3. : iAmLooping(false), input(videoHeight, videoWidth), processing(), controlModule(), interpreter(), intersectionHandler()
  4. {
  5. this->iAmLooping = false;
  6. this->thresholdBinary = thresholdBinary;
  7. this->gaussKernelSize = gaussKernelSize;
  8. this->thresholdCanny1 = thresholdCanny1;
  9. this->thresholdCanny2 = thresholdCanny2;
  10. this->apertureSizeCanny = apertureSizeCanny;
  11. }
  12. LFR::~LFR()
  13. {
  14. if(iAmLooping)
  15. {
  16. this->endLoop();
  17. }
  18. }
  19. void LFR::loop()
  20. {
  21. namedWindow("Display window");
  22. while(iAmLooping)
  23. {
  24. Mat image = input.readWebcam();
  25. processing.processImage(image, this->thresholdBinary, this->gaussKernelSize, this->thresholdCanny1, thresholdCanny2, this->apertureSizeCanny);
  26. std::vector<Vec4i> lines = processing.calculateLineSegments(image);
  27. for( size_t i = 0; i < lines.size(); i++ )
  28. {
  29. line( image, Point(lines[i][0], lines[i][1]),
  30. Point( lines[i][2], lines[i][3]), (0,0,255), 1, 8 );
  31. }
  32. imshow("Display window", image);
  33. char c = (char)waitKey(1);
  34. }
  35. destroyWindow("Display window");
  36. input.freeWebcam();
  37. }
  38. void LFR::startLoop()
  39. {
  40. iAmLooping = true;
  41. this->loopThread=thread(&LFR::loop, this);
  42. }
  43. void LFR::endLoop()
  44. {
  45. iAmLooping = false;
  46. this->loopThread.join();
  47. return;
  48. }