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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "lfr.h"
  2. LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize)
  3. : iAmLooping(false), input(videoHeight, videoWidth), processing(), controlModule(), interpreter(), intersectionHandler()
  4. {
  5. this->iAmLooping = false;
  6. this->thresholdBinary = thresholdBinary;
  7. this->gaussKernelSize = gaussKernelSize;
  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.processImage(image, this->thresholdBinary, this->gaussKernelSize);
  23. std::vector<Vec4i> lines = processing.calculateLineSegments(image);
  24. for( size_t i = 0; i < lines.size(); i++ )
  25. {
  26. line( image, Point(lines[i][0], lines[i][1]),
  27. Point( lines[i][2], lines[i][3]), (0,0,255), 1, 8 );
  28. }
  29. imshow("Display window", image);
  30. char c = (char)waitKey(1);
  31. }
  32. destroyWindow("Display window");
  33. input.freeWebcam();
  34. }
  35. void LFR::startLoop()
  36. {
  37. iAmLooping = true;
  38. this->loopThread=thread(&LFR::loop, this);
  39. }
  40. void LFR::endLoop()
  41. {
  42. iAmLooping = false;
  43. this->loopThread.join();
  44. return;
  45. }