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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.readFile("C:\\Line-Following-Robot\\Test_data");
  22. Mat processedImage = image;
  23. processing.processImage(processedImage, this->thresholdBinary, this->gaussKernelSize);
  24. std::vector<Vec4i> lines = processing.calculateLineSegments(processedImage);
  25. for( size_t i = 0; i < lines.size(); i++ )
  26. {
  27. line( image, Point(lines[i][0], lines[i][1]),
  28. Point( lines[i][2], lines[i][3]), (0,0,255), 1, 8 );
  29. }
  30. imshow("Display window", image);
  31. char c = (char)waitKey(1);
  32. }
  33. destroyWindow("Display window");
  34. input.freeWebcam();
  35. }
  36. void LFR::startLoop()
  37. {
  38. iAmLooping = true;
  39. this->loopThread=thread(&LFR::loop, this);
  40. }
  41. void LFR::endLoop()
  42. {
  43. iAmLooping = false;
  44. this->loopThread.join();
  45. return;
  46. }